[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Changing Emacs indentation behavior
From: |
Juanma |
Subject: |
Re: Changing Emacs indentation behavior |
Date: |
Sat, 19 Jul 2008 04:13:01 +0200 |
User-agent: |
KMail/1.9.6 (enterprise 0.20070907.709405) |
On Saturday 19 July 2008, Nonni wrote:
>[...]
> If I write the if-statement my way, the indentation of the braces are wrong,
> emacs produces:
>
> if (version < FMOD_VERSION)
> {
> return 0;
> }
>
> Is there any way to get emacs to auto-indent my code the way I want it to ?
>
> Thanks.
Yes. It's all about the cc-mode style. You can find CC-Mode in Info and look
for styles.
This is how I configured it:
;; Style I want to use in C/C++ mode
(c-add-style
"mi-estilo"
'("stroustrup" ; style to inherit from. There are many others
(indent-tabs-mode . nil) ; use spaces rather than tabs
(c-basic-offset . 4) ; indent by four spaces
(tab-width . 4) ; if the file specifies tabs, make them 4 chars wide
(c-tab-always-indent . 1) ; tabs when in literals & comments, indent
otherwise
(c-offsets-alist . ; custom indentation rules
((inline-open . 0)
(brace-list-open . 0)
(statement-case-open . +)))))
(add-hook 'c++-mode-hook
(lambda () (c-set-style "mi-estilo")))
I'm sure that 'c-offsets-alist' defines the indentation rules, but I don't
remember if I really need that, after having inherited the style form
"stroustrup" style. If you care, check the Info.
Best regards,
--
Juanma
"Having a smoking section in a restaurant is like
having a peeing section in a swimming pool."
-- Edward Burr