From 08fc6bace202a13d93fc76943c41f19acaab9c73 Mon Sep 17 00:00:00 2001 From: nverno Date: Tue, 21 Nov 2023 16:33:04 -0800 Subject: Fix c-ts-mode indentation (bug#67357) 1. In a compund_statement, we indent the first sibling against the parent, and the rest siblings against their previous sibling. But this strategy falls apart when the first sibling is not on its own line. We should regard the first sibling that is on its own line as the "first sibling"", and indent it against the parent. 2. In linux style, in a do-while statement, if the do-body is bracket-less, the "while" keyword is indented to the same level as the do-body. It should be indented to align with the "do" keyword instead. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--no-prev-standalone-sibling): New function. (c-ts-mode--indent-styles): Use c-ts-mode--no-prev-standalone-sibling. Add while keyword indent rule. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New tests. --- .../lisp/progmodes/c-ts-mode-resources/indent.erts | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'test/lisp/progmodes/c-ts-mode-resources') diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts index bac76fb7378..2fd26d75844 100644 --- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts @@ -330,7 +330,7 @@ label: Name: Bracket-less Block-Statement (Linux Style) (bug#61026) -=-=-= +=-= int main() { while (true) if (true) { @@ -351,6 +351,8 @@ int main() { if (true) { puts ("Hello"); } + else + puts("Hello"); } =-=-= @@ -399,6 +401,34 @@ void foo( } =-=-= +Name: Block-Statement where first siblings are comments (Linux Style) + +=-= +int main() { + while (true) { /* foo */ + if (true) { // bar + puts ("Hello"); + } + } + for (;;) { // 1. fooo + /* 2. baaa */ + /* 3. rrr */ + if (true) + // 2. baaa + puts ("Hello"); + } + if (1) { // 1 + /* + * 2 + */ + if (1) /*3*/ { + /* 4 */ + puts("Hello"); + } + } +} +=-=-= + Name: Initializer List (Linux Style) (Bug#61398) =-= @@ -498,3 +528,19 @@ main (void) { | =-=-= + +Code: + (lambda () + (c-ts-mode) + (setq-local indent-tabs-mode nil) + (goto-line 3) + (indent-for-tab-command)) + +Name: Block-Statement where previous sibling is comment + +=-= +int main() { + puts ("Hello"); // unusual indent and has trailing comment. + return true; // Should align with previous non-comment sibling (rather than one level up against parent). +} +=-=-= -- cgit v1.2.3