diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 79d617b..39c2bd4 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -66,6 +66,7 @@ let s:nearby_disabled = 0 let s:paused = 0 let s:pwin_by_tagbar = 0 let s:buffer_seqno = 0 +let s:vim_quitting = 0 let s:window_expanded = 0 let s:expand_bufnr = -1 @@ -1039,10 +1040,15 @@ function! s:CreateAutocommands() abort autocmd CursorMoved __Tagbar__.* nested call s:ShowInPreviewWin() endif + autocmd QuitPre * let s:vim_quitting = 1 autocmd WinEnter * nested call s:QuitIfOnlyWindow() autocmd WinEnter * if bufwinnr(s:TagbarBufName()) == -1 | \ call s:ShrinkIfExpanded() | \ endif + autocmd BufWinEnter * if exists('s:reopen_window') | + \ unlet s:reopen_window | + \ call s:OpenWindow('') | + \ endif autocmd BufWritePost * call \ s:AutoUpdate(fnamemodify(expand(''), ':p'), 1) @@ -4028,10 +4034,13 @@ endfunction " s:QuitIfOnlyWindow() {{{2 function! s:QuitIfOnlyWindow() abort let tagbarwinnr = bufwinnr(s:TagbarBufName()) - if tagbarwinnr == -1 + if tagbarwinnr == -1 || exists('s:reopen_window') return endif + let vim_quitting = s:vim_quitting + let s:vim_quitting = 0 + let curwinnr = winnr() let prevwinnr = winnr('#') == 0 ? curwinnr : winnr('#') call s:goto_win(tagbarwinnr, 1) @@ -4039,7 +4048,7 @@ function! s:QuitIfOnlyWindow() abort " Check if there is more than one window if s:NextNormalWindow() == -1 " Check if there is more than one tab page - if tabpagenr('$') == 1 + if tabpagenr('$') == 1 && vim_quitting " Before quitting Vim, delete the tagbar buffer so that " the '0 mark is correctly set to the previous buffer. " Also disable autocmd on this command to avoid unnecessary @@ -4048,6 +4057,15 @@ function! s:QuitIfOnlyWindow() abort noautocmd bdelete endif quit + elseif tabpagenr('$') == 1 + " The last normal window closed due to a :bdelete/:bwipeout. + " In order to get a normal file window back delete the Tagbar + " buffer that we're currently displaying and reset the Tagbar-set + " window options, and then re-open the Tagbar window once Vim has + " switched to the buffer it has chosen to display next. + noautocmd bdelete + set winfixwidth< + let s:reopen_window = 1 elseif exists('t:tagbar_buf_name') close endif