I'm trying to create a commit buffer: write text, save to commit, show errors in new buffer on failure.
I'm having trouble with the last step.
I figured I'd use
BufDelete so the user can save and close the file and then my command is executed. However, sometimes the failures are verbose and I need somewhere to show the output.
:help BufDelete warns:
Don't change to another buffer, it will cause problems.
Seems like I cannot create a buffer and switch back:
" ~/.vim/buftest.vim setlocal bufhidden=wipe augroup buftest au! au buftest BufDelete <buffer> new | wincmd p augroup END " List our active autocmd au * <buffer>
edit ~/smell and
source ~/.vim/buftest.vim. Then
ZZ to save and close which wipes the file and invokes
BufDelete. I get error:
|| Error detected while processing BufDelete Autocommands for "<buffer=220>": || E937: Attempt to delete a buffer that is in use: smell
Maybe I need to use an autocmd that doesn't warn about changing buffers?
I tried this variant using
BufWinLeave, but I can't delete the original commit buffer without getting errors:
" ~/.vim/buftest.vim function! Cmd(msg_buf) " Since the buffer sticks around, don't execute anything next time we " close it. au! buftest * <buffer> " Always cause error for testing. "~ let r = system('svn status ~/code/svntest/checkout/') " succeeds let r = system('svn status ~') " fails if r =~# '\v^svn: (warning|error)' new " Make scratch buffer setlocal buftype=nofile bufhidden=hide noswapfile buflisted 0put =r else " Work is done, want to remove the message buffer. " Uncommenting causes E937: Attempt to delete a buffer that is in use: smell "~ execute a:msg_buf ..'bwipe' " Doesn't delete buffer until it's viewed and closed again. call setbufvar(str2nr(a:msg_buf), '&bufhidden', 'wipe') " I guess unlist it so it doesn't clutter up? call setbufvar(str2nr(a:msg_buf), '&buflisted', 0) endif endf augroup buftest au! au BufWinLeave <buffer> call Cmd(expand('<abuf>')) augroup END au * <buffer>