]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix indentation for closing bracket in c-ts-mode (bug#61398)
authorYuan Fu <casouri@gmail.com>
Mon, 13 Feb 2023 03:49:47 +0000 (19:49 -0800)
committerYuan Fu <casouri@gmail.com>
Mon, 13 Feb 2023 03:49:47 +0000 (19:49 -0800)
* 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
test/lisp/progmodes/c-ts-mode-resources/indent.erts

index b898f7d9ee32222d2c835db56b1dda6d22684ceb..af7aa1c3a0eb632f8c41d509e740476beffdf0a6 100644 (file)
@@ -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")
index 21b84c2e7e3105d69fcc9776e64695373c47277b..05d59c10a42c298d8c8f71e2c02661ea8d4d96cc 100644 (file)
@@ -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"},
+  };
+}
+=-=-=