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

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

Re: Auto-indentation


From: Alan Mackenzie
Subject: Re: Auto-indentation
Date: Fri, 10 Feb 2006 19:24:08 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

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)


> here is my .emacs:

> (setq case-fold-search t)
> (global-font-lock-mode t)
> (mouse-wheel-mode t)
> (setq auto-fill-mode 1)
> (setq display-time-day-and-date t)
> (display-time)

> (setq c-mode-hook
>       (function (lambda ()
>                 (c-set-style "K&R")
>                 (setq c-basic-offset 8))))
> (setq objc-mode-hook
>       (function (lambda ()
>                 (c-set-style "K&R")
>                 (setq c-basic-offset 8))))
> (setq c++-mode-hook
>       (function (lambda ()
>                 (c-set-style "K&R")
>                 (setq c-basic-offset 8))))
> (setq java-mode-hook
>       (function (lambda ()
>                 (c-set-style "K&R")
>                 (setq c-basic-offset 8))))

Nothing to do with what you asked for, but a comment all the same.  You
can achieve the effect of the above 16 lines more simply by code like
this in your .emacs:

        (setq c-default-style "K&R")
        (defun my-set-basic-offset ()
          (setq c-basic-offset 8))
        (add-hook 'c-mode-common-hook 'my-set-basic-offset)

> Marcus Husar: mail@marcus-husar.de

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").



reply via email to

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