(defalias 'treesit-thing-defined-p 'treesit-thing-definition
"Return non-nil if THING is defined.")
-(defun treesit-beginning-of-thing (pred &optional arg tactic)
+(defun treesit-beginning-of-thing (thing &optional arg tactic)
"Like `beginning-of-defun', but generalized into things.
-PRED is a thing predicate, see `treesit-thing-settings' for more
-detail. ARG is the same as in `beginning-of-defun'.
+THING can be a thing defined in `treesit-thing-settings', or a
+predicate, which see. ARG is the same as in `beginning-of-defun'.
TACTIC determines how does this function move between things. It
can be `nested', `top-level', `restricted', or nil. `nested'
Return non-nil if successfully moved, nil otherwise."
(pcase-let* ((arg (or arg 1))
(dest (treesit--navigate-thing
- (point) (- arg) 'beg pred tactic)))
+ (point) (- arg) 'beg thing tactic)))
(when dest
(goto-char dest))))
-(defun treesit-end-of-thing (pred &optional arg tactic)
+(defun treesit-end-of-thing (thing &optional arg tactic)
"Like `end-of-defun', but generalized into things.
-PRED is a thing predicate, see `treesit-thing-settings' for more
-detail. ARG is the same as in `end-of-defun'.
+THING can be a thing defined in `treesit-thing-settings', or a
+predicate, which see. ARG is the same as in `end-of-defun'.
TACTIC determines how does this function move between things. It
can be `nested', `top-level', `restricted', or nil. `nested'
Return non-nil if successfully moved, nil otherwise."
(pcase-let* ((arg (or arg 1))
(dest (treesit--navigate-thing
- (point) arg 'end pred tactic)))
+ (point) arg 'end thing tactic)))
(when dest
(goto-char dest))))
;; parent:
;; 1. node covers pos
;; 2. smallest such node
-(defun treesit--things-around (pos pred)
+(defun treesit--things-around (pos thing)
"Return the previous, next, and parent thing around POS.
Return a list of (PREV NEXT PARENT), where PREV and NEXT are
parent thing surrounding POS. All of three could be nil if no
sound things exists.
-PRED should be a thing defined in `treesit-thing-settings', it
+THING should be a thing defined in `treesit-thing-settings', it
can also be a predicate, which see."
(let* ((node (treesit-node-at pos))
(result (list nil nil nil)))
when node
do (let ((cursor node)
(iter-pred (lambda (node)
- (and (treesit-node-match-p node pred)
+ (and (treesit-node-match-p node thing)
(funcall pos-pred node)))))
;; Find the node just before/after POS to start searching.
(save-excursion
(setf (nth idx result)
(treesit-node-top-level cursor iter-pred t))
(setq cursor (treesit-search-forward
- cursor pred backward backward)))))
+ cursor thing backward backward)))))
;; 2. Find the parent defun.
(let ((cursor (or (nth 0 result) (nth 1 result) node))
(iter-pred (lambda (node)
- (and (treesit-node-match-p node pred)
+ (and (treesit-node-match-p node thing)
(not (treesit-node-eq node (nth 0 result)))
(not (treesit-node-eq node (nth 1 result)))
(< (treesit-node-start node)
;; -> Obviously we don't want to go to parent's end, instead, we
;; want to go to parent's prev-sibling's end. Again, we recurse
;; in the function to do that.
-(defun treesit--navigate-thing (pos arg side pred &optional tactic recursing)
+(defun treesit--navigate-thing (pos arg side thing &optional tactic recursing)
"Navigate thing ARG steps from POS.
If ARG is positive, move forward that many steps, if negative,
position it would move to. If there aren't enough things to move
across, return nil.
-PRED can be a regexp, a predicate function, and more. See
+THING can be a regexp, a predicate function, and more. See
`treesit-thing-settings' for details.
TACTIC determines how does this function move between things. It
(while (> counter 0)
(pcase-let
((`(,prev ,next ,parent)
- (treesit--things-around pos pred)))
+ (treesit--things-around pos thing)))
;; When PARENT is nil, nested and top-level are the same, if
;; there is a PARENT, make PARENT to be the top-level parent
;; and pretend there is no nested PREV and NEXT.
(when (and (eq tactic 'top-level)
parent)
- (setq parent (treesit-node-top-level parent pred t)
+ (setq parent (treesit-node-top-level parent thing t)
prev nil
next nil))
;; If TACTIC is `restricted', the implementation is very simple.
;; the end of next before recurring.)
(setq pos (or (treesit--navigate-thing
(treesit-node-end (or next parent))
- 1 'beg pred tactic t)
+ 1 'beg thing tactic t)
(throw 'term nil)))
;; Normal case.
(setq pos (funcall advance (or next parent))))
;; Special case: go to prev end-of-defun.
(setq pos (or (treesit--navigate-thing
(treesit-node-start (or prev parent))
- -1 'end pred tactic t)
+ -1 'end thing tactic t)
(throw 'term nil)))
;; Normal case.
(setq pos (funcall advance (or prev parent))))))
(if (eq counter 0) pos nil)))
;; TODO: In corporate into thing-at-point.
-(defun treesit-thing-at-point (pred tactic)
+(defun treesit-thing-at-point (thing tactic)
"Return the thing node at point or nil if none is found.
-\"Thing\" is defined by PRED, which can be a regexp, a
+\"Thing\" is defined by THING, which can be a regexp, a
predication function, and more, see `treesit-thing-settings'
for details.
Return the top-level defun if TACTIC is `top-level', return the
immediate parent thing if TACTIC is `nested'."
(pcase-let* ((`(,_ ,next ,parent)
- (treesit--things-around (point) pred))
+ (treesit--things-around (point) thing))
;; If point is at the beginning of a thing, we
;; prioritize that thing over the parent in nested
;; mode.
next)
parent)))
(if (eq tactic 'top-level)
- (treesit-node-top-level node pred t)
+ (treesit-node-top-level node thing t)
node)))
(defun treesit-defun-at-point ()