unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Pre-processor commands in c-mode
@ 2003-03-21 20:01 Kevin Dziulko
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Dziulko @ 2003-03-21 20:01 UTC (permalink / raw)


Hello

Does any one know of a good method / setting / package for better
handling of pre-processor commands in c-mode, specificly spacing
and auto-indentation?

For example, if I enter the folloeing code, the #endif moves to
the beginning of the line when I press enter after it.

int main ()
{
    if (x)
    {
        #ifdef DEBUG
        printf("null");
#endif
    }
}

Thanks for any help.
Kevin

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

* Re: Pre-processor commands in c-mode
       [not found] <mailman.3490.1048277110.21513.help-gnu-emacs@gnu.org>
@ 2003-03-21 22:33 ` Pascal Bourguignon
  2003-03-22 16:14 ` Benjamin Riefenstahl
  1 sibling, 0 replies; 6+ messages in thread
From: Pascal Bourguignon @ 2003-03-21 22:33 UTC (permalink / raw)



Kevin Dziulko <dziulko@klaatu.canisius.edu> writes:

> Hello
> 
> Does any one know of a good method / setting / package for better
> handling of pre-processor commands in c-mode, specificly spacing
> and auto-indentation?
> 
> For example, if I enter the folloeing code, the #endif moves to
> the beginning of the line when I press enter after it.
> 
> int main ()
> {
>     if (x)
>     {
>         #ifdef DEBUG
>         printf("null");
> #endif
>     }
> }
> 
> Thanks for any help.
> Kevin

Of course. The normal indentation for cpp directive is column 0:

int main ()
{
    if (x)
        {
#ifdef DEBUG
            printf("null");
#endif
        }
}


Normally, cpp takes into account only directive whose '#' is in column 0.
That's why you sometimes see directives indented this way:

#ifdef COND1
#  ifdef COND2
#     ifdef COND3
#     else
#     endif
#  endif
#else
#  ifdef COND2
#  endif
#endif


-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
Do not adjust your mind, there is a fault in reality.

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

* Re: Pre-processor commands in c-mode
       [not found] <mailman.3490.1048277110.21513.help-gnu-emacs@gnu.org>
  2003-03-21 22:33 ` Pre-processor commands in c-mode Pascal Bourguignon
@ 2003-03-22 16:14 ` Benjamin Riefenstahl
  2003-03-22 17:08   ` Alan Shutko
  1 sibling, 1 reply; 6+ messages in thread
From: Benjamin Riefenstahl @ 2003-03-22 16:14 UTC (permalink / raw)


Hi Kevin, Pascal,


Kevin Dziulko <dziulko@klaatu.canisius.edu> writes:
> Does any one know of a good method / setting / package for better
> handling of pre-processor commands in c-mode, specificly spacing and
> auto-indentation?

Have a look at the CC mode manual in Info (C-h i).  It has several
chapters on customizing indentation.  You probably want to change the
cpp-macro indentation setting.

> Kevin Dziulko <dziulko@klaatu.canisius.edu> writes:
> >     if (x)
> >     {
> >         #ifdef DEBUG
> >         printf("null");

Pascal Bourguignon <pjb@informatimago.com> writes:
> Normally, cpp takes into account only directive whose '#' is in column 0.
> That's why you sometimes see directives indented this way:
> 
> #ifdef COND1
> #  ifdef COND2

Actually the C preprocessor doesn't care, the syntax intended by Kevin
is legal and works.  Whether it is good style is another question.


Hope this helps, benny

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

* Re: Pre-processor commands in c-mode
  2003-03-22 16:14 ` Benjamin Riefenstahl
@ 2003-03-22 17:08   ` Alan Shutko
  2003-03-22 20:56     ` Benjamin Riefenstahl
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Shutko @ 2003-03-22 17:08 UTC (permalink / raw)


Benjamin Riefenstahl <Benjamin.Riefenstahl@epost.de> writes:

> Pascal Bourguignon <pjb@informatimago.com> writes:
>> Normally, cpp takes into account only directive whose '#' is in column 0.

> Actually the C preprocessor doesn't care, the syntax intended by Kevin
> is legal and works.  Whether it is good style is another question.

Old preprocessors did care.  Everything that is ANSI-compliant
doesn't care.  

-- 
Alan Shutko <ats@acm.org> - I am the rocks.
Looking for a developer in St. Louis? http://web.springies.com/~ats/
If you like fast foods, forget the escargot.

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

* Re: Pre-processor commands in c-mode
  2003-03-22 17:08   ` Alan Shutko
@ 2003-03-22 20:56     ` Benjamin Riefenstahl
  2003-03-23 15:08       ` Alan Shutko
  0 siblings, 1 reply; 6+ messages in thread
From: Benjamin Riefenstahl @ 2003-03-22 20:56 UTC (permalink / raw)


Hi Alan,

Alan Shutko <ats@acm.org> writes:
> Old preprocessors did care.  Everything that is ANSI-compliant
> doesn't care.

Introduction of that standard was 13 years ago.

so long, benny

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

* Re: Pre-processor commands in c-mode
  2003-03-22 20:56     ` Benjamin Riefenstahl
@ 2003-03-23 15:08       ` Alan Shutko
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Shutko @ 2003-03-23 15:08 UTC (permalink / raw)


Benjamin Riefenstahl <Benjamin.Riefenstahl@epost.de> writes:

> Alan Shutko <ats@acm.org> writes:
>> Old preprocessors did care.  Everything that is ANSI-compliant
>> doesn't care.
>
> Introduction of that standard was 13 years ago.

I was just clarifying.  Up until a couple years ago, we could depend
on certain ANSI features at work since some of our clients' systems
did not have ANSI compilers.

-- 
Alan Shutko <ats@acm.org> - I am the rocks.
Looking for a developer in St. Louis? http://web.springies.com/~ats/
Kids: Nature's version of the pleasure tax!

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

end of thread, other threads:[~2003-03-23 15:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3490.1048277110.21513.help-gnu-emacs@gnu.org>
2003-03-21 22:33 ` Pre-processor commands in c-mode Pascal Bourguignon
2003-03-22 16:14 ` Benjamin Riefenstahl
2003-03-22 17:08   ` Alan Shutko
2003-03-22 20:56     ` Benjamin Riefenstahl
2003-03-23 15:08       ` Alan Shutko
2003-03-21 20:01 Kevin Dziulko

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).