summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2023-02-12 19:49:47 -0800
committerYuan Fu <casouri@gmail.com>2023-02-12 19:49:47 -0800
commitf2114e8d89feed154a1c523c925ff2fb9fa9ba9a (patch)
tree4ee8ce83571c51110ba0a1742bb8726ee8440c75
parentf49caaa892576e5fa95373c38e6a99904249551c (diff)
downloademacs-f2114e8d89f.tar.gz
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.
-rw-r--r--lisp/progmodes/c-ts-mode.el11
-rw-r--r--test/lisp/progmodes/c-ts-mode-resources/indent.erts27
2 files changed, 35 insertions, 3 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index b898f7d9ee3..af7aa1c3a0e 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 21b84c2e7e3..05d59c10a42 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"},
+ };
+}
+=-=-=