From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Whitfield Newsgroups: gmane.emacs.help Subject: Re: Auto-indentation Date: Mon, 13 Feb 2006 08:30:40 +0800 Message-ID: <43efd2a2$0$22056$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <43efd1b5$0$22056$5a62ac22@per-qv1-newsreader-01.iinet.net.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1139790769 16490 80.91.229.2 (13 Feb 2006 00:32:49 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 13 Feb 2006 00:32:49 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 13 01:32:46 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1F8Rdu-00005s-F4 for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Feb 2006 01:32:38 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F8Rdt-0000TM-LE for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Feb 2006 19:32:37 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsfeed.news.ucla.edu!newsfeed.media.kyoto-u.ac.jp!snewsf0.syd.ops.aspac.uu.net!news1.optus.net.au!optus!news.uwa.edu.au!nntp.waia.asn.au!203.59.27.186.MISMATCH!newsfeed.iinet.net.au!newsfeed.iinet.net.au!per-qv1-newsstorage1.iinet.net.au!per-qv1-newsstorage1.iinet.net.au!per-qv1-newsreader-01.iinet.net.au!not-for-mail User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Thunderbird/1.0.6 Mnenhy/0.7.2.0 Original-Newsgroups: gnu.emacs.help In-Reply-To: <43efd1b5$0$22056$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Original-Lines: 46 Original-NNTP-Posting-Host: 203.59.9.243 Original-X-Trace: 1139790498 per-qv1-newsreader-01.iinet.net.au 22056 203.59.9.243 Original-Xref: shelby.stanford.edu gnu.emacs.help:137546 Original-To: help-gnu-emacs@gnu.org 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:33171 Archived-At: Paul Whitfield wrote: > Alan Mackenzie wrote: >> Marcus Husar wrote on Fri, 10 Feb 2006 14:27:32 >> +0100: >> >>> I no searched 2 hours for auto-indentation in emacs. I couldn't find >>> anything. Could someone please tell me how it works? >> >> Assuming you're talking about C, C++, Objective-C and Java, (as suggested >> by your .emacs), then an existing line of code gets re-indented when >> >> o - you press the TAB key. >> o - you type an "electric" character, such as ";" or "{". >> o - you run some other indentation command, such as C-M-q, C-c C-q, or >> C-M-\. >> >> When you type , the newline doesn't get indented. You can make this >> happen by typing C-j instead of . If you really want to >> indent the new line, then put this into your .emacs: >> >> (defun my-make-CR-do-indent () >> (define-key c-mode-base-map "\C-m" 'c-context-line-break)) >> (add-hook 'c-initialization-hook 'my-make-CR-do-indent) >> > > Alternatively: > > (defun my-c-mode-common-hook () > (define-key c-mode-base-map "\C-m" 'newline-and-indent)) > > (add-hook 'c-mode-common-hook' my-c-mode-common-hook) > > > > This uses the generic newline-and-indent which should work > for even non "c" type languages. > > Adding to the common hook means that all languages that > make use of CC-mode will be "auto" indented. Oops... just re-read the documentation, c-initialization-hook is run first, so ignore my advice about using the common-hook instead of the initialisation hook. regards Paul