[Top][All Lists]

[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:26:43 +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/

Alan Mackenzie wrote:
Marcus Husar <address@hidden> 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

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)


(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.



reply via email to

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