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: Tue, 14 Feb 2006 09:04:34 +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

Alan Mackenzie wrote:
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.

Oh... I think I will try that out!

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.

Goes to show you should re-visit manuals!

Thank you for correcting my wrong headedness :-)

Regards
Paul.





reply via email to

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