unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a class
@ 2016-04-19  9:32 Anders Lindgren
       [not found] ` <mailman.648.1461058386.7477.bug-gnu-emacs@gnu.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Anders Lindgren @ 2016-04-19  9:32 UTC (permalink / raw)
  To: 23312

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

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.

    -- 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'

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS

Important settings:
  value of $LANG: SVE
  locale-coding-system: cp1252

Major mode: C++/l

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
foo3.cpp has auto save data; consider M-x recover-this-file
Mark set
previous-line: Beginning of buffer [3 times]
Quit

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message dired format-spec rfc822 mml
mml-sec epg epg-config gnus-util mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util help-fns mail-prsvr mail-utils cl-extra
help-mode cc-mode cc-fonts easymenu cc-guess cc-menus cc-cmds cc-styles
cc-align cc-engine cc-vars cc-defs cl-loaddefs pcase cl-lib time-date
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel dos-w32 ls-lisp disp-table w32-win w32-vars
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
w32notify w32 multi-tty make-network-process emacs)

Memory information:
((conses 8 108925 13058)
 (symbols 32 21629 0)
 (miscs 32 50 193)
 (strings 16 21243 4209)
 (string-bytes 1 701321)
 (vectors 8 14828)
 (vector-slots 4 458715 7672)
 (floats 8 165 57)
 (intervals 28 291 37)
 (buffers 520 13))

-- 
-- 
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

[-- Attachment #2: Type: text/html, Size: 4213 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a class
       [not found] ` <mailman.648.1461058386.7477.bug-gnu-emacs@gnu.org>
@ 2016-04-22 20:02   ` Alan Mackenzie
  2016-04-25  8:20     ` Anders Lindgren
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Mackenzie @ 2016-04-22 20:02 UTC (permalink / raw)
  To: Anders Lindgren; +Cc: 23312

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).






^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a class
  2016-04-22 20:02   ` Alan Mackenzie
@ 2016-04-25  8:20     ` Anders Lindgren
  2016-04-29 13:42       ` Alan Mackenzie
  0 siblings, 1 reply; 4+ messages in thread
From: Anders Lindgren @ 2016-04-25  8:20 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 23312

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

Hi!

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 <acm@muc.de> wrote:

> 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).
>
>

[-- Attachment #2: Type: text/html, Size: 4793 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#23312: 25.0.92; C++: Incorrect indentation of enum values inside a class
  2016-04-25  8:20     ` Anders Lindgren
@ 2016-04-29 13:42       ` Alan Mackenzie
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2016-04-29 13:42 UTC (permalink / raw)
  To: 23312-done; +Cc: Anders Lindgren

Bug fixed in branch emacs-25.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-29 13:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-04-25  8:20     ` Anders Lindgren
2016-04-29 13:42       ` Alan Mackenzie

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).