aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2023-09-01 17:37:46 -0700
committerYuan Fu2023-09-01 20:38:31 -0700
commited152ccd1d69dbd53bcf4ba32da788753d0ea2e2 (patch)
tree5d7a50fd3eb3d23f3f41867abb58775802857998
parent452697a81ab330d5fe7b4b4ece3acfddd5330a72 (diff)
downloademacs-ed152ccd1d69dbd53bcf4ba32da788753d0ea2e2.tar.gz
emacs-ed152ccd1d69dbd53bcf4ba32da788753d0ea2e2.zip
Rename PRED to THING in tree-sitter navigation functions
The primary way to use these functions should be to supply a thing symbol. Change the parameter name to THING to reflect that. * lisp/treesit.el (treesit-beginning-of-thing) (treesit-end-of-thing) (treesit--things-around) (treesit--navigate-thing) (treesit-thing-at-point): Change parameter.
-rw-r--r--lisp/treesit.el46
1 files changed, 23 insertions, 23 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 379f39771c5..d77d9519eb6 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1941,11 +1941,11 @@ A thing is considered defined if it has an entry in
1941(defalias 'treesit-thing-defined-p 'treesit-thing-definition 1941(defalias 'treesit-thing-defined-p 'treesit-thing-definition
1942 "Return non-nil if THING is defined.") 1942 "Return non-nil if THING is defined.")
1943 1943
1944(defun treesit-beginning-of-thing (pred &optional arg tactic) 1944(defun treesit-beginning-of-thing (thing &optional arg tactic)
1945 "Like `beginning-of-defun', but generalized into things. 1945 "Like `beginning-of-defun', but generalized into things.
1946 1946
1947PRED is a thing predicate, see `treesit-thing-settings' for more 1947THING can be a thing defined in `treesit-thing-settings', or a
1948detail. ARG is the same as in `beginning-of-defun'. 1948predicate, which see. ARG is the same as in `beginning-of-defun'.
1949 1949
1950TACTIC determines how does this function move between things. It 1950TACTIC determines how does this function move between things. It
1951can be `nested', `top-level', `restricted', or nil. `nested' 1951can be `nested', `top-level', `restricted', or nil. `nested'
@@ -1960,15 +1960,15 @@ should there be one. If omitted, TACTIC is considered to be
1960Return non-nil if successfully moved, nil otherwise." 1960Return non-nil if successfully moved, nil otherwise."
1961 (pcase-let* ((arg (or arg 1)) 1961 (pcase-let* ((arg (or arg 1))
1962 (dest (treesit--navigate-thing 1962 (dest (treesit--navigate-thing
1963 (point) (- arg) 'beg pred tactic))) 1963 (point) (- arg) 'beg thing tactic)))
1964 (when dest 1964 (when dest
1965 (goto-char dest)))) 1965 (goto-char dest))))
1966 1966
1967(defun treesit-end-of-thing (pred &optional arg tactic) 1967(defun treesit-end-of-thing (thing &optional arg tactic)
1968 "Like `end-of-defun', but generalized into things. 1968 "Like `end-of-defun', but generalized into things.
1969 1969
1970PRED is a thing predicate, see `treesit-thing-settings' for more 1970THING can be a thing defined in `treesit-thing-settings', or a
1971detail. ARG is the same as in `end-of-defun'. 1971predicate, which see. ARG is the same as in `end-of-defun'.
1972 1972
1973TACTIC determines how does this function move between things. It 1973TACTIC determines how does this function move between things. It
1974can be `nested', `top-level', `restricted', or nil. `nested' 1974can be `nested', `top-level', `restricted', or nil. `nested'
@@ -1983,7 +1983,7 @@ should there be one. If omitted, TACTIC is considered to be
1983Return non-nil if successfully moved, nil otherwise." 1983Return non-nil if successfully moved, nil otherwise."
1984 (pcase-let* ((arg (or arg 1)) 1984 (pcase-let* ((arg (or arg 1))
1985 (dest (treesit--navigate-thing 1985 (dest (treesit--navigate-thing
1986 (point) arg 'end pred tactic))) 1986 (point) arg 'end thing tactic)))
1987 (when dest 1987 (when dest
1988 (goto-char dest)))) 1988 (goto-char dest))))
1989 1989
@@ -2124,7 +2124,7 @@ the current line if the beginning of the defun is indented."
2124;; parent: 2124;; parent:
2125;; 1. node covers pos 2125;; 1. node covers pos
2126;; 2. smallest such node 2126;; 2. smallest such node
2127(defun treesit--things-around (pos pred) 2127(defun treesit--things-around (pos thing)
2128 "Return the previous, next, and parent thing around POS. 2128 "Return the previous, next, and parent thing around POS.
2129 2129
2130Return a list of (PREV NEXT PARENT), where PREV and NEXT are 2130Return a list of (PREV NEXT PARENT), where PREV and NEXT are
@@ -2132,7 +2132,7 @@ previous and next sibling things around POS, and PARENT is the
2132parent thing surrounding POS. All of three could be nil if no 2132parent thing surrounding POS. All of three could be nil if no
2133sound things exists. 2133sound things exists.
2134 2134
2135PRED should be a thing defined in `treesit-thing-settings', it 2135THING should be a thing defined in `treesit-thing-settings', it
2136can also be a predicate, which see." 2136can also be a predicate, which see."
2137 (let* ((node (treesit-node-at pos)) 2137 (let* ((node (treesit-node-at pos))
2138 (result (list nil nil nil))) 2138 (result (list nil nil nil)))
@@ -2156,7 +2156,7 @@ can also be a predicate, which see."
2156 when node 2156 when node
2157 do (let ((cursor node) 2157 do (let ((cursor node)
2158 (iter-pred (lambda (node) 2158 (iter-pred (lambda (node)
2159 (and (treesit-node-match-p node pred) 2159 (and (treesit-node-match-p node thing)
2160 (funcall pos-pred node))))) 2160 (funcall pos-pred node)))))
2161 ;; Find the node just before/after POS to start searching. 2161 ;; Find the node just before/after POS to start searching.
2162 (save-excursion 2162 (save-excursion
@@ -2170,11 +2170,11 @@ can also be a predicate, which see."
2170 (setf (nth idx result) 2170 (setf (nth idx result)
2171 (treesit-node-top-level cursor iter-pred t)) 2171 (treesit-node-top-level cursor iter-pred t))
2172 (setq cursor (treesit-search-forward 2172 (setq cursor (treesit-search-forward
2173 cursor pred backward backward))))) 2173 cursor thing backward backward)))))
2174 ;; 2. Find the parent defun. 2174 ;; 2. Find the parent defun.
2175 (let ((cursor (or (nth 0 result) (nth 1 result) node)) 2175 (let ((cursor (or (nth 0 result) (nth 1 result) node))
2176 (iter-pred (lambda (node) 2176 (iter-pred (lambda (node)
2177 (and (treesit-node-match-p node pred) 2177 (and (treesit-node-match-p node thing)
2178 (not (treesit-node-eq node (nth 0 result))) 2178 (not (treesit-node-eq node (nth 0 result)))
2179 (not (treesit-node-eq node (nth 1 result))) 2179 (not (treesit-node-eq node (nth 1 result)))
2180 (< (treesit-node-start node) 2180 (< (treesit-node-start node)
@@ -2211,7 +2211,7 @@ can also be a predicate, which see."
2211;; -> Obviously we don't want to go to parent's end, instead, we 2211;; -> Obviously we don't want to go to parent's end, instead, we
2212;; want to go to parent's prev-sibling's end. Again, we recurse 2212;; want to go to parent's prev-sibling's end. Again, we recurse
2213;; in the function to do that. 2213;; in the function to do that.
2214(defun treesit--navigate-thing (pos arg side pred &optional tactic recursing) 2214(defun treesit--navigate-thing (pos arg side thing &optional tactic recursing)
2215 "Navigate thing ARG steps from POS. 2215 "Navigate thing ARG steps from POS.
2216 2216
2217If ARG is positive, move forward that many steps, if negative, 2217If ARG is positive, move forward that many steps, if negative,
@@ -2222,7 +2222,7 @@ This function doesn't actually move point, it just returns the
2222position it would move to. If there aren't enough things to move 2222position it would move to. If there aren't enough things to move
2223across, return nil. 2223across, return nil.
2224 2224
2225PRED can be a regexp, a predicate function, and more. See 2225THING can be a regexp, a predicate function, and more. See
2226`treesit-thing-settings' for details. 2226`treesit-thing-settings' for details.
2227 2227
2228TACTIC determines how does this function move between things. It 2228TACTIC determines how does this function move between things. It
@@ -2252,13 +2252,13 @@ function is called recursively."
2252 (while (> counter 0) 2252 (while (> counter 0)
2253 (pcase-let 2253 (pcase-let
2254 ((`(,prev ,next ,parent) 2254 ((`(,prev ,next ,parent)
2255 (treesit--things-around pos pred))) 2255 (treesit--things-around pos thing)))
2256 ;; When PARENT is nil, nested and top-level are the same, if 2256 ;; When PARENT is nil, nested and top-level are the same, if
2257 ;; there is a PARENT, make PARENT to be the top-level parent 2257 ;; there is a PARENT, make PARENT to be the top-level parent
2258 ;; and pretend there is no nested PREV and NEXT. 2258 ;; and pretend there is no nested PREV and NEXT.
2259 (when (and (eq tactic 'top-level) 2259 (when (and (eq tactic 'top-level)
2260 parent) 2260 parent)
2261 (setq parent (treesit-node-top-level parent pred t) 2261 (setq parent (treesit-node-top-level parent thing t)
2262 prev nil 2262 prev nil
2263 next nil)) 2263 next nil))
2264 ;; If TACTIC is `restricted', the implementation is very simple. 2264 ;; If TACTIC is `restricted', the implementation is very simple.
@@ -2290,7 +2290,7 @@ function is called recursively."
2290 ;; the end of next before recurring.) 2290 ;; the end of next before recurring.)
2291 (setq pos (or (treesit--navigate-thing 2291 (setq pos (or (treesit--navigate-thing
2292 (treesit-node-end (or next parent)) 2292 (treesit-node-end (or next parent))
2293 1 'beg pred tactic t) 2293 1 'beg thing tactic t)
2294 (throw 'term nil))) 2294 (throw 'term nil)))
2295 ;; Normal case. 2295 ;; Normal case.
2296 (setq pos (funcall advance (or next parent)))) 2296 (setq pos (funcall advance (or next parent))))
@@ -2302,7 +2302,7 @@ function is called recursively."
2302 ;; Special case: go to prev end-of-defun. 2302 ;; Special case: go to prev end-of-defun.
2303 (setq pos (or (treesit--navigate-thing 2303 (setq pos (or (treesit--navigate-thing
2304 (treesit-node-start (or prev parent)) 2304 (treesit-node-start (or prev parent))
2305 -1 'end pred tactic t) 2305 -1 'end thing tactic t)
2306 (throw 'term nil))) 2306 (throw 'term nil)))
2307 ;; Normal case. 2307 ;; Normal case.
2308 (setq pos (funcall advance (or prev parent)))))) 2308 (setq pos (funcall advance (or prev parent))))))
@@ -2312,17 +2312,17 @@ function is called recursively."
2312 (if (eq counter 0) pos nil))) 2312 (if (eq counter 0) pos nil)))
2313 2313
2314;; TODO: In corporate into thing-at-point. 2314;; TODO: In corporate into thing-at-point.
2315(defun treesit-thing-at-point (pred tactic) 2315(defun treesit-thing-at-point (thing tactic)
2316 "Return the thing node at point or nil if none is found. 2316 "Return the thing node at point or nil if none is found.
2317 2317
2318\"Thing\" is defined by PRED, which can be a regexp, a 2318\"Thing\" is defined by THING, which can be a regexp, a
2319predication function, and more, see `treesit-thing-settings' 2319predication function, and more, see `treesit-thing-settings'
2320for details. 2320for details.
2321 2321
2322Return the top-level defun if TACTIC is `top-level', return the 2322Return the top-level defun if TACTIC is `top-level', return the
2323immediate parent thing if TACTIC is `nested'." 2323immediate parent thing if TACTIC is `nested'."
2324 (pcase-let* ((`(,_ ,next ,parent) 2324 (pcase-let* ((`(,_ ,next ,parent)
2325 (treesit--things-around (point) pred)) 2325 (treesit--things-around (point) thing))
2326 ;; If point is at the beginning of a thing, we 2326 ;; If point is at the beginning of a thing, we
2327 ;; prioritize that thing over the parent in nested 2327 ;; prioritize that thing over the parent in nested
2328 ;; mode. 2328 ;; mode.
@@ -2330,7 +2330,7 @@ immediate parent thing if TACTIC is `nested'."
2330 next) 2330 next)
2331 parent))) 2331 parent)))
2332 (if (eq tactic 'top-level) 2332 (if (eq tactic 'top-level)
2333 (treesit-node-top-level node pred t) 2333 (treesit-node-top-level node thing t)
2334 node))) 2334 node)))
2335 2335
2336(defun treesit-defun-at-point () 2336(defun treesit-defun-at-point ()