emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tree-sitter a73f2b9990 04/26: Fix treesit-search-forward


From: Yuan Fu
Subject: feature/tree-sitter a73f2b9990 04/26: Fix treesit-search-forward
Date: Thu, 16 Jun 2022 14:53:45 -0400 (EDT)

branch: feature/tree-sitter
commit a73f2b9990465820d80c58ed25208b72731d410d
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    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 98fcf84355..78dfcae7e5 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]