[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter 76b86d9853 08/10: Generalize js--treesit-imenu-top-l
From: |
Yuan Fu |
Subject: |
feature/tree-sitter 76b86d9853 08/10: Generalize js--treesit-imenu-top-level-p |
Date: |
Wed, 26 Oct 2022 21:42:00 -0400 (EDT) |
branch: feature/tree-sitter
commit 76b86d98534da2c9e6cf8fd1c7edcbe53d84eb82
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Generalize js--treesit-imenu-top-level-p
* lisp/progmodes/js.el (js--treesit-imenu-top-level-p): Move.
(js--treesit-font-lock-settings): Fix usage.
* lisp/treesit.el (treesit-node-top-level-p): Move to here.
---
lisp/progmodes/js.el | 14 +-------------
lisp/treesit.el | 12 ++++++++++++
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 8802ea0b5f..7e1d7569ca 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3601,18 +3601,6 @@ This function can be used as a value in
`which-func-functions'"
do (setq node (treesit-node-parent node))
finally return (string-join name-list "."))))
-(defun js--treesit-imenu-top-level-p (node)
- "Return t if NODE is top-level, nil otherwise.
-Being top-level means there is no parent of NODE that has the
-same type."
- (when node
- (catch 'term
- (let ((type (treesit-node-type node)))
- (while (setq node (treesit-node-parent node))
- (when (equal (treesit-node-type node) type)
- (throw 'term nil))))
- t)))
-
;; Keep this private since we might later change it or generalize it.
(defvar js--treesit-imenu-type-alist
'((variable . "V")
@@ -3673,7 +3661,7 @@ definition*\"."
((null ts-node)
subtrees)
((and (eq type 'variable)
- (not (js--treesit-imenu-top-level-p ts-node)))
+ (not (treesit-node-top-level-p ts-node)))
nil)
(subtrees
(let ((parent-label (js--treesit-imenu-label type name))
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 8426a02a26..f07fe7d609 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -195,6 +195,18 @@ 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)
+ "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."
+ (when node
+ (catch 'term
+ (let ((type (treesit-node-type node)))
+ (while (setq node (treesit-node-parent node))
+ (when (equal (treesit-node-type node) type)
+ (throw 'term nil))))
+ t)))
+
(defun treesit-buffer-root-node (&optional language)
"Return the root node of the current buffer.
Use the first parser in (`treesit-parser-list'), if LANGUAGE is
- 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 <=
- 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, 2022/10/26
- feature/tree-sitter 1f74e9112e 01/10: Don't disable parse cache in tree-sitter activated js-mode, Yuan Fu, 2022/10/26