diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index be1afbe..f3fc0be 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -101,9 +101,7 @@ endfunction "FUNCTION: nerdtree#closeTree() {{{2 "Closes the primary NERD tree window for this tab function! nerdtree#closeTree() - if !nerdtree#isTreeOpen() - throw "NERDTree.NoTreeFoundError: no NERDTree is open" - endif + call g:NERDTree.MustBeOpen() if winnr("$") != 1 if winnr() == g:NERDTree.GetWinNum() @@ -125,7 +123,7 @@ endfunction "FUNCTION: nerdtree#closeTreeIfOpen() {{{2 "Closes the NERD tree window if it is open function! nerdtree#closeTreeIfOpen() - if nerdtree#isTreeOpen() + if g:NERDTree.IsOpen() call nerdtree#closeTree() endif endfunction @@ -133,7 +131,7 @@ endfunction "FUNCTION: nerdtree#closeTreeIfQuitOnOpen() {{{2 "Closes the NERD tree window if the close on open option is set function! nerdtree#closeTreeIfQuitOnOpen() - if g:NERDTreeQuitOnOpen && nerdtree#isTreeOpen() + if g:NERDTreeQuitOnOpen && g:NERDTree.IsOpen() call nerdtree#closeTree() endif endfunction @@ -275,11 +273,6 @@ function! nerdtree#echoWarning(msg) echohl normal endfunction -"FUNCTION: nerdtree#isTreeOpen() {{{2 -function! nerdtree#isTreeOpen() - return g:NERDTree.GetWinNum() != -1 -endfunction - "FUNCTION: nerdtree#putCursorOnBookmarkTable(){{{2 "Places the cursor at the top of the bookmarks table function! nerdtree#putCursorOnBookmarkTable() @@ -306,10 +299,7 @@ endfunction "FUNCTION: nerdtree#putCursorInTreeWin(){{{2 "Places the cursor in the nerd tree window function! nerdtree#putCursorInTreeWin() - if !nerdtree#isTreeOpen() - throw "NERDTree.InvalidOperationError: cant put cursor in NERD tree window, no window exists" - endif - + call g:NERDTree.MustBeOpen() call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w") endfunction diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index a86011c..3b9784a 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -275,7 +275,7 @@ function! s:findAndRevealPath() endif else if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path) - if !nerdtree#isTreeOpen() + if !g:NERDTree.IsOpen() call g:NERDTreeCreator.TogglePrimary('') else call nerdtree#putCursorInTreeWin() @@ -283,7 +283,7 @@ function! s:findAndRevealPath() let b:NERDTreeShowHidden = g:NERDTreeShowHidden call s:chRoot(g:NERDTreeDirNode.New(p.getParent())) else - if !nerdtree#isTreeOpen() + if !g:NERDTree.IsOpen() call g:NERDTreeCreator.TogglePrimary("") endif endif diff --git a/lib/nerdtree/creator.vim b/lib/nerdtree/creator.vim index 0697759..efa9846 100644 --- a/lib/nerdtree/creator.vim +++ b/lib/nerdtree/creator.vim @@ -55,7 +55,7 @@ function! s:Creator.createPrimary(name) endif if g:NERDTree.ExistsForTab() - if nerdtree#isTreeOpen() + if g:NERDTree.IsOpen() call nerdtree#closeTree() endif unlet t:NERDTreeBufName @@ -168,7 +168,7 @@ function! s:Creator.createMirror() return endif - if g:NERDTree.ExistsForTab() && nerdtree#isTreeOpen() + if g:NERDTree.ExistsForTab() && g:NERDTree.IsOpen() call nerdtree#closeTree() endif @@ -333,7 +333,7 @@ endfunction "initialized. function! s:Creator.togglePrimary(dir) if g:NERDTree.ExistsForTab() - if !nerdtree#isTreeOpen() + if !g:NERDTree.IsOpen() call self._createTreeWin() if !&hidden call b:NERDTree.render() diff --git a/lib/nerdtree/nerdtree.vim b/lib/nerdtree/nerdtree.vim index 91ccc53..29a5930 100644 --- a/lib/nerdtree/nerdtree.vim +++ b/lib/nerdtree/nerdtree.vim @@ -33,6 +33,19 @@ function! s:NERDTree.GetWinNum() endif endfunction +"FUNCTION: s:NERDTree.IsOpen() {{{1 +function! s:NERDTree.IsOpen() + return s:NERDTree.GetWinNum() != -1 +endfunction + +"FUNCTION: s:NERDTree.MustBeOpen() {{{1 +function! s:NERDTree.MustBeOpen() + if !s:NERDTree.IsOpen() + throw "NERDTree.TreeNotOpen" + endif +endfunction + +"FUNCTION: s:NERDTree.New() {{{1 function! s:NERDTree.New(path) let newObj = copy(self) let newObj.ui = g:NERDTreeUI.New(newObj) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 28fd3ad..8038668 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -185,7 +185,7 @@ function! NERDTreeRender() endfunction function! NERDTreeFocus() - if nerdtree#isTreeOpen() + if g:NERDTree.IsOpen() call nerdtree#putCursorInTreeWin() else call g:NERDTreeCreator.TogglePrimary("")