unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 王斌波 <binbowang1987@163.com>
Cc: acm@muc.de, 48992@debbugs.gnu.org
Subject: bug#48992: cc-mode initialize list indentation bug
Date: Sat, 21 Aug 2021 17:57:33 +0000	[thread overview]
Message-ID: <YSE+jQnpZG4UvKfL@ACM> (raw)
In-Reply-To: <56c9cab5.165.17a028f7978.Coremail.binbowang1987@163.com>

[-- Attachment #1: Type: text/plain, Size: 1248 bytes --]

Hello, Binbowang.

On Sun, Jun 13, 2021 at 07:29:55 +0800, 王斌波 wrote:
> class A {
> public:
>   static std::set<int> setA;
> };


> std::set<int> A::setA {
>   1,
>     2,
>     3
> }


> The indentation in setA initialize list is not correct. I want it like the following.
> class A {
> public:
>   static std::set<int> setA;
> };


> std::set<int> A::setA {
>   1,
>   2,
>   3
> }

The indentation was indeed incorrect.  CC Mode was mis-analysing the
brace list as a function.  I think the patch attached should fix this.

Would you please apply the patch to your CC Mode (in directory
..../emacs/lisp/progmodes), byte compile that file, load it into your
Emacs and try it out on your real C++ source code.  Then please let me
know if the bug is indeed fixed.  (If you would like any help with the
patching or byte compilation, feel free to send me private email.)


> In GNU Emacs 27.1 (build 1, x86_64-w64-mingw32)
>  of 2020-08-22 built on CIRROCUMULUS
> Repository revision: 86d8d76aa36037184db0b2897c434cdaab1a9ae8
> Repository branch: HEAD
> Windowing system distributor 'Microsoft Corp.', version 10.0.19042
> System Description: Microsoft Windows 10 Pro (v10.0.2009.19042.1052)

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).


[-- Attachment #2: diff.20210821.diff --]
[-- Type: text/plain, Size: 1052 bytes --]

diff -r 92a4592886a1 cc-engine.el
--- a/cc-engine.el	Sun Apr 25 17:26:38 2021 +0000
+++ b/cc-engine.el	Sat Aug 21 17:38:30 2021 +0000
@@ -11882,12 +11882,15 @@
 	  pos2 in-paren parens-before-brace
 	  paren-state paren-pos)
 
-      (setq res (c-backward-token-2 1 t lim))
+      (setq res
+	    (or (progn (c-backward-syntactic-ws)
+		       (c-back-over-compound-identifier))
+		(c-backward-token-2 1 t lim)))
       ;; Checks to do only on the first sexp before the brace.
       ;; Have we a C++ initialization, without an "="?
       (if (and (c-major-mode-is 'c++-mode)
 	       (cond
-		((and (or (not (eq res 0))
+		((and (or (not (memq res '(t 0)))
 			  (eq (char-after) ?,))
 		      (setq paren-state (c-parse-state))
 		      (setq paren-pos (c-pull-open-brace paren-state))
@@ -11911,7 +11914,7 @@
 		(t nil))
 	       (save-excursion
 		 (cond
-		  ((or (not (eq res 0))
+		  ((or (not (memq res '(t 0)))
 		       (eq (char-after) ?,))
 		   (and (setq paren-state (c-parse-state))
 			(setq paren-pos (c-pull-open-brace paren-state))

  reply	other threads:[~2021-08-21 17:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-12 23:29 bug#48992: cc-mode initialize list indentation bug 王斌波
2021-08-21 17:57 ` Alan Mackenzie [this message]
2021-08-28  1:40   ` 王斌波
2021-08-29 14:56     ` 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=YSE+jQnpZG4UvKfL@ACM \
    --to=acm@muc.de \
    --cc=48992@debbugs.gnu.org \
    --cc=binbowang1987@163.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).