aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2022-10-23 18:54:12 -0700
committerYuan Fu2022-10-23 18:54:37 -0700
commit6203b9db347d2d002c0cb660d5b4daeea54bf3ad (patch)
tree6241251607b2b1861b09680bc869c5e6ecec0a0e
parent1787e651d376486909e736478b1be92c949a368d (diff)
downloademacs-6203b9db347d2d002c0cb660d5b4daeea54bf3ad.tar.gz
emacs-6203b9db347d2d002c0cb660d5b4daeea54bf3ad.zip
* lisp/treesit.el (treesit-node-at): Remove argument LARGEST.
LARGEST returns the root node at BOB, finding the smallest node at point and search upward is a better practice.
-rw-r--r--lisp/treesit.el13
1 files changed, 2 insertions, 11 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 0df9b6c6876..a3bc1259b13 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -101,7 +101,7 @@ Return the root node of the syntax tree."
101 (treesit-parser-language 101 (treesit-parser-language
102 (treesit-node-parser node))) 102 (treesit-node-parser node)))
103 103
104(defun treesit-node-at (pos &optional parser-or-lang named largest strict) 104(defun treesit-node-at (pos &optional parser-or-lang named strict)
105 "Return the smallest node that starts at or after buffer position POS. 105 "Return the smallest node that starts at or after buffer position POS.
106 106
107\"Starts at or after POS\" means the start of the node is greater or 107\"Starts at or after POS\" means the start of the node is greater or
@@ -114,9 +114,6 @@ If PARSER-OR-LANG is nil, use the first parser in
114that parser; if PARSER-OR-LANG is a language, find a parser using 114that parser; if PARSER-OR-LANG is a language, find a parser using
115that language in the current buffer, and use that. 115that language in the current buffer, and use that.
116 116
117If LARGEST is non-nil, return the largest node instead of the
118smallest.
119
120If POS is after all the text in the buffer, i.e., there is no 117If POS is after all the text in the buffer, i.e., there is no
121node after POS, return the last leaf node in the parse tree, even 118node after POS, return the last leaf node in the parse tree, even
122though that node is before POS. If STRICT is non-nil, return nil 119though that node is before POS. If STRICT is non-nil, return nil
@@ -140,13 +137,7 @@ in this case."
140 (while (setq next (treesit-node-child node -1 named)) 137 (while (setq next (treesit-node-child node -1 named))
141 (setq node next)) 138 (setq node next))
142 node) 139 node)
143 ;; If LARGEST non-nil, find the largest node that has the same 140 node))))
144 ;; starting point as NODE.
145 (if (not largest)
146 node
147 (treesit-parent-while
148 node (lambda (n) (eq (treesit-node-start n)
149 (treesit-node-start node)))))))))
150 141
151(defun treesit-node-on (beg end &optional parser-or-lang named) 142(defun treesit-node-on (beg end &optional parser-or-lang named)
152 "Return the smallest node covering BEG to END. 143 "Return the smallest node covering BEG to END.