emacs-diffs
[Top][All Lists]
Advanced

[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



reply via email to

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