[Top][All Lists]

[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: Anders Lindgren
Subject: bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a class
Date: Mon, 25 Apr 2016 10:20:57 +0200


I can confirm that the patch fix the problems I've seen regarding indentation of enums in C++ classes.

I would recommend that this patch is installed in Emacs 25.1, as there is a big C++ community using Emacs.

Alan, thanks for fixing this!

    -- Anders

On Fri, Apr 22, 2016 at 10:02 PM, Alan Mackenzie <address@hidden> wrote:
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

 # Built by 'make install'.

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 "=")))))

-(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))
@@ -8941,7 +8941,10 @@ c-backward-colon-prefixed-type
               (or (not (looking-at "\\s)"))
-               ((eql (char-after) ?:)
+               ((and (eql (char-after) ?:)
+                     (save-excursion
+                       (c-backward-syntactic-ws)
+                       (c-on-identifier)))
                 (setq colon-pos (point))
@@ -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))
         (eq (c-backward-token-2) 0)

>     -- Anders Lindgren

> In GNU Emacs (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]