emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tree-sitter 5532ae81cf 09/10: * lisp/treesit.el (treesit-node-to


From: Yuan Fu
Subject: feature/tree-sitter 5532ae81cf 09/10: * lisp/treesit.el (treesit-node-top-level-p): New argument TYPE.
Date: Wed, 26 Oct 2022 21:42:00 -0400 (EDT)

branch: feature/tree-sitter
commit 5532ae81cff138a2f6d30c3541210311a4894ac1
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    * lisp/treesit.el (treesit-node-top-level-p): New argument TYPE.
---
 lisp/treesit.el | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index f07fe7d609..5c89a63bf6 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -195,15 +195,19 @@ that language in the current buffer, and use that."
                 (treesit-buffer-root-node parser-or-lang))))
     (treesit-node-descendant-for-range root beg (or end beg) named)))
 
-(defun treesit-node-top-level-p (node)
+(defun treesit-node-top-level-p (node &optional type)
   "Return non-nil if NODE is top-level, nil otherwise.
 Being top-level means there is no parent of NODE that has the
-same type."
+same type.
+
+If TYPE is non-nil, match each parent's type with TYPE as a regexp."
   (when node
     (catch 'term
-      (let ((type (treesit-node-type node)))
+      (let ((plain-type (treesit-node-type node)))
         (while (setq node (treesit-node-parent node))
-          (when (equal (treesit-node-type node) type)
+          (when (if type
+                    (string-match-p type (treesit-node-type node))
+                  (equal (treesit-node-type node) plain-type))
             (throw 'term nil))))
       t)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]