[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master ed152ccd1d6 3/6: Rename PRED to THING in tree-sitter navigation f
From: |
Yuan Fu |
Subject: |
master ed152ccd1d6 3/6: Rename PRED to THING in tree-sitter navigation functions |
Date: |
Sat, 2 Sep 2023 00:04:33 -0400 (EDT) |
branch: master
commit ed152ccd1d69dbd53bcf4ba32da788753d0ea2e2
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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.
---
lisp/treesit.el | 46 +++++++++++++++++++++++-----------------------
1 file 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
(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'
@@ -1960,15 +1960,15 @@ should there be one. If omitted, TACTIC is considered
to be
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'
@@ -1983,7 +1983,7 @@ should there be one. If omitted, TACTIC is considered to
be
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))))
@@ -2124,7 +2124,7 @@ the current line if the beginning of the defun is
indented."
;; 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
@@ -2132,7 +2132,7 @@ previous and next sibling things around POS, and PARENT
is the
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)))
@@ -2156,7 +2156,7 @@ can also be a predicate, which see."
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
@@ -2170,11 +2170,11 @@ can also be a predicate, which see."
(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)
@@ -2211,7 +2211,7 @@ can also be a predicate, which see."
;; -> 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,
@@ -2222,7 +2222,7 @@ This function doesn't actually move point, it just
returns the
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
@@ -2252,13 +2252,13 @@ function is called recursively."
(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.
@@ -2290,7 +2290,7 @@ function is called recursively."
;; 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))))
@@ -2302,7 +2302,7 @@ function is called recursively."
;; 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))))))
@@ -2312,17 +2312,17 @@ function is called recursively."
(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.
@@ -2330,7 +2330,7 @@ immediate parent thing if TACTIC is `nested'."
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 ()
- master updated (d286f6889cf -> e6340934d62), Yuan Fu, 2023/09/02
- master ed152ccd1d6 3/6: Rename PRED to THING in tree-sitter navigation functions,
Yuan Fu <=
- master 1e91183c399 5/6: ; * src/treesit.c (Vtreesit_thing_settings): Update docstring., Yuan Fu, 2023/09/02
- master 452697a81ab 2/6: Add an optional arg to Ftreesit_node_match_p, Yuan Fu, 2023/09/02
- master e6340934d62 6/6: ; * lisp/treesit.el (treesit-thing-settings): Declare in treesit.el., Yuan Fu, 2023/09/02
- master 7fc416d90b9 4/6: Don't signal error when calling treesit-node-match-p in treesit.el, Yuan Fu, 2023/09/02
- master 2547fbe9c44 1/6: Obsolete treesit-block/sexp/sentence/text-type-regexp, Yuan Fu, 2023/09/02