diff options
| author | Yuan Fu | 2023-12-10 18:24:27 -0800 |
|---|---|---|
| committer | Yuan Fu | 2023-12-10 18:24:27 -0800 |
| commit | 7f1bd69cd19504f2bd47e13c530a55ffca08e27d (patch) | |
| tree | 6bb9aaf1a3d9969b7b757c4fa00694de618b5d86 | |
| parent | e23068cb9a1692fc3c50b0b386237a56cae201f4 (diff) | |
| download | emacs-7f1bd69cd19504f2bd47e13c530a55ffca08e27d.tar.gz emacs-7f1bd69cd19504f2bd47e13c530a55ffca08e27d.zip | |
Fix c-ts-mode bracketless indentation for BSD style (bug#66152)
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--indent-styles): Make sure the BSD rules only apply to
opening bracket (compound_statement), then bracketless statements will
fallback to common rules.
* test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts: Copy the
bracketless test from indent.erts to here.
| -rw-r--r-- | lisp/progmodes/c-ts-mode.el | 14 | ||||
| -rw-r--r-- | test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts | 34 |
2 files changed, 41 insertions, 7 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 5606996eee2..ca831a9c5f9 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el | |||
| @@ -515,13 +515,13 @@ MODE is either `c' or `cpp'." | |||
| 515 | ((node-is "labeled_statement") parent-bol c-ts-mode-indent-offset) | 515 | ((node-is "labeled_statement") parent-bol c-ts-mode-indent-offset) |
| 516 | ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset) | 516 | ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset) |
| 517 | ((parent-is "compound_statement") parent-bol c-ts-mode-indent-offset) | 517 | ((parent-is "compound_statement") parent-bol c-ts-mode-indent-offset) |
| 518 | ((parent-is "if_statement") parent-bol 0) | 518 | ((match "compound_statement" "if_statement") standalone-parent 0) |
| 519 | ((parent-is "else_clause") parent-bol 0) | 519 | ((match "compound_statement" "else_clause") standalone-parent 0) |
| 520 | ((parent-is "for_statement") parent-bol 0) | 520 | ((match "compound_statement" "for_statement") standalone-parent 0) |
| 521 | ((parent-is "while_statement") parent-bol 0) | 521 | ((match "compound_statement" "while_statement") standalone-parent 0) |
| 522 | ((parent-is "switch_statement") parent-bol 0) | 522 | ((match "compound_statement" "switch_statement") standalone-parent 0) |
| 523 | ((parent-is "case_statement") parent-bol 0) | 523 | ((match "compound_statement" "case_statement") standalone-parent 0) |
| 524 | ((parent-is "do_statement") parent-bol 0) | 524 | ((match "compound_statement" "do_statement") standalone-parent 0) |
| 525 | ,@common)))) | 525 | ,@common)))) |
| 526 | 526 | ||
| 527 | (defun c-ts-mode--top-level-label-matcher (node parent &rest _) | 527 | (defun c-ts-mode--top-level-label-matcher (node parent &rest _) |
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts b/test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts index 74e34fe821b..fa65ba83a69 100644 --- a/test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts +++ b/test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts | |||
| @@ -91,3 +91,37 @@ main (int argc, | |||
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | =-=-= | 93 | =-=-= |
| 94 | |||
| 95 | Name: Bracketless Simple Statement (bug#66152) | ||
| 96 | |||
| 97 | =-= | ||
| 98 | for (int i = 0; i < 5; i++) | ||
| 99 | continue; | ||
| 100 | |||
| 101 | while (true) | ||
| 102 | return 1; | ||
| 103 | |||
| 104 | do | ||
| 105 | i++; | ||
| 106 | while (true) | ||
| 107 | |||
| 108 | if (true) | ||
| 109 | break; | ||
| 110 | else | ||
| 111 | break; | ||
| 112 | =-= | ||
| 113 | for (int i = 0; i < 5; i++) | ||
| 114 | continue; | ||
| 115 | |||
| 116 | while (true) | ||
| 117 | return 1; | ||
| 118 | |||
| 119 | do | ||
| 120 | i++; | ||
| 121 | while (true) | ||
| 122 | |||
| 123 | if (true) | ||
| 124 | break; | ||
| 125 | else | ||
| 126 | break; | ||
| 127 | =-=-= | ||