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)