From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Nikolai Weibull Newsgroups: gmane.emacs.devel Subject: Re: C99 compound literals in c-mode Date: Wed, 23 Aug 2017 12:01:34 +0200 Message-ID: References: <20170820204030.GA8206@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1503482552 9089 195.159.176.226 (23 Aug 2017 10:02:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 23 Aug 2017 10:02:32 +0000 (UTC) Cc: Nikolai Weibull , Stefan Monnier , Emacs Developers To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 23 12:02:24 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dkSUI-0001TB-CQ for ged-emacs-devel@m.gmane.org; Wed, 23 Aug 2017 12:02:14 +0200 Original-Received: from localhost ([::1]:42723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkSUL-0008GY-Rs for ged-emacs-devel@m.gmane.org; Wed, 23 Aug 2017 06:02:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkSTm-0008GG-8C for emacs-devel@gnu.org; Wed, 23 Aug 2017 06:01:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkSTj-0005Nw-5S for emacs-devel@gnu.org; Wed, 23 Aug 2017 06:01:42 -0400 Original-Received: from disu.se ([71.19.156.204]:38978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkSTi-0005ND-T8 for emacs-devel@gnu.org; Wed, 23 Aug 2017 06:01:39 -0400 Original-Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by disu.se (Postfix) with ESMTPSA id C918EC0AE for ; Wed, 23 Aug 2017 12:01:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=disu.se; s=mail; t=1503482492; bh=+nNYhCoTHJJgWFRvuj2VmUkfOVovTvjT2NyvLQj/ALE=; l=1929; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=JlHDrb3nFzWpwkmYaKIGgmcRbKGOnI+A0Rt3zLV9qAcBQyVGQI/DOCtzyEKqz6mlc mZ2yqjy0dKEOVoXaSqC1rQbStlGKYSXlHrSAJqFf+Q/Hz0ZK0oybfYF25+2v3X2kLF HYPXEu8ZRv2Q/KnAqJL0/lvJzffhZIE100yVQfmE= Original-Received: by mail-wm0-f53.google.com with SMTP id l19so11926131wmi.1 for ; Wed, 23 Aug 2017 03:01:35 -0700 (PDT) X-Gm-Message-State: AHYfb5j1REMWhGc5mKbQ1+8uhB2556WxLbUw+5PFsgYmtQZXT2g/RyAf ig3+NAX4d9c1b6AWdikla/EdorfHpA== X-Received: by 10.80.145.189 with SMTP id g58mr2688223eda.14.1503482494588; Wed, 23 Aug 2017 03:01:34 -0700 (PDT) Original-Received: by 10.80.183.131 with HTTP; Wed, 23 Aug 2017 03:01:34 -0700 (PDT) In-Reply-To: <20170820204030.GA8206@ACM> X-Gmail-Original-Message-ID: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 71.19.156.204 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217719 Archived-At: On Sun, Aug 20, 2017 at 10:40 PM, Alan Mackenzie 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 >> wrote: >> >> C-mode doesn=E2=80=99t seem to understand C99=E2=80=99s compound lite= rals, 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=E2=80=99t even defined. Nikolai