help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Auto-indentation


From: Paul Whitfield
Subject: Re: Auto-indentation
Date: Mon, 13 Feb 2006 08:30:40 +0800
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

Paul Whitfield wrote:
Alan Mackenzie wrote:
Marcus Husar <mail@marcus-husar.de> 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 <ret>, the newline doesn't get indented.  You can make this
happen by typing C-j instead of <ret>.  If you really want <ret> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]