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

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

Closed
Nudin opened this issue Sep 14, 2018 · 2 comments · Fixed by #97
Closed

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

Nudin opened this issue Sep 14, 2018 · 2 comments · Fixed by #97

Comments

@Nudin
Copy link

Nudin commented Sep 14, 2018

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:

let cmd = { 'level': 1, 'ex': "'[,']write !" }

'[,'] 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
Copy link
Owner

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
Copy link
Author

Nudin commented Sep 15, 2018

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.

jamessan added a commit that referenced this issue Nov 18, 2018
BufWriteCmd writes the whole buffer, so it can use the bare ":w".  Other
plugins may manipulate the '[/'] marks on save, which can cause the
write with marks to not write the entire buffer.

Closes: #96
Signed-off-by: James McCoy <jamessan@jamessan.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants