Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gofmt adds empty changes to undo tree #5

Open
muffin4 opened this issue May 19, 2021 · 0 comments
Open

gofmt adds empty changes to undo tree #5

muffin4 opened this issue May 19, 2021 · 0 comments

Comments

@muffin4
Copy link

muffin4 commented May 19, 2021

Description

Every time gofmt#apply is invoked, another change is added to the undo tree. This is perfectly fine when gofmt actually changes the buffer, but it's unnecessary and inconvenient if the buffer doesn't actually change.

The empty change in the undo tree makes it more effort to navigate the undo tree (for example with u and CTRL-R) and it marks the buffer as modified. This can force users to save the buffer unnecessarily, if the buffer was previously unmodified. This can happen when the function gets invoked in a way other than with the autocmd, like with a mapping.

Suggestion

gofmt#apply could check whether gofmt -l lists its standard input as differing from its formatting. Based on that gofmt#apply could terminate without making any changes to the buffer.

from gofmt --help:

  -l    list files whose formatting differs from gofmt's

The -l option is also supported by goimports.

It might be a good idea to also add an option to enable or disable this behavior, for example if g:gofmt_exe doesn't support the -l flag or if it's undesired for some other reason.

muffin4 added a commit to muffin4/gofmt.vim that referenced this issue May 19, 2021
by checking the output of `g:gofmt_exe -l`

see issue tweekmonster#5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant