From: Alan Mackenzie <acm@muc.de>
To: Anders Lindgren <andlind@gmail.com>
Cc: 23312@debbugs.gnu.org
Subject: bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a class
Date: 22 Apr 2016 20:02:08 -0000 [thread overview]
Message-ID: <20160422200208.40627.qmail@mail.muc.de> (raw)
In-Reply-To: <mailman.648.1461058386.7477.bug-gnu-emacs@gnu.org>
Hello, Anders.
In article <mailman.648.1461058386.7477.bug-gnu-emacs@gnu.org> you wrote:
> [-- text/plain, encoding 7bit, charset: UTF-8, 101 lines --]
> In C++ mode in Emacs 25.0.92, enums inside classes are incorrectly indented.
> For example (emacs -Q):
> class MyClass
> {
> public:
> enum Id
> {
> kAlpha,
> kBeta // Incorrect indentation.
> In Emacs 24.5, the "kAlpha" and "kBeta" were aligned, as expected.
This was caused by an enhancement (for C++ typed enums) which failed
properly to check its occurrence.
I think the following patch fixes the bug. Would you please try it out
in real code, and either confirm it works properly, or tell me what is
still faulty. Thanks!
diff --git a/.gitignore b/.gitignore
index 7c8b743..c1d9067 100644
--- a/.gitignore
+++ b/.gitignore
@@ -261,7 +261,10 @@ ChangeLog
[0-9]*.txt
.dir-locals?.el
/vc-dwim-log-*
+*.diff
+.gitattributes
+*.acm
# Built by 'make install'.
etc/emacs.tmpdesktop
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 62bc236..1be438f 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -8928,11 +8928,11 @@ c-cheap-inside-bracelist-p
(not (looking-at "=")))))
b-pos)))
-(defun c-backward-colon-prefixed-type ()
- ;; We're at the token after what might be a type prefixed with a colon. Try
- ;; moving backward over this type and the colon. On success, return t and
- ;; leave point before colon; on failure, leave point unchanged. Will clobber
- ;; match data.
+(defun c-backward-typed-enum-colon ()
+ ;; We're at a "{" which might be the opening brace of a enum which is
+ ;; strongly typed (by a ":" followed by a type). If this is the case, leave
+ ;; point before the colon and return t. Otherwise leave point unchanged and return nil.
+ ;; Match data will be clobbered.
(let ((here (point))
(colon-pos nil))
(save-excursion
@@ -8941,7 +8941,10 @@ c-backward-colon-prefixed-type
(or (not (looking-at "\\s)"))
(c-go-up-list-backward))
(cond
- ((eql (char-after) ?:)
+ ((and (eql (char-after) ?:)
+ (save-excursion
+ (c-backward-syntactic-ws)
+ (c-on-identifier)))
(setq colon-pos (point))
(forward-char)
(c-forward-syntactic-ws)
@@ -8965,7 +8968,7 @@ c-backward-over-enum-header
(let ((here (point))
up-sexp-pos before-identifier)
(when c-recognize-post-brace-list-type-p
- (c-backward-colon-prefixed-type))
+ (c-backward-typed-enum-colon))
(while
(and
(eq (c-backward-token-2) 0)
> -- Anders Lindgren
> In GNU Emacs 25.0.92.1 (i686-w64-mingw32)
> of 2016-03-21 built on LAPHROAIG
> Windowing system distributor 'Microsoft Corp.', version 6.1.7601
> Configured using:
> 'configure --host=i686-w64-mingw32 --without-dbus
> --without-compress-install CFLAGS=-static'
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2016-04-22 20:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-19 9:32 bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a class Anders Lindgren
[not found] ` <mailman.648.1461058386.7477.bug-gnu-emacs@gnu.org>
2016-04-22 20:02 ` Alan Mackenzie [this message]
2016-04-25 8:20 ` Anders Lindgren
2016-04-29 13:42 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160422200208.40627.qmail@mail.muc.de \
--to=acm@muc.de \
--cc=23312@debbugs.gnu.org \
--cc=andlind@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.