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.
This commit is contained in:
Yuan Fu 2023-02-12 19:49:47 -08:00
parent f49caaa892
commit f2114e8d89
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
2 changed files with 35 additions and 3 deletions

View 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")

View 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"},
};
}
=-=-=