diff options
| author | Yuan Fu | 2023-02-12 19:49:47 -0800 |
|---|---|---|
| committer | Yuan Fu | 2023-02-12 19:49:47 -0800 |
| commit | f2114e8d89feed154a1c523c925ff2fb9fa9ba9a (patch) | |
| tree | 4ee8ce83571c51110ba0a1742bb8726ee8440c75 | |
| parent | f49caaa892576e5fa95373c38e6a99904249551c (diff) | |
| download | emacs-f2114e8d89feed154a1c523c925ff2fb9fa9ba9a.tar.gz emacs-f2114e8d89feed154a1c523c925ff2fb9fa9ba9a.zip | |
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.el | 11 | ||||
| -rw-r--r-- | test/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 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'." | |||
| 272 | ;; Indent the body of namespace definitions. | 272 | ;; Indent the body of namespace definitions. |
| 273 | ((parent-is "declaration_list") parent-bol c-ts-mode-indent-offset))) | 273 | ((parent-is "declaration_list") parent-bol c-ts-mode-indent-offset))) |
| 274 | 274 | ||
| 275 | ;; Closing bracket. This should be before initializer_list | ||
| 276 | ;; (and probably others) rule because that rule (and other | ||
| 277 | ;; similar rules) will match the closing bracket. (Bug#61398) | ||
| 278 | ((node-is "}") point-min c-ts-common-statement-offset) | ||
| 279 | |||
| 275 | ;; int[5] a = { 0, 0, 0, 0 }; | 280 | ;; int[5] a = { 0, 0, 0, 0 }; |
| 276 | ((parent-is "initializer_list") parent-bol c-ts-mode-indent-offset) | 281 | ((parent-is "initializer_list") parent-bol c-ts-mode-indent-offset) |
| 277 | ;; Statement in enum. | 282 | ;; Statement in enum. |
| @@ -281,8 +286,6 @@ MODE is either `c' or `cpp'." | |||
| 281 | 286 | ||
| 282 | ;; Statement in {} blocks. | 287 | ;; Statement in {} blocks. |
| 283 | ((parent-is "compound_statement") point-min c-ts-common-statement-offset) | 288 | ((parent-is "compound_statement") point-min c-ts-common-statement-offset) |
| 284 | ;; Closing bracket. | ||
| 285 | ((node-is "}") point-min c-ts-common-statement-offset) | ||
| 286 | ;; Opening bracket. | 289 | ;; Opening bracket. |
| 287 | ((node-is "compound_statement") point-min c-ts-common-statement-offset) | 290 | ((node-is "compound_statement") point-min c-ts-common-statement-offset) |
| 288 | ;; Bug#61291. | 291 | ;; Bug#61291. |
| @@ -768,7 +771,9 @@ the semicolon. This function skips the semicolon." | |||
| 768 | (setq-local c-ts-common-indent-type-regexp-alist | 771 | (setq-local c-ts-common-indent-type-regexp-alist |
| 769 | `((block . ,(rx (or "compound_statement" | 772 | `((block . ,(rx (or "compound_statement" |
| 770 | "field_declaration_list" | 773 | "field_declaration_list" |
| 771 | "enumerator_list"))) | 774 | "enumerator_list" |
| 775 | "initializer_list" | ||
| 776 | "field_declaration_list"))) | ||
| 772 | (if . "if_statement") | 777 | (if . "if_statement") |
| 773 | (else . ("if_statement" . "alternative")) | 778 | (else . ("if_statement" . "alternative")) |
| 774 | (do . "do_statement") | 779 | (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) | |||
| 182 | return 3; | 182 | return 3; |
| 183 | =-=-= | 183 | =-=-= |
| 184 | 184 | ||
| 185 | Name: Initializer List (Bug#61398) | ||
| 186 | |||
| 187 | =-= | ||
| 188 | int main() | ||
| 189 | { | ||
| 190 | const char *emoticons[][2] = | ||
| 191 | { | ||
| 192 | {":-)", "SLIGHTLY SMILING FACE"}, | ||
| 193 | {";-)", "WINKING FACE"}, | ||
| 194 | {":-(", "SLIGHTLY FROWNING FACE"}, | ||
| 195 | }; | ||
| 196 | } | ||
| 197 | =-=-= | ||
| 198 | |||
| 185 | Name: Multiline Block Comments 1 (bug#60270) | 199 | Name: Multiline Block Comments 1 (bug#60270) |
| 186 | 200 | ||
| 187 | =-= | 201 | =-= |
| @@ -327,3 +341,16 @@ void foo( | |||
| 327 | } | 341 | } |
| 328 | } | 342 | } |
| 329 | =-=-= | 343 | =-=-= |
| 344 | |||
| 345 | Name: Initializer List (Linux Style) (Bug#61398) | ||
| 346 | |||
| 347 | =-= | ||
| 348 | int main() | ||
| 349 | { | ||
| 350 | const char *emoticons[][2] = { | ||
| 351 | {":-)", "SLIGHTLY SMILING FACE"}, | ||
| 352 | {";-)", "WINKING FACE"}, | ||
| 353 | {":-(", "SLIGHTLY FROWNING FACE"}, | ||
| 354 | }; | ||
| 355 | } | ||
| 356 | =-=-= | ||