bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CC Mode 5.28 (C); Bad indent of code inside macro call


From: Martin Stjernholm
Subject: Re: CC Mode 5.28 (C); Bad indent of code inside macro call
Date: 20 Jun 2001 22:51:01 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Stefan Monnier <monnier@cs.yale.edu> wrote:

> The following piece of code has been indented by CC-mode.
> 
>     int
>     invisible_p (propval, list)
>          register Lisp_Object propval;
>          Lisp_Object list;
>     {
>       register Lisp_Object propelt, tem;
>       LOOP_PROPVAL (propelt, propval,
>                     DOLIST (tem, list,
>                             if (EQ (propelt, tem))
>                             return 1;
>                             if (CONSP (tem) && EQ (propelt, XCAR (tem)))
>                             return 1;));
>     }
> 
> Clearly the two `return 1;' statements should be indented 2 chars further.

It's a known problem that CC Mode doesn't always do the right thing
when macros are involved, since they can break the normal syntactic
rules in almost any way. In this case, CC Mode checks the enclosing
paren, sees that it's a '(' and thus indents the contents as an
argument list. It would be possible to instead search backward by
token and see if it looks like a statement or a declaration, but it
wouldn't always work and it would be significantly slower.

I often recommend that macros are used in a way that makes them follow
the normal syntactic rules as much as possible; that tend to confuse
both CC Mode and the reader less(*). Here it can be done by enclosing
the statements in a brace block.

*)  Although the latter is arguably not a problem in this specific
    case, given that the indentation is sane. It often is in other
    cases, however, e.g. when a macro opens a block but the
    corresponding closing paren is written directly in the code.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]