Paul Whitfield <NoSpam@iinet.net.au> wrote on Mon, 13 Feb 2006 08:26:43 +0800:
Alan Mackenzie wrote:
[ .... ]
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.
Yes, but the binding suggested is in CC Mode's main keymap
(c-mode-base-map), so this is irrelevant. The command
c-context-line-break, unlike newline-and-indent, continues comments and
multi-line macros with comment prefixes (e.g. " * " at beginning of line)
and backslashed newlines.
Adding to the common hook means that all languages that
make use of CC-mode will be "auto" indented.
Yes. I've seen your follow-up post. ;-) The thing about
c-mode-common-hook is that it's executed every time you visit a new
buffer. You only need to bind key sequences once. Binding them in the
common hook isn't wrong, and doesn't noticeably delay anything, but it's
kind of klunky. This klunkiness was actually encouraged by the CC Mode
manual, but newer editions have corrected this.