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) ((parent-is "do_statement") parent-bol 0)
,@common)))) ,@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. "A matcher that matches a top-level label.
NODE should be a labeled_statement." NODE should be a labeled_statement. PARENT is its parent."
(let ((func (treesit-parent-until (and (equal (treesit-node-type node)
node (lambda (n) "labeled_statement")
(equal (treesit-node-type n) (equal "function_definition"
"compound_statement"))))) (treesit-node-type (treesit-node-parent parent)))))
(and (equal (treesit-node-type node)
"labeled_statement")
(not (treesit-node-top-level func "compound_statement")))))
;;; Font-lock ;;; Font-lock