From: Jules Colding <colding@venalicium.dk>
To: help-gnu-emacs@gnu.org
Subject: How do I make emacs indent treat #ifdef and #endif as if they were { and }?
Date: Fri, 3 Feb 2012 22:49:35 +0100 [thread overview]
Message-ID: <1AEEB8AA-7A49-4338-B5EC-9234FE5C1CFD@venalicium.dk> (raw)
Hi,
I've tried to figure out how to make emacs indent #ifdef blocks just like it would curly brace blocks. With a twist though… I'd prefer if I could convince emacs to indent include statement half the amount of whitespace that normal code would be indented.
My preference is to indent code with 8 spaces (or one tab of that size) and then use 4 spaces for include statements. Within code my preference would be if "#ifdef" was treated exactly as a "{" and "#endif" like a "}", indentation wise.
Like this:
#include <ifaddrs.h>
#ifdef __linux__
#include <sys/socket.h>
#endif
int
func(void)
{
int foo = 0;
#ifdef DO_STUFF
foo = do_stuff();
#endif
return foo;
}
instead of the current affair:
#include <ifaddrs.h>
#ifdef __linux__
#include <sys/socket.h>
#endif
int
func(void)
{
int foo = 0;
#ifdef DO_STUFF
foo = do_stuff();
#endif
return foo;
}
Messing around with the indentation functions in emacs seems like a black art. Likely because I don't do lisp well...
Would anyone have code that solves this or pointers to something that is close to what I want?
Thanks a lot,
jules
next reply other threads:[~2012-02-03 21:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-03 21:49 Jules Colding [this message]
2012-02-08 21:57 ` How do I make emacs indent treat #ifdef and #endif as if they were { and }? Ken Goldman
2012-02-08 22:01 ` Jules Colding
[not found] ` <mailman.3503.1328738521.15002.help-gnu-emacs@gnu.org>
[not found] ` <jjh1pi$7kb$4@reader1.panix.com>
[not found] ` <icpqcjye2l.fsf@home.home>
2012-04-04 7:41 ` David Combs
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=1AEEB8AA-7A49-4338-B5EC-9234FE5C1CFD@venalicium.dk \
--to=colding@venalicium.dk \
--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).