diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index ca241a5..4147798 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -3359,7 +3359,7 @@ endfunction " s:QuitIfOnlyWindow() {{{2 function! s:QuitIfOnlyWindow() abort " Check if there is more than window - if winbufnr(2) == -1 + if s:NextNormalWindow() == -1 " Check if there is more than one tab page if tabpagenr('$') == 1 " Before quitting Vim, delete the tagbar buffer so that @@ -3372,6 +3372,41 @@ function! s:QuitIfOnlyWindow() abort endif endfunction +" s:NextNormalWindow() {{{2 +fun! s:NextNormalWindow() + let l:i = 1 + while(l:i <= winnr('$')) + let l:buf = winbufnr(l:i) + + " skip unlisted buffers + if buflisted(l:buf) == 0 + let l:i = l:i + 1 + continue + endif + + " skip un-modifiable buffers + if getbufvar(l:buf, '&modifiable') != 1 + let l:i = l:i + 1 + continue + endif + + " skip temporary buffers with buftype set + if empty(getbufvar(l:buf, "&buftype")) != 1 + let l:i = l:i + 1 + continue + endif + + " skip current normal window + if l:i == winnr() + let l:i = l:i + 1 + continue + endif + + return l:i + endwhile + return -1 +endfun + " s:winexec() {{{2 function! s:winexec(cmd) abort call s:LogDebugMessage("Executing without autocommands: " . a:cmd)