unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Nikolai Weibull <now@disu.se>
To: Alan Mackenzie <acm@muc.de>
Cc: Nikolai Weibull <now@disu.se>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	Emacs Developers <emacs-devel@gnu.org>
Subject: Re: C99 compound literals in c-mode
Date: Wed, 23 Aug 2017 12:01:34 +0200	[thread overview]
Message-ID: <CADdV=MufQUQMcoueaqiAdqveaUYy7jSLTPV+j6kn0yva4WgKcg@mail.gmail.com> (raw)
In-Reply-To: <20170820204030.GA8206@ACM>

On Sun, Aug 20, 2017 at 10:40 PM, Alan Mackenzie <acm@muc.de> 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
>> <monnier@iro.umontreal.ca> 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	other threads:[~2017-08-23 10:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15  8:04 C99 compound literals in c-mode Nikolai Weibull
2017-08-15  9:03 ` Stefan Monnier
2017-08-15  9:56   ` Nikolai Weibull
2017-08-15  9:57   ` Helmut Eller
2017-08-15  9:57   ` Nikolai Weibull
2017-08-16 17:26     ` Alan Mackenzie
2017-08-16 17:52       ` Nikolai Weibull
2017-08-20 20:40     ` Alan Mackenzie
2017-08-23 10:01       ` Nikolai Weibull [this message]
2017-08-24 16:37         ` Alan Mackenzie

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='CADdV=MufQUQMcoueaqiAdqveaUYy7jSLTPV+j6kn0yva4WgKcg@mail.gmail.com' \
    --to=now@disu.se \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).