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

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

bug#30115: 25.1; cc-mode (C++) : bad indentation on function closing cur


From: Alan Mackenzie
Subject: bug#30115: 25.1; cc-mode (C++) : bad indentation on function closing curly brackets
Date: Fri, 19 Jan 2018 18:01:36 +0000
User-agent: Mutt/1.7.2 (2016-11-26)

Hello, Gaétam/

On Sun, Jan 14, 2018 at 23:13:23 +0000, Gaétan Allaert wrote:

> It is about an indentation issue in C++.

> The closing curly bracket at the end of the function is wrongly indented
> when:
> 1. at least one base_1 exists (the comma at the end of base_1 is
>    required);
> 2. base_2 is the last call before the opening curly bracket of the
>    function;
> 3. base_2 has only 1 argument that must be a symbol, not a literal or a
>    string.

> Example:
> foo_good::foo_good (int arg_1, int arg_2) :
>   base_1 (),
>   base_2 (arg_1, arg_2) {
> } // good indentation

> foo_bad::foo_bad (int arg_1, int arg_2) :
>   base_1 (),
>   base_2 (arg_1) {
>   } // bad identation

> Thanks to have a look at this issue.



> In GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
>  of 2017-09-15, modified by Debian built on trouble
> Windowing system distributor 'The X.Org Foundation', version 11.0.11902000
> System Description:   Debian GNU/Linux 9.3 (stretch)

[ .... ]

Thanks for taking the trouble to report this bug, and thanks even more
for cutting your example down to a concise, easy to work with snippet.
It seems already to be fixed in the emacs-26 branch, the fix being for
an entirely different symptom, but appears to fix this, too.

It will be some time before Emacs 26 gets released.  In the meantime,
can I ask you to apply the following patch to cc-engine.el in your Emacs
25.1 (in .../emacs/lisp/progmodes), compile it, and test it with your
real code.  (If you want any help applying the patch or compiling the
file, feel free to contact me by private mail.)  Would you please let me
know how well it solves the problem in your real code.  Thanks.



--- cc-engine.20180119.eeel     2017-10-01 17:14:49.185254672 +0000
+++ cc-engine.el        2018-01-19 17:49:09.308202347 +0000
@@ -7615,8 +7615,10 @@
 
         ;; CASE 11
         (when (and got-identifier
-                   (not context)
                    (looking-at c-after-suffixed-type-decl-key)
+                   (or (eq context 'top)
+                       (and (eq context nil)
+                            (match-beginning 1)))
                    (if (and got-parens
                             (not got-prefix)
                             (not got-suffix)
@@ -8287,7 +8289,7 @@
               (c-forward-objc-directive)))
 
      (setq id-start
-          (car-safe (c-forward-decl-or-cast-1 (c-point 'bosws) nil nil)))
+          (car-safe (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil)))
      (< id-start beg)
 
      ;; There should not be a '=' or ',' between beg and the



-- 
Alan Mackenzie (Nuremberg, Germany).





reply via email to

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