From a444c62066ccdced9524ccc08f431e0438bc58d0 Mon Sep 17 00:00:00 2001 From: Techlive Zheng Date: Sat, 10 Nov 2012 04:17:27 +0800 Subject: [PATCH] Quit if no more normal window exists There might be other plugin windows but no normal file window open, we need to make sure tagbar window is closed at this situation. --- autoload/tagbar.vim | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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)