diff options
| author | Jørgen Kvalsvik | 2024-11-19 08:01:01 +0100 |
|---|---|---|
| committer | Yuan Fu | 2024-12-01 17:53:21 -0800 |
| commit | c65c5d02224335562be7e04dd1bf185dfca3dbf1 (patch) | |
| tree | 83c7fe53580c6db7a7b26ba9bcffd9a94d6fdae0 /test | |
| parent | 4afd1eca3662eda052d0017f83b4baa1f6131e8b (diff) | |
| download | emacs-c65c5d02224335562be7e04dd1bf185dfca3dbf1.tar.gz emacs-c65c5d02224335562be7e04dd1bf185dfca3dbf1.zip | |
Improve c-ts-mode compound indents (bug#74507)
Properly indent the body of compound expressions, even when then
compound expression is not at the beginning of line and the
parent is not an if/for/while/etc., and matches the behavior of
c-mode.
This fixes a problem that is common with macros and in testing
frameworks. For example, you expect this to indent:
TEST_CASE(1) {
assert (...);
}
If the compound statement is the function body itself, don't
apply this new rule and instead guide by the parent and first
sibling.
I'm sure there are subtle interactions that aren't handled
properly by checking for "function_definition" rather than
something more general, but it does fix the test case and the
check can be improved as more cases are found.
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--parent-is-not-top-compound): New function.
(c-ts-mode--indent-styles): Use it.
* test/lisp/progmodes/c-ts-mode-resources/indent.erts: New
compound statement test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/progmodes/c-ts-mode-resources/indent.erts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts index 2f3540c3970..61e61677ed7 100644 --- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts | |||
| @@ -223,6 +223,36 @@ make_pair(int long_identifier_a[], int long_identifier_b[], | |||
| 223 | 223 | ||
| 224 | =-=-= | 224 | =-=-= |
| 225 | 225 | ||
| 226 | Name: Compound Statement after code | ||
| 227 | |||
| 228 | =-= | ||
| 229 | #define IOTA(var, n) for (int var = 0; var != (n); ++var) | ||
| 230 | int main() | ||
| 231 | { | ||
| 232 | IOTA (v, 10) { | ||
| 233 | printf("%d ", v); | ||
| 234 | } | ||
| 235 | |||
| 236 | const char *msg = "Hello, world!"; { | ||
| 237 | puts("Hello, world!"); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | |||
| 241 | =-= | ||
| 242 | #define IOTA(var, n) for (int var = 0; var != (n); ++var) | ||
| 243 | int main() | ||
| 244 | { | ||
| 245 | IOTA (v, 10) { | ||
| 246 | printf("%d ", v); | ||
| 247 | } | ||
| 248 | |||
| 249 | const char *msg = "Hello, world!"; { | ||
| 250 | puts("Hello, world!"); | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | =-=-= | ||
| 255 | |||
| 226 | Name: Switch-Case statement | 256 | Name: Switch-Case statement |
| 227 | 257 | ||
| 228 | =-= | 258 | =-= |