emacs-devel
[Top][All Lists]
Advanced

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

Re: C99 compound literals in c-mode


From: Nikolai Weibull
Subject: Re: C99 compound literals in c-mode
Date: Wed, 23 Aug 2017 12:01:34 +0200

On Sun, Aug 20, 2017 at 10:40 PM, Alan Mackenzie <address@hidden> wrote:
> Hello, Nikolai.
>
> On Tue, Aug 15, 2017 at 11:57:25 +0200, Nikolai Weibull wrote:
>> On Tue, Aug 15, 2017 at 11:03 AM, Stefan Monnier
>> <address@hidden> wrote:
>> >> C-mode doesn’t seem to understand C99’s compound literals, resulting in
>> >> rather broken indentation.  Is this correct and, if so, how difficult 
>> >> would
>> >> it be to add support for it?
>
>> > Could you show some example problematic code?
>
>> Yes:
>
>> struct a {
>>         int b;
>> };
>
> This seems to be correctly analysed and indented by CC Mode.  You can
> see this by doing C-c C-s on any line to get the syntactic analysis.  On
> the middle line, this shows ((inclass 332) (topmost-intro 332)) (where
> the "332" may vary, depending on the position in the file).  The
> "inclass" bit causes an indentation of c-basic-offset (here 8) columns.
>
> What indentation do you want here?

Sorry, this was just there to give a complete example, it indents
correctly as is.

>> int
>> main(void)
>> {
>>         return (struct a){
>>                 0
>>                         }.b;
>> }

> Here, the "0" line is being wrongly analysed as a statement-block-intro,
> when it should be a brace-list-intro.  The problem is that brace lists
> are recognised only by their context in the source code, rather than
> their internal structure.  When a brace list can appear virtually
> anywhere, this doesn't make sense.
>
> The following patch causes brace lists to be recognised by their
> internal structure too.  Would you please apply it to CC Mode (in
> directory .../lisp/progmodes), try it out, and let me know how well it
> solves the problems with compound literals.

This seems to be a patch for a newer version of CC Mode than that
installed with my Emacs (25.2.1 via MacPorts).  The function
c-looking-at-statement-block isn’t even defined.

  Nikolai



reply via email to

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