From 7cb92b5398771b088450942d9eaefd53b5f91cf6 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sun, 5 Feb 2023 17:05:21 -0800 Subject: [PATCH] Fix c-ts-mode indentation Turns out I shouldn't have removed the explicit rules. Anyway, now it indents properly. * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Add rules. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: Add tests --- lisp/progmodes/c-ts-mode.el | 6 ++++++ .../lisp/progmodes/c-ts-mode-resources/indent.erts | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 1737b8c5715..f2d5a482009 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -287,6 +287,12 @@ MODE is either `c' or `cpp'." ((node-is "compound_statement") point-min c-ts-common-statement-offset) ;; Bug#61291. ((match "expression_statement" nil "body") point-min c-ts-common-statement-offset) + ;; These rules are for cases where the body is bracketless. + ;; Tested by the "Bracketless Simple Statement" test. + ((parent-is "if_statement") point-min c-ts-common-statement-offset) + ((parent-is "for_statement") point-min c-ts-common-statement-offset) + ((parent-is "while_statement") point-min c-ts-common-statement-offset) + ((parent-is "do_statement") point-min c-ts-common-statement-offset) ,@(when (eq mode 'cpp) `(((node-is "field_initializer_list") parent-bol ,(* c-ts-mode-indent-offset 2))))))) diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts index 2750526f893..8c588f56f9a 100644 --- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts @@ -155,6 +155,20 @@ for (int i = 0; ; =-=-= +Name: Bracketless Simple Statement + +=-= +for (int i = 0; i < 5; i++) + continue; + +while (true) + return 1; + +do + i++; +while (true) +=-=-= + Name: Multiline Block Comments 1 (bug#60270) =-=