]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix treesit-search-forward
authorYuan Fu <casouri@gmail.com>
Mon, 13 Jun 2022 20:22:17 +0000 (13:22 -0700)
committerYuan Fu <casouri@gmail.com>
Mon, 13 Jun 2022 21:20:25 +0000 (14:20 -0700)
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

index 98fcf84355097d400f1412d1c05736a6e413de67..78dfcae7e560c3924057fc6b29e9769624d092f2 100644 (file)
@@ -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.