* Changing Emacs indentation behavior
@ 2008-07-18 23:08 Nonni
2008-07-19 2:13 ` Juanma
2008-07-20 22:20 ` Nikolaj Schumacher
0 siblings, 2 replies; 3+ messages in thread
From: Nonni @ 2008-07-18 23:08 UTC (permalink / raw)
To: Help-gnu-emacs
Hi,
I'm new to using emacs. I'm currently using to to write code and its going
well apart from one thing...
Emacs' auto indentation doesn't like the way I write my braces.
The way I want to write code:
if (version < FMOD_VERSION)
{
return 0;
}
The way Emacs wants me to write code:
if(version < FMOD_VERSION) {
return 0;
}
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.
--
View this message in context: http://www.nabble.com/Changing-Emacs-indentation-behavior-tp18539174p18539174.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Changing Emacs indentation behavior
2008-07-18 23:08 Changing Emacs indentation behavior Nonni
@ 2008-07-19 2:13 ` Juanma
2008-07-20 22:20 ` Nikolaj Schumacher
1 sibling, 0 replies; 3+ messages in thread
From: Juanma @ 2008-07-19 2:13 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Changing Emacs indentation behavior
2008-07-18 23:08 Changing Emacs indentation behavior Nonni
2008-07-19 2:13 ` Juanma
@ 2008-07-20 22:20 ` Nikolaj Schumacher
1 sibling, 0 replies; 3+ messages in thread
From: Nikolaj Schumacher @ 2008-07-20 22:20 UTC (permalink / raw)
To: Nonni; +Cc: Help-gnu-emacs
Nonni <nonnsi@gmail.com> wrote:
> Is there any way to get emacs to auto-indent my code the way I want it to ?
For the beginning it should be enough to call `c-set-style' or set
`c-default-style'.
regards,
Nikolaj Schumacher
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-20 22:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-18 23:08 Changing Emacs indentation behavior Nonni
2008-07-19 2:13 ` Juanma
2008-07-20 22:20 ` Nikolaj Schumacher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).