From: Juanma <juanma_bellon@yahoo.es>
To: help-gnu-emacs@gnu.org
Subject: Re: Changing Emacs indentation behavior
Date: Sat, 19 Jul 2008 04:13:01 +0200 [thread overview]
Message-ID: <200807190413.01436.juanma_bellon@yahoo.es> (raw)
In-Reply-To: <18539174.post@talk.nabble.com>
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
next prev parent reply other threads:[~2008-07-19 2:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-18 23:08 Changing Emacs indentation behavior Nonni
2008-07-19 2:13 ` Juanma [this message]
2008-07-20 22:20 ` Nikolaj Schumacher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200807190413.01436.juanma_bellon@yahoo.es \
--to=juanma_bellon@yahoo.es \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).