[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)))
- feature/tree-sitter updated (5070278539 -> 62c8c8e51a), Yuan Fu, 2022/10/26
- feature/tree-sitter c9df4cace0 02/10: * src/treesit.c (treesit_search_forward): Fix traverses algorithm., Yuan Fu, 2022/10/26
- feature/tree-sitter 5c1b9e65b9 03/10: ; * src/treesit.c (treesit_search_forward): Fix comment., Yuan Fu, 2022/10/26
- feature/tree-sitter 734df28368 05/10: Fix tree-sitter navigation, Yuan Fu, 2022/10/26
- feature/tree-sitter 62c8c8e51a 10/10: Plug tree-sitter-simple-indent into c-offset-alist, Yuan Fu, 2022/10/26
- feature/tree-sitter e868955bff 04/10: * src/treesit.c (treesit_search_dfs): Fix traverse algorithm., Yuan Fu, 2022/10/26
- feature/tree-sitter 6fb6cb075f 06/10: Add tree-sitter imenu support for js-mode and ts-mode, Yuan Fu, 2022/10/26
- feature/tree-sitter 76b86d9853 08/10: Generalize js--treesit-imenu-top-level-p, Yuan Fu, 2022/10/26
- feature/tree-sitter c352392420 07/10: Add tree-sitter navigation support to python-mode, Yuan Fu, 2022/10/26
- feature/tree-sitter 5532ae81cf 09/10: * lisp/treesit.el (treesit-node-top-level-p): New argument TYPE.,
Yuan Fu <=
- feature/tree-sitter 1f74e9112e 01/10: Don't disable parse cache in tree-sitter activated js-mode, Yuan Fu, 2022/10/26