rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.09k stars 176 forks source link

`rust-end-of-defun` and `rust-beginning-of-defun` inconsistent around impl blocks #454

Closed cowile closed 2 months ago

cowile commented 1 year ago

Similar to #227

If outside of an impl block, rust-end-of-defun will jump to the end of that block, but using rust-beginning-of-defun immediately after will stop at each nested function definition.

[cursor]impl MyStruct {
    fn f1() {
    }

    fn f2() {
    }

    fn f3() {
    }
}

Call rust-end-of-defun Call rust-beginning-of-defun

impl MyStruct {
    fn f1() {
    }

    fn f2() {
    }

[cursor]    fn f3() {
    }
}

For consistent behavior, I would expect either the cursor is back where it started (if impl is considered a function block) or at the beginning of f1 (if it is not).

psibi commented 4 months ago

Can you test it with the tree-sitter support: https://github.com/rust-lang/rust-mode?tab=readme-ov-file#tree-sitter

If outside of an impl block, rust-end-of-defun will jump to the end of that block, but using rust-beginning-of-defun immediately after will stop at each nested function definition.

From my testing, treesit-end-of-defun jumps to the end of the block and using treesit-beginning-of-defun jumps to the start of the block.

For consistent behavior, I would expect either the cursor is back where it started

I believe this is fixed via the tree sitter support.

psibi commented 2 months ago

I'm closing this issue for now as I haven't been able to reproduce it recently using tree sitter and haven't heard back. Please feel free to reopen it if you encounter the issue again in the future.