I'm writing a BufUnload
autocmd
, and I want to conditionally prevent the buffer from actually being unloaded or closed from within the autocmd. Is there a way to do this?
For instance, I want to use the contents of the buffer as a commit message for mercurial using an autocmd that does:
autocmd BufUnload <buffer> !hg ci -l logfile
So if the commit fails (the hg
command returns non-zero error code), I want to leave the buffer open and unchanged.
I would suggest saving this message in a variable. In aurum (plugin for VCS↔Vim integration) there is the following logic coded: when buffer with commit message is wiped out or written (which triggers actual committing and wiping it out) I save three variables:
hg log -r .
).. Then when committing something again the following logic is used: if current repository root is the same as the saved one and so is current commit hex then commit message is taken from the variable and initializes the buffer.
Reasons for the following behavior:
hg rollback
, edited something and want to commit again I want to restore commit message.Saving current commit hex is here for distinguishing between first three and the last case.