EricEngineered / vim

Automatically exported from code.google.com/p/vim
0 stars 0 forks source link

bdelete/bwipeout in BufNewFile/BufReadPost autocmd breaks `vim -[poO]` #293

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Given the following rc file:

% cat test_vimrc.vim 
fun! BufReadPost()
  let bufname=bufname('%')
  echomsg bufname
  if bufname[-1:] == ':'
    echomsg "EDIT"
    let bufnr = bufnr('%')
    exec 'edit' bufname[0:-2]
    exec 'bwipeout' bufnr
  endif
endfun
autocmd BufNewFile,BufReadPost * call BufReadPost()

This command fails:

    % vim -N -u test_vimrc.vim -p foo: bar baz -c '3tabclose | qa'
    3 files to edit
    "foo" [New File]
    Error detected while processing command line:
    E784: Cannot close last tab page
    Press ENTER or type command to continue

Using `bufhidden=wipe` instead of `bwipeout` works for `vim -p`, but not for
`-o`.

I could imagine that the pointer to the current buffer needs special
handling/restoring in this case, after the BufNewFile/BufReadPost autocommand 
has
been called.

The use case is handling `file:line` patterns, in the file_line plugin
(https://github.com/bogado/file-line).
See https://github.com/bogado/file-line/pull/37 for a pull request where this
is discussed.

Original issue reported on code.google.com by dhahler@gmail.com on 4 Dec 2014 at 1:27

GoogleCodeExporter commented 9 years ago
I am not sure, it is a good idea, to do this during the startup of Vim. Can't 
this be done after Vim has fully initialized using the VimEnter autocommand?

Original comment by chrisbr...@googlemail.com on 5 Dec 2014 at 7:55

GoogleCodeExporter commented 9 years ago
As can be seen in the PR, it is using VimEnter currently, but only "to make it 
work with -p".

This causes several other issues (can be seen in the plugins issue tracker) 
though, both when using `bufdo` or `argdo` to handle all buffers/arguments.

Original comment by dhahler@gmail.com on 5 Dec 2014 at 8:50