emacs-diffs
[Top][All Lists]
Advanced

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

emacs-29 f2114e8d89: Fix indentation for closing bracket in c-ts-mode (b


From: Yuan Fu
Subject: emacs-29 f2114e8d89: Fix indentation for closing bracket in c-ts-mode (bug#61398)
Date: Sun, 12 Feb 2023 22:50:44 -0500 (EST)

branch: emacs-29
commit f2114e8d89feed154a1c523c925ff2fb9fa9ba9a
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Fix indentation for closing bracket in c-ts-mode (bug#61398)
    
    * lisp/progmodes/c-ts-mode.el:
    (c-ts-mode--indent-styles): Move the rule earlier.
    (c-ts-base-mode): Add move block type.
    * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New tests.
---
 lisp/progmodes/c-ts-mode.el                        | 11 ++++++---
 .../lisp/progmodes/c-ts-mode-resources/indent.erts | 27 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index b898f7d9ee..af7aa1c3a0 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -272,6 +272,11 @@ MODE is either `c' or `cpp'."
                  ;; Indent the body of namespace definitions.
                  ((parent-is "declaration_list") parent-bol 
c-ts-mode-indent-offset)))
 
+           ;; Closing bracket.  This should be before initializer_list
+           ;; (and probably others) rule because that rule (and other
+           ;; similar rules) will match the closing bracket.  (Bug#61398)
+           ((node-is "}") point-min c-ts-common-statement-offset)
+
            ;; int[5] a = { 0, 0, 0, 0 };
            ((parent-is "initializer_list") parent-bol c-ts-mode-indent-offset)
            ;; Statement in enum.
@@ -281,8 +286,6 @@ MODE is either `c' or `cpp'."
 
            ;; Statement in {} blocks.
            ((parent-is "compound_statement") point-min 
c-ts-common-statement-offset)
-           ;; Closing bracket.
-           ((node-is "}") point-min c-ts-common-statement-offset)
            ;; Opening bracket.
            ((node-is "compound_statement") point-min 
c-ts-common-statement-offset)
            ;; Bug#61291.
@@ -768,7 +771,9 @@ the semicolon.  This function skips the semicolon."
   (setq-local c-ts-common-indent-type-regexp-alist
               `((block . ,(rx (or "compound_statement"
                                   "field_declaration_list"
-                                  "enumerator_list")))
+                                  "enumerator_list"
+                                  "initializer_list"
+                                  "field_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 21b84c2e7e..05d59c10a4 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -182,6 +182,20 @@ else if (false)
   return 3;
 =-=-=
 
+Name: Initializer List (Bug#61398)
+
+=-=
+int main()
+{
+  const char *emoticons[][2] =
+    {
+      {":-)", "SLIGHTLY SMILING FACE"},
+      {";-)", "WINKING FACE"},
+      {":-(", "SLIGHTLY FROWNING FACE"},
+    };
+}
+=-=-=
+
 Name: Multiline Block Comments 1 (bug#60270)
 
 =-=
@@ -327,3 +341,16 @@ void foo(
     }
 }
 =-=-=
+
+Name: Initializer List (Linux Style) (Bug#61398)
+
+=-=
+int main()
+{
+  const char *emoticons[][2] = {
+    {":-)", "SLIGHTLY SMILING FACE"},
+    {";-)", "WINKING FACE"},
+    {":-(", "SLIGHTLY FROWNING FACE"},
+  };
+}
+=-=-=



reply via email to

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