[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 edf5b976869 2/2: Simplify c-ts-mode--top-level-label-matcher
From: |
Yuan Fu |
Subject: |
emacs-29 edf5b976869 2/2: Simplify c-ts-mode--top-level-label-matcher |
Date: |
Mon, 27 Feb 2023 00:47:55 -0500 (EST) |
branch: emacs-29
commit edf5b97686908114f254b5077c71e8202149545f
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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.
---
lisp/progmodes/c-ts-mode.el | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 2c79cf46308..befc0cf5643 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -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