]> git.eshelyaron.com Git - emacs.git/commit
Adjust tree-sitter defun navigation (bug#61617)
authorYuan Fu <casouri@gmail.com>
Mon, 27 Feb 2023 08:14:32 +0000 (00:14 -0800)
committerYuan Fu <casouri@gmail.com>
Mon, 27 Feb 2023 08:14:32 +0000 (00:14 -0800)
commitaee10ca1cbee1d653f89f028c34066bf3ebb32ab
tree2f95d63c61b4acb2dbd35965c866da045cf80caf
parentedf5b97686908114f254b5077c71e8202149545f
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.
lisp/treesit.el
test/src/treesit-tests.el