Subject: bug#61617: M-x mark-defun doesn't work correctly in tree-sitter modes when comments exist between functions

From: Evgeni Kolev <[email-masked]>
Date: Sat, 25 Feb 2023 09:27:17 +0200

On Sat, Feb 25, 2023 at 7:08 AM Yuan Fu <[email-masked]> 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.

>
> Are you using emacs-29 or emacs-30? Theo might have changed something on master.

I've observed the issue on both. If you can't reproduce it - I'll
re-test on a fresh docker image to make sure the issue is not in my
setup. However, I'm pretty sure it's not in my setup because I used a
freshly built emacs just for this purpose (emacs-30 maybe, I'm not
sure), and ran it with emacs -Q.