unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Sam Pagenkopf <ssaammp@gmail.com>, 27130@debbugs.gnu.org, acm@muc.de
Subject: bug#27130: c-mode indentation mistreats structs in function arguments
Date: Mon, 30 Nov 2020 17:04:34 +0000	[thread overview]
Message-ID: <X8UmIl+Yp8A/R17n__19080.0212485314$1606756311$gmane$org@ACM> (raw)
In-Reply-To: <87zh2zaykj.fsf@gnus.org>

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	other threads:[~2020-11-30 17:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-29 13:33 bug#27130: c-mode indentation mistreats structs in function arguments Sam Pagenkopf
2020-11-30 11:11 ` Lars Ingebrigtsen
2020-11-30 17:04   ` Alan Mackenzie [this message]
2020-12-02  9:55     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='X8UmIl+Yp8A/R17n__19080.0212485314$1606756311$gmane$org@ACM' \
    --to=acm@muc.de \
    --cc=27130@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=ssaammp@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).