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:

  1. commit message.
  2. current commit hex (you can see using hg log -r .).
  3. 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:

  1. if commit failed want restore commit message (same yours).
  2. if did hg rollback, edited , want commit again want restore commit message.
  3. if closed commit buffer because remembered want code more changes want …
  4. if did not of above not want see old commit message.

saving current commit hex here distinguishing between first 3 , last case.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -