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

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

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


From: Alan Mackenzie
Subject: bug#27130: c-mode indentation mistreats structs in function arguments
Date: Mon, 30 Nov 2020 17:04:34 +0000

Hello, Lars.

On Mon, Nov 30, 2020 at 12:11:56 +0100, Lars Ingebrigtsen wrote:
> Sam Pagenkopf <ssaammp@gmail.com> 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.  Possibly, one might want the .kind line indented one space
further (it is indented 2 * c-basic-offset from the draw_add on the
previous line).  C-c C-s on that line gives the following analysis:

    ((arglist-cont-nonempty 19 27) (brace-list-intro 19))

.  C-c C-s on the following line should give

    ((brace-list-entry 63))

, where 63 is the position of the . in .kind.  This is correct.  In fact,
something in this area was corrected in the last three or four years, 

The closing paren is lined up by c-align-arglist-close-under-paren, which
contains a bit of DWIMery which misfires here, causing the ) to be
indented c-basic-offset from the first character on the line opening the
construct (here the draw_add line).  This DWIMery has also recently
misfired on a C++ file, so I think I'll have to modernise
c-align-arglist-close-under-paren to be more discerning.

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

-- 
Alan Mackenzie (Nuremberg, Germany).





reply via email to

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