z0mbix / vim-shfmt

Vim plugin for shfmt (https://github.com/mvdan/sh)
MIT License
135 stars 11 forks source link

Format on save undoes all changes in file #2

Closed nkakouros closed 5 years ago

nkakouros commented 6 years ago

I think the logic of the plugin it to before saving to format the file. But the file that is being formatted is the one without the changes and this is what is being saved.

Probably related to the above is the fact that the undo history gets deleted for the file in question after saving, even if set hidden is present.

nkakouros commented 6 years ago

Changing

        autocmd BufWritePre *.sh Shfmt
        autocmd FileType sh autocmd BufWritePre <buffer> Shfmt

to

        autocmd BufWritePost *.sh Shfmt
        autocmd FileType sh autocmd BufWritePost <buffer> Shfmt

seems to solve the issue of losing the changes. But the undo history issue remains. The problem is not that the history gets emptied as I mentioned, but that it fills with a lot of 'no-op' records.

nkakouros commented 6 years ago

This might be relevant to the undo history issue https://stackoverflow.com/questions/24690441/call-a-function-without-adding-to-undo-list

I am at my limits of vimscript here to move further.

z0mbix commented 5 years ago

@tterranigma Thanks for the report, and sorry about the delay in getting to this. I have just updated master (#3) with your change, and it is still working for me. I don't really know how to handle the undo history problem right now, but I have been looking at other similar plugins which also don't handle this well, so not sure how best to solve that one.

CC: @sublimino @radioinmyhead