diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index f3fc0be..bb422db 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -98,44 +98,6 @@ endfunction " SECTION: View Functions {{{1 "============================================================ -"FUNCTION: nerdtree#closeTree() {{{2 -"Closes the primary NERD tree window for this tab -function! nerdtree#closeTree() - call g:NERDTree.MustBeOpen() - - if winnr("$") != 1 - if winnr() == g:NERDTree.GetWinNum() - call nerdtree#exec("wincmd p") - let bufnr = bufnr("") - call nerdtree#exec("wincmd p") - else - let bufnr = bufnr("") - endif - - call nerdtree#exec(g:NERDTree.GetWinNum() . " wincmd w") - close - call nerdtree#exec(bufwinnr(bufnr) . " wincmd w") - else - close - endif -endfunction - -"FUNCTION: nerdtree#closeTreeIfOpen() {{{2 -"Closes the NERD tree window if it is open -function! nerdtree#closeTreeIfOpen() - if g:NERDTree.IsOpen() - call nerdtree#closeTree() - endif -endfunction - -"FUNCTION: nerdtree#closeTreeIfQuitOnOpen() {{{2 -"Closes the NERD tree window if the close on open option is set -function! nerdtree#closeTreeIfQuitOnOpen() - if g:NERDTreeQuitOnOpen && g:NERDTree.IsOpen() - call nerdtree#closeTree() - endif -endfunction - "FUNCTION: nerdtree#dumpHelp {{{2 "prints out the quick help function! nerdtree#dumpHelp() diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 3b9784a..1dbfc50 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -212,7 +212,7 @@ function! s:closeTreeWindow() exec "buffer " . b:NERDTreePreviousBuf else if winnr("$") > 1 - call nerdtree#closeTree() + call g:NERDTree.Close() else call nerdtree#echo("Cannot close last window") endif @@ -547,7 +547,7 @@ endfunction function! nerdtree#ui_glue#setupCommands() command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.CreatePrimary('') command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.TogglePrimary('') - command! -n=0 -bar NERDTreeClose :call nerdtree#closeTreeIfOpen() + command! -n=0 -bar NERDTreeClose :call g:NERDTree.Close() command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreatePrimary('') command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror() command! -n=0 -bar NERDTreeFind call s:findAndRevealPath() diff --git a/lib/nerdtree/creator.vim b/lib/nerdtree/creator.vim index efa9846..2d6a5c2 100644 --- a/lib/nerdtree/creator.vim +++ b/lib/nerdtree/creator.vim @@ -56,7 +56,7 @@ function! s:Creator.createPrimary(name) if g:NERDTree.ExistsForTab() if g:NERDTree.IsOpen() - call nerdtree#closeTree() + call g:NERDTree.Close() endif unlet t:NERDTreeBufName endif @@ -169,7 +169,7 @@ function! s:Creator.createMirror() endif if g:NERDTree.ExistsForTab() && g:NERDTree.IsOpen() - call nerdtree#closeTree() + call g:NERDTree.Close() endif let t:NERDTreeBufName = bufferName @@ -340,7 +340,7 @@ function! s:Creator.togglePrimary(dir) endif call b:NERDTree.ui.restoreScreenState() else - call nerdtree#closeTree() + call g:NERDTree.Close() endif else call self.createPrimary(a:dir) diff --git a/lib/nerdtree/nerdtree.vim b/lib/nerdtree/nerdtree.vim index 29a5930..7fec67b 100644 --- a/lib/nerdtree/nerdtree.vim +++ b/lib/nerdtree/nerdtree.vim @@ -3,6 +3,38 @@ let s:NERDTree = {} let g:NERDTree = s:NERDTree +"FUNCTION: s:NERDTree.Close() {{{1 +"Closes the primary NERD tree window for this tab +function! s:NERDTree.Close() + if !s:NERDTree.IsOpen() + return + endif + + if winnr("$") != 1 + if winnr() == s:NERDTree.GetWinNum() + call nerdtree#exec("wincmd p") + let bufnr = bufnr("") + call nerdtree#exec("wincmd p") + else + let bufnr = bufnr("") + endif + + call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w") + close + call nerdtree#exec(bufwinnr(bufnr) . " wincmd w") + else + close + endif +endfunction + +"FUNCTION: s:NERDTree.CloseIfQuitOnOpen() {{{1 +"Closes the NERD tree window if the close on open option is set +function! s:NERDTree.CloseIfQuitOnOpen() + if g:NERDTreeQuitOnOpen && s:NERDTree.IsOpen() + call s:NERDTree.Close() + endif +endfunction + " Function: s:NERDTree.ExistsForBuffer() {{{1 " Returns 1 if a nerd tree root exists in the current buffer function! s:NERDTree.ExistsForBuf() @@ -59,4 +91,3 @@ endfunction function! s:NERDTree.render() call self.ui.render() endfunction - diff --git a/lib/nerdtree/opener.vim b/lib/nerdtree/opener.vim index 845e55c..6dea3b0 100644 --- a/lib/nerdtree/opener.vim +++ b/lib/nerdtree/opener.vim @@ -40,7 +40,7 @@ function! s:Opener._checkToCloseTree(newtab) endif if (a:newtab && self._where == 't') || !a:newtab - call nerdtree#closeTreeIfQuitOnOpen() + call g:NERDTree.CloseIfQuitOnOpen() endif endfunction