Skip to content

rust-format-buffer does not preserve point position #162

@Wilfred

Description

@Wilfred

Suppose I have the following code, where | is the point:

fn foo(foo_bar_baz1: i32, foo_bar_baz2: i32, foo_bar_baz3: i32, foo_bar_baz4: i32, foo_bar_baz5: i32, foo_bar_baz6: i32) {

}

fn bar() {|}

Calling M-x rust-format-buffer naively moves to the same position after formatting, putting point in the arguments to foo. It then calls rust--after-revert-hook, which moves point to the start of the buffer.

Ideally, we'd use rustfmt's --write-mode=diff so emacs-rustfmt could just apply the diff. Emacs' markers are smart enough to move if text is inserted before them. This is how gofmt is integrated with Emacs.

A simple partial fix would be to move to the same line number and column number as before -- this would handle more cases correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions