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:26:43 +0800 Message-ID: <43efd1b5$0$22056$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: 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 1139790576 16005 80.91.229.2 (13 Feb 2006 00:29:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 13 Feb 2006 00:29:36 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 13 01:29:35 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 1F8Raw-0007vF-Pm for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Feb 2006 01:29:35 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F8Rav-0007bp-EE for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Feb 2006 19:29:33 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news3.google.com!news.glorb.com!newsfeed-east.nntpserver.com!nntpserver.com!statler.nntpserver.com!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: Original-Lines: 42 Original-NNTP-Posting-Host: 203.59.9.243 Original-X-Trace: 1139790261 per-qv1-newsreader-01.iinet.net.au 22056 203.59.9.243 Original-Xref: shelby.stanford.edu gnu.emacs.help:137545 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:33170 Archived-At: 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. regards Paul