GNU bug report logs -
#61617
M-x mark-defun doesn't work correctly in tree-sitter modes when comments exist between functions
Previous Next
Full log
Message #17 received at 61617 <at> debbugs.gnu.org (full text, mbox):
> On Feb 24, 2023, at 11:27 PM, Evgeni Kolev <evgenysw <at> gmail.com> wrote:
>
> On Sat, Feb 25, 2023 at 7:08 AM Yuan Fu <casouri <at> gmail.com> wrote:
>
>> Huh, with or without comments, mark-defun always includes the empty
>> lines before the defun for me. I get the same behavior in rust-ts-mode.
>> This seems intentional, because this is at the end of the definition of
>> mark-defun:
>>
>> (skip-chars-backward "[:space:]\n")
>> (unless (bobp)
>> (forward-line 1))
>
> Did you check with my example or another example? With my example, the
> issue I get is that only the empty lines are marked, without the
> defun, without the comments. I'm attaching two screenshots - before
> and after mark-defun.
>
> Note: I get the correct behaviour when there is just one defun in the
> file. But if there are more, or the defun at point is not at the top
> of the file - mark-defun does not work as expected.
Sorry, I used wrong go mode when testing your recipe. I used go-mode thinking it is go-ts-mode :-( Using go-ts-mode, I can reproduce what you see, yes.
The problem you discovered revealed some shortcoming in our tree-sitter navigation function, and requires quite a few non-trivial changes, I working on fixing it.
The direct cause is that (treesit-beginning-of-defun -1) is supposed to go to the beginning of next defun, but instead goes to the beginning of next next defun. That was a design decision I made but I can see it causing old functions to misbehave.
Yuan
This bug report was last modified 2 years and 169 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.