[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter 734df28368 05/10: Fix tree-sitter navigation
From: |
Yuan Fu |
Subject: |
feature/tree-sitter 734df28368 05/10: Fix tree-sitter navigation |
Date: |
Wed, 26 Oct 2022 21:42:00 -0400 (EDT) |
branch: feature/tree-sitter
commit 734df28368c7f7c21b1068a67d4ae89e64d4a3d3
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Fix tree-sitter navigation
* lisp/treesit.el (treesit-search-forward-goto): Track current
position with a local variable instead of (point). Clean up the
condition forms.
(treesit-beginning-of-defun): Fix traverse direction.
---
lisp/treesit.el | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index c6b396494b..8426a02a26 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -892,9 +892,10 @@ progress in terms of buffer position: the start/end
position of
the returned node is always greater than that of NODE.
BACKWARD and ALL are the same as in `treesit-search-forward'."
- (when-let ((start-pos (if start
- (treesit-node-start node)
- (treesit-node-end node))))
+ (when-let* ((start-pos (if start
+ (treesit-node-start node)
+ (treesit-node-end node)))
+ (current-pos start-pos))
;; When searching forward and stopping at beginnings, or search
;; backward stopping at ends, it is possible to "roll back" in
;; position. Take three nodes N1, N2, N3 as an example, if we
@@ -905,19 +906,21 @@ BACKWARD and ALL are the same as in
`treesit-search-forward'."
;; |<--------N1------->|
;; |<--N2-->| |<--N3-->|
(while (and node (if backward
- (>= (point) start-pos)
- (<= (point) start-pos)))
+ (>= current-pos start-pos)
+ (<= current-pos start-pos)))
(setq node (treesit-search-forward
node predicate backward all))
- (if-let ((pos (if start
- (treesit-node-start node)
- (treesit-node-end node))))
- (goto-char pos)))
- ;; If we made reverse progress, go back to where we started.
- (when (if backward
- (>= (point) start-pos)
- (<= (point) start-pos))
- (goto-char start-pos))
+ (setq current-pos (if start
+ (treesit-node-start node)
+ (treesit-node-end node))))
+ (cond
+ ;; When there is a match and match made progress, go to the
+ ;; result position.
+ ((and node
+ (if backward
+ (< current-pos (point))
+ (> current-pos (point))))
+ (goto-char current-pos)))
node))
;;; Navigation
@@ -955,11 +958,13 @@ ARG is the same as in `beginning-of-defun."
;; Go forward.
(while (and (< arg 0)
(setq node (treesit-search-forward-goto
- node treesit-defun-type-regexp t t)))
+ node treesit-defun-type-regexp)))
(setq node (treesit--find-top-level-match
node treesit-defun-type-regexp))
(setq arg (1+ arg))))
- (goto-char (treesit-node-start node))))
+ (when node
+ (goto-char (treesit-node-start node))
+ t)))
(defun treesit-end-of-defun ()
"Tree-sitter `end-of-defun' function."
- feature/tree-sitter updated (5070278539 -> 62c8c8e51a), Yuan Fu, 2022/10/26
- feature/tree-sitter c9df4cace0 02/10: * src/treesit.c (treesit_search_forward): Fix traverses algorithm., Yuan Fu, 2022/10/26
- feature/tree-sitter 5c1b9e65b9 03/10: ; * src/treesit.c (treesit_search_forward): Fix comment., Yuan Fu, 2022/10/26
- feature/tree-sitter 734df28368 05/10: Fix tree-sitter navigation,
Yuan Fu <=
- feature/tree-sitter 62c8c8e51a 10/10: Plug tree-sitter-simple-indent into c-offset-alist, Yuan Fu, 2022/10/26
- feature/tree-sitter e868955bff 04/10: * src/treesit.c (treesit_search_dfs): Fix traverse algorithm., Yuan Fu, 2022/10/26
- feature/tree-sitter 6fb6cb075f 06/10: Add tree-sitter imenu support for js-mode and ts-mode, Yuan Fu, 2022/10/26
- feature/tree-sitter 76b86d9853 08/10: Generalize js--treesit-imenu-top-level-p, Yuan Fu, 2022/10/26
- feature/tree-sitter c352392420 07/10: Add tree-sitter navigation support to python-mode, Yuan Fu, 2022/10/26
- feature/tree-sitter 5532ae81cf 09/10: * lisp/treesit.el (treesit-node-top-level-p): New argument TYPE., Yuan Fu, 2022/10/26
- feature/tree-sitter 1f74e9112e 01/10: Don't disable parse cache in tree-sitter activated js-mode, Yuan Fu, 2022/10/26