unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#61617: M-x mark-defun doesn't work correctly in tree-sitter modes when comments exist between functions
@ 2023-02-19  8:39 Evgeni Kolev
  2023-02-20  8:30 ` Evgeni Kolev
  2023-02-25  5:08 ` Yuan Fu
  0 siblings, 2 replies; 7+ messages in thread
From: Evgeni Kolev @ 2023-02-19  8:39 UTC (permalink / raw)
  To: 61617

M-x mark-defun doesn't work correctly when the function at point is
preceded by a comment.

I've noticed this bug in go-ts-mode, and have also checked it's
reproduced in rust-ts-mode:

To reproduce:
1. with the following code in go-ts-mode, "|" is the point (in function sum2)
```
package main

func sum(a, b int) int {
    return a + b
}

// comment
func sum2(a, b int) int {
    Ireturn a + b
}
```
2. Execute M-x mark-defun
3. The region selected is wrong - the empty line between the two
functions is marked. I expect only function sum2 and the preceding
comment to be marked.

Observations:
- The issue is reproducible with a fresh build of master, and
reproducible with emacs -Q.
- The issue is also reproducible in rust-ts-mode which makes me think
the root cause is in treesit code (treesit.el maybe).
- From what I've checked, (beginning-of-defun-comments) works
correctly, but (end-of-defun) doesn't. These two (and other) functions
are used by mark-defun.
- The issue does not exist when the function is not preceded by a
comment. In other words - the issue is not reproduced when no comments
exist between the functions.

Below is a Rust example which reproduces the issue, again "|" is the
point (in function main2). Steps to reproduce are identical to the
steps for go-ts-mode:
```
fn main() {
    println!("Hello World!");
}

// comment
fn main2() {
    |println!("Hello World!");
}
```





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-27 16:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-19  8:39 bug#61617: M-x mark-defun doesn't work correctly in tree-sitter modes when comments exist between functions Evgeni Kolev
2023-02-20  8:30 ` Evgeni Kolev
2023-02-25  5:08 ` Yuan Fu
2023-02-25  7:27   ` Evgeni Kolev
2023-02-27  0:42     ` Yuan Fu
2023-02-27  9:24       ` Yuan Fu
2023-02-27 16:03         ` Evgeni Kolev

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).