emacs-devel
[Top][All Lists]
Advanced

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

CPP indentation bikeshed (was: Emacs master build failing on RHEL 6.8)


From: Stefan Monnier
Subject: CPP indentation bikeshed (was: Emacs master build failing on RHEL 6.8)
Date: Wed, 08 May 2019 13:16:07 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> That's correct. C89-and-later allows white space (but not comments)
> before the leading "#" in a line. K&R C did not.

Aha!  So it comes from K&R!
Thanks.

>> It's common in style rules to mandate # at the left margin, but that
>> always looked like superstition (or perverted aesthetics) to me.
> Yes, that common style is often hard to read. It exists mostly because
> of inertia. For example, by default cc-mode insists on jamming the "#"
> on the left and I have been too lazy so far to fix that (at least it
> should respect the already-existing style).

FWIW, I find indentation such as the chunk below from coding.c:

    if (VECTORP (eol_type))
      {
        /* Format of end-of-line decided by system.
           This is Qunix on Unix and Mac, Qdos on DOS/Windows.
           This has an effect only for external encoding (i.e., for output to
           file and process), not for in-buffer or Lisp string encoding.  */
        Lisp_Object system_eol_type = Qunix;
        #ifdef DOS_NT
         system_eol_type = Qdos;
        #endif

to be philosophically wrong: CPP doesn't know anything about C's
syntactic structure (such as {...} nesting), so its indentation should
only pay attention to previous CPP statement and not surrounding C code.

Basically, the way I see it, you have code from two different languages
(C and CPP) that is interleaved (in completely arbitrary ways, not
always obeying nesting) and indentation of one should not impact
indentation of the other.  E.g. the reverse situation is also something
I wouldn't like:

    #    ifdef FOO
           extern toto ();
    #    else
           extern toto (int x);
    #    endif

As for jamming # to the left: I like to do that probably mostly out of
habit, but I can rationalize it based on the argument that CPP is applied
"outside" of the C execution, so CPP statement and "layed over" the text
of the C source.


        Stefan



reply via email to

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