all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How do I make emacs indent treat #ifdef and #endif as if they were { and }?
@ 2012-02-03 21:49 Jules Colding
  2012-02-08 21:57 ` Ken Goldman
       [not found] ` <mailman.3503.1328738521.15002.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Jules Colding @ 2012-02-03 21:49 UTC (permalink / raw
  To: help-gnu-emacs

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






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do I make emacs indent treat #ifdef and #endif as if they were { and }?
  2012-02-03 21:49 How do I make emacs indent treat #ifdef and #endif as if they were { and }? Jules Colding
@ 2012-02-08 21:57 ` Ken Goldman
  2012-02-08 22:01   ` Jules Colding
       [not found] ` <mailman.3503.1328738521.15002.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Ken Goldman @ 2012-02-08 21:57 UTC (permalink / raw
  To: help-gnu-emacs

If you care about portability, some older compilers do not permit white 
space before the #.

On 2/3/2012 4:49 PM, Jules Colding wrote:
>
> 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.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do I make emacs indent treat #ifdef and #endif as if they were { and }?
  2012-02-08 21:57 ` Ken Goldman
@ 2012-02-08 22:01   ` Jules Colding
  0 siblings, 0 replies; 4+ messages in thread
From: Jules Colding @ 2012-02-08 22:01 UTC (permalink / raw
  To: help-gnu-emacs


On Feb 8, 2012, at 10:57 PM, Ken Goldman wrote:

> If you care about portability, some older compilers do not permit white space before the #.

I don't. I just want the source to look as readable as possible. I don't care if it can't compile in some old compiler. Most, if not all, recent compilers are happy about spaces before the #.

Cheers,
  jules





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do I make emacs indent treat #ifdef and #endif as if they were { and }?
       [not found]     ` <icpqcjye2l.fsf@home.home>
@ 2012-04-04  7:41       ` David Combs
  0 siblings, 0 replies; 4+ messages in thread
From: David Combs @ 2012-04-04  7:41 UTC (permalink / raw
  To: help-gnu-emacs

In article <icpqcjye2l.fsf@home.home>, Dan Espen  <despen@verizon.net> wrote:
>dkcombs@panix.com (David Combs) writes:
>
>> In article <mailman.3503.1328738521.15002.help-gnu-emacs@gnu.org>,
>> Jules Colding  <colding@venalicium.dk> wrote:
>>>
>>>On Feb 8, 2012, at 10:57 PM, Ken Goldman wrote:
>>>
>>>> If you care about portability, some older compilers do not permit white space before the #.
>>>
>>>I don't. I just want the source to look as readable as possible. I don't care if it can't compile in some old compiler. Most, if not all, recent compilers are happy
>>>about spaces before the #.
>>>
>>>Cheers,
>>>  jules
>>>
>>>
>>>
>>
>> Aren't there well-known (unix) programs whose sole purpose is
>> to "beautify" (via indenting) various kinds of files?
>>
>> Maybe "indent" is the name of one.  
>>
>> I recall looking at either that or another one once,
>> but it had so many complicated options that it overwhelmed
>> me.
>>
>> Maybe things have improved since then -- I don't know.
>
>Last time I used it I noticed a huge number of options.
>
>So, I just used it once, looked at the results,
>then searched the man page for things I wanted to change.
>
>
>-- 
>Dan Espen

Maybe someone here uses that program.  If so, and you're one
of the indent users, perhaps you could show us some indent runs,
with options, and for each run (or just invocation),
say what you wanted to accomplish, and
why you used those options, and maybe how you came up with
that set of options.

That would *really* be useful, would make indent a *lot* more
likely to get used.


Thanks!

David



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-04  7:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-03 21:49 How do I make emacs indent treat #ifdef and #endif as if they were { and }? Jules Colding
2012-02-08 21:57 ` 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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.