logo       

Re: C formatting: msg#00888

emacs.help

Subject: Re: C formatting

Kai Großjohann a écrit:


I suggest to try C-c C-o on the first line that has wrong indentation
and to follow the prompts. Then hit TAB to reindent the line. When
you like the indentation, you can use C-x ESC ESC and then M-p/M-n to
retrieve the right c-set-offset statement. That's what you can put
in the hook, below:

I started from what an user answer here gave me:

(add-hook 'c-mode-hook
(function (lambda ()
(c-set-style "bsd")
(setq c-basic-offset 4)
))
)

and then what what you said:
C-x C-o
I get the the statement
Syntactic symabol to change: substatement
I hit Enter...
substatement offset (default +):
I put 0, and then I get the *wanted behaviour*.
C-x ESC ESC
redo (c-set-offset (quote substatement) 0 nil)

So I modify my .emacs:

(add-hook 'c-mode-hook
(function (lambda ()
(c-set-style "bsd")
(setq c-basic-offset 4)
(c-set-offset 0)
))
)

But then I obtain a different behaviour.
Typically, after an "if", when I go on a new line to do my opening brace, and hit Tab, the offset is 12 characters (8 char tab, and four characters).

You didn't say which version of Emacs you are using. I'm assuming
Emacs 21. Probably the above works for Emacs 20, too.

21.2.1

--
. .
. .:::. ### \|/ ` ___ '
:(o o): . (o o) (o o) - (O o) -
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise