[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 7cb92b5398 2/3: Fix c-ts-mode indentation
From: |
Yuan Fu |
Subject: |
emacs-29 7cb92b5398 2/3: Fix c-ts-mode indentation |
Date: |
Mon, 6 Feb 2023 21:29:53 -0500 (EST) |
branch: emacs-29
commit 7cb92b5398771b088450942d9eaefd53b5f91cf6
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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 ++++++
test/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 1737b8c571..f2d5a48200 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 2750526f89..8c588f56f9 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)
=-=