From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Riley Newsgroups: gmane.emacs.help Subject: Re: Tabs and Spaces Date: Mon, 25 May 2009 17:36:27 +0200 Organization: aich tea tea pea dicky riley dot net Message-ID: References: <77vbbiF1jhhubU1@mid.individual.net> <7chbz9bdyu.fsf@pbourguignon.informatimago.com> <77vgiiF1jjcfrU1@mid.individual.net> <7czld19ttv.fsf@pbourguignon.informatimago.com> <77vq0cF1jh3k6U1@mid.individual.net> <7cmy919puo.fsf@pbourguignon.anevia.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1243267990 17155 80.91.229.12 (25 May 2009 16:13:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 May 2009 16:13:10 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 25 18:13:03 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1M8cnO-00022K-Ra for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2009 18:13:03 +0200 Original-Received: from localhost ([127.0.0.1]:56547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M8cnO-0008FP-45 for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2009 12:13:02 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!goblin1!goblin.stu.neva.ru!feeder.motzarella.org!news.motzarella.org!news.eternal-september.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 117 Original-X-Trace: news.eternal-september.org U2FsdGVkX1+/XMhBbPEy++DijKVAE9YWeSx1XwQKcz7j2KwoZPMeJ9o9ocjQUrQTiDPJ9WSkhzBQWclt6p/RWn1AO8UqowRFDw6irwL/bqWLmBnBEo6yRbhxwu5YL3nGN/pqWxk+/rkCfbySqWI7hg== Original-X-Complaints-To: abuse@eternal-september.org Original-NNTP-Posting-Date: Mon, 25 May 2009 15:36:28 +0000 (UTC) X-Auth-Sender: U2FsdGVkX19i4w3Shfv+wb47rDMsbepSD9teqZF+ifdnuQmkIL1+ag== Cancel-Lock: sha1:EkVnjPKR61Q8pSIY94uDuUTReI0= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.93 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:169465 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:64697 Archived-At: pjb@informatimago.com (Pascal J. Bourguignon) writes: > use.address@my.homepage.invalid (Chris Gordon-Smith) writes: > >> Pascal J. Bourguignon wrote: >>> use.address@my.homepage.invalid (Chris Gordon-Smith) writes: >>> >>>> Pascal J. Bourguignon wrote: >>>>> use.address@my.homepage.invalid (Chris Gordon-Smith) writes: >>>>> >>>>>> Hello All >>>>>> >>>>>> I have recenly started using emacs for programming, after years using >>>>>> KDevelop. One problem I have is indenting code. I have my own indentation >>>>>> style. and ideally I would like to setup emacs to support it automatically. >>>>>> However, in the short term I'll settle for having emacs convert a TAB >>>>>> keypress into the correct number of spaces to fill whitespace up to the >>>>>> next tabstop. >>>>>> >>>>>> At the moment I have >>>>>> >>>>>> (global-set-key (kbd "TAB") 'self-insert-command) >>>>>> >>>>>> in my .emacs to force insertion of a tab, but I have to keep invoking >>>>>> untabify manually (otherwise my code looks misaligned when I upload it to >>>>>> Google Code). >>>>>> >>>>>> Can anyone help. >>>>> >>>>> You shouldn't insert TAB, this is very bad. At the very least, you >>>>> may compute the number of spaces you need to insert and insert them >>>>> rather. >>>> Yes, that's what I would like to do. Can you suggest how to do this. Do I >>>> need to put something in my .emacs file. What would it look like? >>>> >>>>> >>>>> But depending on the language you use, a different mode will be used >>>>> to edit your source and each mode may provide its own indenting rules. >>>>> >>>>> In the case of Lisp, you may add a indent-function property to the >>>>> plist of the operator name. >>>>> >>>>> In the case of C, you may customize the variable: c-offsets-alist. See >>>>> also: c-style-alist ; perhaps there's already a style defined that >>>>> you'll like. >>> >>> >>> In my post, there was a subliminal question, but it didn't reach your >>> consciousness, I'm sorry. Here it is: >> >> It wasn't really a question, and the fact that you had mentioned that the >> solution to the problem might be language dependent did register with me. >> >> I think its a pity that you chose to answer in what appears to be a rather >> rude manner. > > That wasn't intended. Sorry again. > > >>> What programming language do you use? >> >> C++. But I had already established before my original post that the >> standard emacs indenting would not suit me. Perhaps I should have mentioned >> this. > > c++-mode is derived from c-mode, you can configure c-offsets-alist and > possibly define your own c-style in c-style-alist. > > The point here is that almost all the syntactic elements of C/C++ are > already taken into account by the C indenting functions, so you only > need to specify the indenting you want, and let the existing machinery > do the work for you. > > > >>> Depending on the answer you give, you may well have nothing to program. >>> Otherwise, you could do something like this: >>> >>> (defconst +space+ 32 "ASCII code for the space character") >>> >>> (defun my-language/indent-line () >>> (interactive) >>> (let ((where (let ((m (make-marker))) (set-marker m (point)) m)) >>> (indent (my-language/get-indent-from-some-parsing-around (point)))) >>> (beginning-of-line) >>> (looking-at "^[ \t]*") >>> (delete-region (beginning-of-line) (match-end)) >>> (goto-char (beginning-of-line)) >>> (insert (make-string indent +space+)) >>> (goto-char where) >>> (set-marker where nil))) >>> >>> >>> (local-set-key (kbd "TAB") 'my-language/indent-line) >>> >>> >>> Of course, all the difficulty (or simplicity, depends on your language) >>> is in implementing my-language/get-indent-from-some-parsing-around. >>> >>> >> >> Thanks for this. >> I'll need to read it and understand it before I use it, but it looks like a >> good starting point. > > Well, C++ is quite difficult to parse, so you should really first try > to configure the existing emacs C indentation feature. > > However, if you want to write your own parser, you may use the > bovinator from cedet: http://cedet.sourceforge.net/ > http://cedet.sourceforge.net/semantic.shtml One can't help but think that that advice is so far from reality for someone who has just started using emacs that it must be meant as a joke :-; Besides which, does cedet not parse c++ already?