jamessan / vim-gnupg

This script implements transparent editing of gpg encrypted files.
http://www.vim.org/scripts/script.php?script_id=3645
728 stars 73 forks source link

vim-gnupg writes partial file if other autocommands change the buffer #96

Closed Nudin closed 6 years ago

Nudin commented 6 years ago

Hi,

Thanks for vim-gnupg! I'm one of the coauthors of vimwiki and am using both plugins in combination. Recently I found one serve problem of doing so: vimwiki#556 when saving an encrypted wikipage with a TOC beeing auto-updated the page content is lost.

I looked into it: vimwikis autocommand is called by vim-gnupgs autocommand and seem to run correctly. Then vim-gnupg uses '[,']write ! to write to gnupg: https://github.com/jamessan/vim-gnupg/blob/22cbc6b6ab1623edd2e325d256245d21580f912a/plugin/gnupg.vim#L749 '[,'] is the last changed or yanked text. I don't get why you do this. With a simple write ! the problem is gone – but I assume there's a reason for this code?

jamessan commented 6 years ago

This is documented in :help FileWriteCmd, and is to allow writing a partial file to disk. This is partly a Vim bug and partly a plugin bug.

For the plugin side, I can change to clearly differentiate between BufWriteCmd and FileWriteCmd. This could potentially still be a problem if the user does :'<,'>w foo and your plugin then changes that '[ and '] refer to.

The part that's a Vim bug is that you can't (yet) use :lockmarks to preserve these marks. I've been working on fixing that, but haven't completed the code so I can propose it to Bram.

Nudin commented 6 years ago

For the plugin side, I can change to clearly differentiate between BufWriteCmd and FileWriteCmd. This could potentially still be a problem if the user does :'<,'>w foo and your plugin then changes that '[ and '] refer to.

This sounds like a really good solution for now. Writes in the form of :'<,'>w foo are really rare compared to normal writes, so this would fix it for nearly all cases.

The part that's a Vim bug is that you can't (yet) use :lockmarks to preserve these marks. I've been working on fixing that, but haven't completed the code so I can propose it to Bram.

That seems like the proper thing. But until this reaches users one time – I'd like to have the BufWriteCmd/FileWriteCmd`-split.