1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-02 08:22:22 +00:00

Simplify c-ts-mode--top-level-label-matcher

* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--top-level-label-matcher): Make more assumptions and remove
the loop, so it's faster in large files.
This commit is contained in:
Yuan Fu 2023-02-26 18:24:49 -08:00
parent 0f15286c53
commit edf5b97686
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442

View File

@ -394,16 +394,13 @@ MODE is either `c' or `cpp'."
((parent-is "do_statement") parent-bol 0)
,@common))))
(defun c-ts-mode--top-level-label-matcher (node &rest _)
(defun c-ts-mode--top-level-label-matcher (node parent &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)
"compound_statement")))))
(and (equal (treesit-node-type node)
"labeled_statement")
(not (treesit-node-top-level func "compound_statement")))))
NODE should be a labeled_statement. PARENT is its parent."
(and (equal (treesit-node-type node)
"labeled_statement")
(equal "function_definition"
(treesit-node-type (treesit-node-parent parent)))))
;;; Font-lock