aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2023-01-08 16:57:29 -0800
committerYuan Fu2023-01-08 20:32:51 -0800
commit1238fa8e49bdb12db66d856dcb4b192db5d026ff (patch)
treee8334c26272b6eb235d5ce665a25d204759a8058
parentdc911e4ba5ccfc99d66504b6e99c9abcf3e617f3 (diff)
downloademacs-1238fa8e49bdb12db66d856dcb4b192db5d026ff.tar.gz
emacs-1238fa8e49bdb12db66d856dcb4b192db5d026ff.zip
Fix label indent of GNU and Linux style in c-ts-mode (bug#60543)
The previous fix isn't correct. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--indent-styles): New indent rule. Fix the rule for Linux style. (c-ts-mode--top-level-label-matcher): New function.
-rw-r--r--lisp/progmodes/c-ts-mode.el17
1 files changed, 16 insertions, 1 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index e1b45b06e1a..772b259d59e 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -125,6 +125,7 @@ MODE is either `c' or `cpp'."
125 ((and (parent-is "comment") c-ts-mode--looking-at-star) 125 ((and (parent-is "comment") c-ts-mode--looking-at-star)
126 c-ts-mode--comment-start-after-first-star -1) 126 c-ts-mode--comment-start-after-first-star -1)
127 ((parent-is "comment") prev-adaptive-prefix 0) 127 ((parent-is "comment") prev-adaptive-prefix 0)
128 (c-ts-mode--top-level-label-matcher point-min 1)
128 ((node-is "labeled_statement") parent-bol 0) 129 ((node-is "labeled_statement") parent-bol 0)
129 ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset) 130 ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset)
130 ((match "preproc_ifdef" "compound_statement") point-min 0) 131 ((match "preproc_ifdef" "compound_statement") point-min 0)
@@ -171,7 +172,10 @@ MODE is either `c' or `cpp'."
171 ,@common) 172 ,@common)
172 (k&r ,@common) 173 (k&r ,@common)
173 (linux 174 (linux
174 ((node-is "labeled_statement") point-min 1) 175 ;; Reference:
176 ;; https://www.kernel.org/doc/html/latest/process/coding-style.html,
177 ;; and script/Lindent in Linux kernel repository.
178 ((node-is "labeled_statement") point-min 0)
175 ,@common) 179 ,@common)
176 (bsd 180 (bsd
177 ((parent-is "if_statement") parent-bol 0) 181 ((parent-is "if_statement") parent-bol 0)
@@ -195,6 +199,17 @@ MODE is either `c' or `cpp'."
195 ('linux (alist-get 'linux (c-ts-mode--indent-styles mode))))))) 199 ('linux (alist-get 'linux (c-ts-mode--indent-styles mode)))))))
196 `((,mode ,@style)))) 200 `((,mode ,@style))))
197 201
202(defun c-ts-mode--top-level-label-matcher (node &rest _)
203 "A matcher that matches a top-level label.
204NODE should be a labeled_statement."
205 (let ((func (treesit-parent-until
206 node (lambda (n)
207 (equal (treesit-node-type n)
208 "function_definition")))))
209 (and (equal (treesit-node-type node)
210 "labeled_statement")
211 (not (treesit-node-top-level func "function_definition")))))
212
198(defun c-ts-mode--bracket-children-anchor (_n parent &rest _) 213(defun c-ts-mode--bracket-children-anchor (_n parent &rest _)
199 "This anchor is used for children of a compound_statement. 214 "This anchor is used for children of a compound_statement.
200So anything inside a {} block. PARENT should be the 215So anything inside a {} block. PARENT should be the