From a0de028688b4802de65c1b17963d7e5479035530 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Thu, 19 Nov 2015 23:44:39 +0000 Subject: [PATCH] wipeout "stale" nerdtree bufs When :NERDTree is called several times and &hidden is set, stale nerdtree bufs will exist. Wipe them out. --- lib/nerdtree/creator.vim | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/nerdtree/creator.vim b/lib/nerdtree/creator.vim index 61f204f..2141170 100644 --- a/lib/nerdtree/creator.vim +++ b/lib/nerdtree/creator.vim @@ -62,7 +62,8 @@ function! s:Creator.createTabTree(name) if g:NERDTree.IsOpen() call g:NERDTree.Close() endif - unlet t:NERDTreeBufName + + call self._removeTreeBufForTab() endif call self._createTreeWin() @@ -197,6 +198,15 @@ function! s:Creator._createTreeWin() call self._setCommonBufOptions() endfunction +"FUNCTION: s:Creator._isBufHidden(nr) {{{1 +function! s:Creator._isBufHidden(nr) + redir => bufs + ls! + redir END + + return bufs =~ a:nr . '..h' +endfunction + "FUNCTION: s:Creator.New() {{{1 function! s:Creator.New() let newCreator = copy(self) @@ -251,6 +261,23 @@ function! s:Creator._pathForString(str) return path endfunction +" Function: s:Creator._removeTreeBufForTab() {{{1 +function! s:Creator._removeTreeBufForTab() + let buf = bufnr(t:NERDTreeBufName) + + "if &hidden is not set then it will already be gone + if buf != -1 + + "nerdtree buf may be mirrored/displayed elsewhere + if self._isBufHidden(buf) + exec "bwipeout " . buf + endif + + endif + + unlet t:NERDTreeBufName +endfunction + "FUNCTION: s:Creator._setCommonBufOptions() {{{1 function! s:Creator._setCommonBufOptions() "throwaway buffer options