aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJørgen Kvalsvik2024-11-19 08:01:01 +0100
committerYuan Fu2024-12-01 17:53:21 -0800
commitc65c5d02224335562be7e04dd1bf185dfca3dbf1 (patch)
tree83c7fe53580c6db7a7b26ba9bcffd9a94d6fdae0 /test
parent4afd1eca3662eda052d0017f83b4baa1f6131e8b (diff)
downloademacs-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.erts30
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
226Name: Compound Statement after code
227
228=-=
229#define IOTA(var, n) for (int var = 0; var != (n); ++var)
230int main()
231{
232IOTA (v, 10) {
233printf("%d ", v);
234}
235
236const char *msg = "Hello, world!"; {
237puts("Hello, world!");
238}
239}
240
241=-=
242#define IOTA(var, n) for (int var = 0; var != (n); ++var)
243int 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
226Name: Switch-Case statement 256Name: Switch-Case statement
227 257
228=-= 258=-=