bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a c


From: Alan Mackenzie
Subject: bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a class
Date: 22 Apr 2016 20:02:08 -0000
User-agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.3-RELEASE (amd64))

Hello, Anders.

In article <address@hidden> 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).






reply via email to

[Prev in Thread] Current Thread [Next in Thread]