From a73f2b9990465820d80c58ed25208b72731d410d Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Mon, 13 Jun 2022 13:22:17 -0700 Subject: [PATCH] Fix treesit-search-forward Move the check for movement (if (> arg 0) ;; Make sure we moved forward. (> (funcall pos-fn node) starting-point) ;; Make sure we moved backward. (< (funcall pos-fn node) starting-point)) into cl-loop: if (treesit-node-eq cap-node node) becomes if (and (treesit-node-eq cap-node node) (if (> arg 0) ;; Make sure we moved forward. (> (funcall pos-fn node) starting-point) ;; Make sure we moved backward. (< (funcall pos-fn node) starting-point))) * lisp/treesit.el (treesit-search-forward): Move the check. --- lisp/treesit.el | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 98fcf843550..78dfcae7e56 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -864,17 +864,20 @@ return the matched node. Return nil if search failed." (lambda (node) (and (not (eq (funcall pos-fn node) starting-point)) - (if (> arg 0) - ;; Make sure we move forward. - (> (funcall pos-fn node) starting-point) - ;; Make sure we move backward. - (< (funcall pos-fn node) starting-point)) - (cl-loop for cap-node in - (mapcar - #'cdr - (treesit-query-capture node query)) - if (treesit-node-eq cap-node node) - return t))) + (cl-loop + for cap-node in + (mapcar + #'cdr + (treesit-query-capture node query)) + if (and (treesit-node-eq cap-node node) + (if (> arg 0) + ;; Make sure we moved forward. + (> (funcall pos-fn node) + starting-point) + ;; Make sure we moved backward. + (< (funcall pos-fn node) + starting-point))) + return t))) arg)) for pos = (funcall pos-fn node) ;; If we can find a match, jump to it. -- 2.39.5