aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorYuan Fu2023-02-27 00:14:32 -0800
committerYuan Fu2023-02-27 00:14:32 -0800
commitaee10ca1cbee1d653f89f028c34066bf3ebb32ab (patch)
tree2f95d63c61b4acb2dbd35965c866da045cf80caf /test/src
parentedf5b97686908114f254b5077c71e8202149545f (diff)
downloademacs-aee10ca1cbee1d653f89f028c34066bf3ebb32ab.tar.gz
emacs-aee10ca1cbee1d653f89f028c34066bf3ebb32ab.zip
Adjust tree-sitter defun navigation (bug#61617)
Before this change, when you use a tree-sitter navigation function to move to the next beginning of a thing, it jumps over the immediate next thing and lands you at the beginning of the next-next thing. Eg, when point is at the "|", and we evaluate (treesit--navigate-thing pos 1 'beg), we go from | (thing) (thing) to (thing) |(thing) But some might expect point to go to |(thing) (thing) instead, which makes sense. Also, that's how Emacs expect defun navigation functions to work. The discrepancy in expectation causes bug#61617. In this change I made tree-sitter navigation functions to work as what Emacs expects. And what I described for moving to the next beginning of thing is similarly applicable to moving to the end of previous end of thing. * lisp/treesit.el (treesit-beginning-of-defun) (treesit-end-of-defun): Handle the case where defun-skipper moves point back to where we started, by adding a retry. (treesit--navigate-thing): Add a single condition checking for progress to the condition form responsible for checking whether to skip the next defun. Namely (eq pos (funcall advance next)))). * test/src/treesit-tests.el: (treesit--ert-defun-navigation-nested-master) (treesit--ert-defun-navigation-top-level-master): Change tests to reflect the new expectation.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/treesit-tests.el32
1 files changed, 16 insertions, 16 deletions
diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el
index 5aa12e8aa0e..468cd221ef9 100644
--- a/test/src/treesit-tests.el
+++ b/test/src/treesit-tests.el
@@ -977,22 +977,22 @@ and \"]\"."
977 977
978(defvar treesit--ert-defun-navigation-nested-master 978(defvar treesit--ert-defun-navigation-nested-master
979 ;; START PREV-BEG NEXT-END PREV-END NEXT-BEG 979 ;; START PREV-BEG NEXT-END PREV-END NEXT-BEG
980 '((0 103 105 102 106) ; Between Beg of parent & 1st sibling. 980 '((0 103 105 102 104) ; Between Beg of parent & 1st sibling.
981 (1 103 105 102 106) ; Beg of 1st sibling. 981 (1 103 105 102 106) ; Beg of 1st sibling.
982 (2 104 105 102 106) ; Inside 1st sibling. 982 (2 104 105 102 106) ; Inside 1st sibling.
983 (3 104 107 102 109) ; End of 1st sibling. 983 (3 104 107 102 106) ; End of 1st sibling.
984 (4 104 107 102 109) ; Between 1st sibling & 2nd sibling. 984 (4 104 107 105 106) ; Between 1st sibling & 2nd sibling.
985 (5 104 107 102 109) ; Beg of 2nd sibling. 985 (5 104 107 105 109) ; Beg of 2nd sibling.
986 (6 106 107 105 109) ; Inside 2nd sibling. 986 (6 106 107 105 109) ; Inside 2nd sibling.
987 (7 106 108 105 109) ; End of 2nd sibling. 987 (7 106 108 105 109) ; End of 2nd sibling.
988 (8 106 108 105 109) ; Between 2nd sibling & end of parent. 988 (8 106 108 107 109) ; Between 2nd sibling & end of parent.
989 (9 103 110 102 nil) ; End of parent. 989 (9 103 110 102 109) ; End of parent.
990 990
991 (100 nil 102 nil 103) ; Before 1st parent. 991 (100 nil 102 nil 101) ; Before 1st parent.
992 (101 nil 102 nil 103) ; Beg of 1st parent. 992 (101 nil 102 nil 103) ; Beg of 1st parent.
993 (102 101 108 nil 109) ; Between 1st & 2nd parent. 993 (102 101 108 102 103) ; Between 1st & 2nd parent.
994 (103 101 108 nil 109) ; Beg of 2nd parent. 994 (103 101 108 102 109) ; Beg of 2nd parent.
995 (110 109 nil 108 nil) ; After 3rd parent. 995 (110 109 nil 110 nil) ; After 3rd parent.
996 ) 996 )
997 "Master of nested navigation test. 997 "Master of nested navigation test.
998 998
@@ -1000,7 +1000,7 @@ This basically says, e.g., \"start with point on marker 0, go to
1000the prev-beg, now point should be at marker 103\", etc.") 1000the prev-beg, now point should be at marker 103\", etc.")
1001 1001
1002(defvar treesit--ert-defun-navigation-top-level-master 1002(defvar treesit--ert-defun-navigation-top-level-master
1003 ;; START PREV-BEG NEXT-END NEXT-BEG PREV-END 1003 ;; START PREV-BEG NEXT-END PREV-END NEXT-BEG
1004 '((0 103 108 102 109) ; Between Beg of parent & 1st sibling. 1004 '((0 103 108 102 109) ; Between Beg of parent & 1st sibling.
1005 (1 103 108 102 109) ; Beg of 1st sibling. 1005 (1 103 108 102 109) ; Beg of 1st sibling.
1006 (2 103 108 102 109) ; Inside 1st sibling. 1006 (2 103 108 102 109) ; Inside 1st sibling.
@@ -1010,14 +1010,14 @@ the prev-beg, now point should be at marker 103\", etc.")
1010 (6 103 108 102 109) ; Inside 2nd sibling. 1010 (6 103 108 102 109) ; Inside 2nd sibling.
1011 (7 103 108 102 109) ; End of 2nd sibling. 1011 (7 103 108 102 109) ; End of 2nd sibling.
1012 (8 103 108 102 109) ; Between 2nd sibling & end of parent. 1012 (8 103 108 102 109) ; Between 2nd sibling & end of parent.
1013 (9 103 110 102 nil) ; End of parent. 1013 (9 103 110 102 109) ; End of parent.
1014 1014
1015 ;; Top-level defuns should be identical to the nested test. 1015 ;; Top-level defuns should be identical to the nested test.
1016 (100 nil 102 nil 103) ; Before 1st parent. 1016 (100 nil 102 nil 101) ; Before 1st parent.
1017 (101 nil 102 nil 103) ; Beg of 1st parent. 1017 (101 nil 102 nil 103) ; Beg of 1st parent.
1018 (102 101 108 nil 109) ; Between 1st & 2nd parent. 1018 (102 101 108 102 103) ; Between 1st & 2nd parent.
1019 (103 101 108 nil 109) ; Beg of 2nd parent. 1019 (103 101 108 102 109) ; Beg of 2nd parent.
1020 (110 109 nil 108 nil) ; After 3rd parent. 1020 (110 109 nil 110 nil) ; After 3rd parent.
1021 ) 1021 )
1022 "Master of top-level navigation test.") 1022 "Master of top-level navigation test.")
1023 1023