Subject: Re: bug#61635: 30.0.50; c++-ts-mode: "}" indented wrong when a class in namespace

From: Daniel Martín <[email-masked]>
Date: Sun, 19 Feb 2023 23:13:06 +0100

tags 61635 + patch
quit

xhcoding <[email-masked]> writes:

> The closing '};' is indented wrong in the following class/struct definition:
>
> namespace test {
>   class Name {
> };  <--  error indent
>     
> } <-- when press tab, minibuffer output "Wrong type argument: wholenump, -2" 
>
>

The attached patch fixes the problem by considering "declaration_list"
nodes as "blocks".

>From 1435efef0e3c6af871f97be9553a92cd125f4ffb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <[email-masked]>
Date: Sun, 19 Feb 2023 22:57:54 +0100
Subject: [PATCH] Add declaration_list to c-ts-common-indent-type-regexp-alist

* lisp/progmodes/c-ts-mode.el (c-ts-base-mode): Consider a
"declaration_list" a block. (Bug#61635)
* test/lisp/progmodes/c-ts-mode-resources/indent.erts (Code): Add a
test case.
---
 lisp/progmodes/c-ts-mode.el                      |  3 ++-
 .../progmodes/c-ts-mode-resources/indent.erts    | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index a60c464093e..43b88cd57b1 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -774,7 +774,8 @@ c-ts-base-mode
               `((block . ,(rx (or "compound_statement"
                                   "field_declaration_list"
                                   "enumerator_list"
-                                  "initializer_list")))
+                                  "initializer_list"
+                                  "declaration_list")))
                 (if . "if_statement")
                 (else . ("if_statement" . "alternative"))
                 (do . "do_statement")
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 05d59c10a42..a4f700e7c79 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -354,3 +354,19 @@ int main()
   };
 }
 =-=-=
+
+Code:
+  (lambda ()
+    (c++-ts-mode)
+    (setq-local indent-tabs-mode nil)
+    (setq-local c-ts-mode-indent-offset 2)
+    (indent-region (point-min) (point-max)))
+
+Name: Declaration List (Namespace) (Bug#61635)
+
+=-=
+namespace test {
+  class Name {
+  };
+}
+=-=-=
-- 
2.34.1