You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
muffin4
added a commit
to muffin4/gofmt.vim
that referenced
this issue
May 19, 2021
Description
Every time
gofmt#apply
is invoked, another change is added to the undo tree. This is perfectly fine whengofmt
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
andCTRL-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 theautocmd
, like with a mapping.Suggestion
gofmt#apply
could check whethergofmt -l
lists its standard input as differing from its formatting. Based on thatgofmt#apply
could terminate without making any changes to the buffer.from
gofmt --help
:The
-l
option is also supported bygoimports
.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.The text was updated successfully, but these errors were encountered: