vim - Prevent buffer from unloading in autocmd -
i'm writing bufunload
autocmd
, , want conditionally prevent buffer being unloaded or closed within autocmd. there way this?
for instance, want use contents of buffer commit message mercurial using autocmd does:
autocmd bufunload <buffer> !hg ci -l logfile
so if commit fails (the hg
command returns non-zero error code), want leave buffer open , unchanged.
i suggest saving message in variable. in aurum (plugin vcs↔vim integration) there following logic coded: when buffer commit message wiped out or written (which triggers actual committing , wiping out) save 3 variables:
- commit message.
- current commit hex (you can see using
hg log -r .
). - current repository root.
. when committing again following logic used: if current repository root same saved 1 , current commit hex commit message taken variable , initializes buffer.
reasons following behavior:
- if commit failed want restore commit message (same yours).
- if did
hg rollback
, edited , want commit again want restore commit message. - if closed commit buffer because remembered want code more changes want …
- if did not of above not want see old commit message.
saving current commit hex here distinguishing between first 3 , last case.
Comments
Post a Comment