]> git.eshelyaron.com Git - emacs.git/commitdiff
Simplify c-ts-mode--top-level-label-matcher
authorYuan Fu <casouri@gmail.com>
Mon, 27 Feb 2023 02:24:49 +0000 (18:24 -0800)
committerYuan Fu <casouri@gmail.com>
Mon, 27 Feb 2023 05:38:22 +0000 (21:38 -0800)
* 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.

lisp/progmodes/c-ts-mode.el

index 2c79cf46308d1bdab8fe0f723480e4c637485b25..befc0cf564393fe9e4eeebd564df318c7e0c475f 100644 (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