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.
This commit is contained in:
parent
dc911e4ba5
commit
1238fa8e49
1 changed files with 16 additions and 1 deletions
|
@ -125,6 +125,7 @@ MODE is either `c' or `cpp'."
|
|||
((and (parent-is "comment") c-ts-mode--looking-at-star)
|
||||
c-ts-mode--comment-start-after-first-star -1)
|
||||
((parent-is "comment") prev-adaptive-prefix 0)
|
||||
(c-ts-mode--top-level-label-matcher point-min 1)
|
||||
((node-is "labeled_statement") parent-bol 0)
|
||||
((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset)
|
||||
((match "preproc_ifdef" "compound_statement") point-min 0)
|
||||
|
@ -171,7 +172,10 @@ MODE is either `c' or `cpp'."
|
|||
,@common)
|
||||
(k&r ,@common)
|
||||
(linux
|
||||
((node-is "labeled_statement") point-min 1)
|
||||
;; Reference:
|
||||
;; https://www.kernel.org/doc/html/latest/process/coding-style.html,
|
||||
;; and script/Lindent in Linux kernel repository.
|
||||
((node-is "labeled_statement") point-min 0)
|
||||
,@common)
|
||||
(bsd
|
||||
((parent-is "if_statement") parent-bol 0)
|
||||
|
@ -195,6 +199,17 @@ MODE is either `c' or `cpp'."
|
|||
('linux (alist-get 'linux (c-ts-mode--indent-styles mode)))))))
|
||||
`((,mode ,@style))))
|
||||
|
||||
(defun c-ts-mode--top-level-label-matcher (node &rest _)
|
||||
"A matcher that matches a top-level label.
|
||||
NODE should be a labeled_statement."
|
||||
(let ((func (treesit-parent-until
|
||||
node (lambda (n)
|
||||
(equal (treesit-node-type n)
|
||||
"function_definition")))))
|
||||
(and (equal (treesit-node-type node)
|
||||
"labeled_statement")
|
||||
(not (treesit-node-top-level func "function_definition")))))
|
||||
|
||||
(defun c-ts-mode--bracket-children-anchor (_n parent &rest _)
|
||||
"This anchor is used for children of a compound_statement.
|
||||
So anything inside a {} block. PARENT should be the
|
||||
|
|
Loading…
Add table
Reference in a new issue