Subject: Re: bug#27130: c-mode indentation mistreats structs in function arguments

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 02 Dec 2020 10:55:26 +0100

Alan Mackenzie <[email-masked]> writes:

> Hello, Lars.
>
> On Mon, Nov 30, 2020 at 12:11:56 +0100, Lars Ingebrigtsen wrote:
>> Sam Pagenkopf <[email-masked]> writes:
>
>> > In emacs 25.2.1.
>
>> > Relevant code:
>
>> >     draw_add(&battle.draw, (Drawn){
>> >             .kind = DRAW_RECT,
>> >                 .size = {40,24},
>> >                 .pos.border = {
>> >                 .align = {ALIGN_LEFT, ALIGN_TOP},
>> >                 .dist = 3
>> >             }
>> >         }
>> >         );
>
>> > My guess is that it's reading (Drawn){...} as a statement, and the , as
>> > the (,) C operator.
>
>> I'm not sure how this should be indented (as I didn't even know that
>> that was valid C).  But that does look wrong, in any case.  (I've
>> confirmed that it indents it the same way in Emacs 28.)
>
>> Alan?
>
> That's strange.  In my Emacs 28 copy, I get this indentation:
>
>     int main ()
>     {
>         draw_add(&battle.draw, (Drawn){
>                 .kind = DRAW_RECT,
>                 .size = {40,24},
>                 .pos.border = {
>                     .align = {ALIGN_LEFT, ALIGN_TOP},
>                     .dist = 3
>                 }
>             }
>             );
>     }
>
> , which apart from the closing parenthesis being indented too far, looks
> basically OK.

I was thinking the next-to-last } was in a somewhat odd place (the one
that closes the Drawn), but on the other hand I don't really know where
else it should be.  On the third hand...

int main ()
{
  draw_add(&battle.draw, (Drawn)
           {
             .kind = DRAW_RECT,
             .size = {40,24},
             .pos.border = {
               .align = {ALIGN_LEFT, ALIGN_TOP},
               .dist = 3
             }
           }
           );
}

Now the end brace looks correct to me.  So perhaps it should be indented
the same way in the original case?  That is:

int main ()
{
  draw_add(&battle.draw, (Drawn) {
             .kind = DRAW_RECT,
             .size = {40,24},
             .pos.border = {
               .align = {ALIGN_LEFT, ALIGN_TOP},
               .dist = 3
             }
           }
           );
}

I'm talking about the braces only -- as you point out, the end
parenthesis is a different matter.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no