From c2dd750860288b8cf81f6bd5ff49dc5ee76a34d5 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Thu, 17 Jul 2014 20:27:21 +0100 Subject: [PATCH] move nerdtree#treeExists.* methods into the NERDTree class --- autoload/nerdtree.vim | 12 ------------ autoload/nerdtree/ui_glue.vim | 2 +- lib/nerdtree/creator.vim | 6 +++--- lib/nerdtree/key_map.vim | 2 +- lib/nerdtree/nerdtree.vim | 18 +++++++++++++++++- lib/nerdtree/tree_file_node.vim | 4 ++-- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index 7f588b8..539e783 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -95,18 +95,6 @@ function! nerdtree#runningWindows() return has("win16") || has("win32") || has("win64") endfunction -" Function: nerdtree#treeExistsForBuffer() {{{2 -" Returns 1 if a nerd tree root exists in the current buffer -function! nerdtree#treeExistsForBuf() - return exists("b:NERDTreeRoot") -endfunction - -" Function: nerdtree#treeExistsForTab() {{{2 -" Returns 1 if a nerd tree root exists in the current tab -function! nerdtree#treeExistsForTab() - return exists("t:NERDTreeBufName") -endfunction - "FUNCTION: nerdtree#treeMarkupReg(dir) {{{2 function! nerdtree#treeMarkupReg() if g:NERDTreeDirArrows diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index a5fdb16..8607389 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -260,7 +260,7 @@ function! s:findAndRevealPath() let g:NERDTreeShowHidden = 1 endif - if !nerdtree#treeExistsForTab() + if !g:NERDTree.ExistsForTab() try let cwd = g:NERDTreePath.New(getcwd()) catch /^NERDTree.InvalidArgumentsError/ diff --git a/lib/nerdtree/creator.vim b/lib/nerdtree/creator.vim index 3791599..86f951a 100644 --- a/lib/nerdtree/creator.vim +++ b/lib/nerdtree/creator.vim @@ -49,7 +49,7 @@ function! s:Creator.createPrimary(name) call path.changeToDir() endif - if nerdtree#treeExistsForTab() + if g:NERDTree.ExistsForTab() if nerdtree#isTreeOpen() call nerdtree#closeTree() endif @@ -163,7 +163,7 @@ function! s:Creator.createMirror() return endif - if nerdtree#treeExistsForTab() && nerdtree#isTreeOpen() + if g:NERDTree.ExistsForTab() && nerdtree#isTreeOpen() call nerdtree#closeTree() endif @@ -327,7 +327,7 @@ endfunction "dir: the full path for the root node (is only used if the NERD tree is being "initialized. function! s:Creator.togglePrimary(dir) - if nerdtree#treeExistsForTab() + if g:NERDTree.ExistsForTab() if !nerdtree#isTreeOpen() call self._createTreeWin() if !&hidden diff --git a/lib/nerdtree/key_map.vim b/lib/nerdtree/key_map.vim index 07311ef..2411406 100644 --- a/lib/nerdtree/key_map.vim +++ b/lib/nerdtree/key_map.vim @@ -85,7 +85,7 @@ function! s:KeyMap.Invoke(key) "is in first " "TODO: remove this check when the vim bug is fixed - if !nerdtree#treeExistsForBuf() + if !g:NERDTree.ExistsForBuf() return {} endif diff --git a/lib/nerdtree/nerdtree.vim b/lib/nerdtree/nerdtree.vim index 84ffd3e..a41490b 100644 --- a/lib/nerdtree/nerdtree.vim +++ b/lib/nerdtree/nerdtree.vim @@ -3,8 +3,24 @@ let s:NERDTree = {} let g:NERDTree = s:NERDTree +" Function: s:NERDTree.ExistsForBuffer() {{{1 +" Returns 1 if a nerd tree root exists in the current buffer +function! s:NERDTree.ExistsForBuf() + return exists("b:NERDTreeRoot") +endfunction + +" Function: s:NERDTree.ExistsForTab() {{{1 +" Returns 1 if a nerd tree root exists in the current tab +function! s:NERDTree.ExistsForTab() + return exists("t:NERDTreeBufName") +endfunction + function! s:NERDTree.ForCurrentBuf() - return b:NERDTree + if s:NERDTree.ExistsForBuf() + return b:NERDTree + else + return {} + endif endfunction function! s:NERDTree.New(path) diff --git a/lib/nerdtree/tree_file_node.vim b/lib/nerdtree/tree_file_node.vim index c450a52..b4924d7 100644 --- a/lib/nerdtree/tree_file_node.vim +++ b/lib/nerdtree/tree_file_node.vim @@ -181,7 +181,7 @@ endfunction "FUNCTION: TreeFileNode.GetRootForTab(){{{1 "get the root node for this tab function! s:TreeFileNode.GetRootForTab() - if nerdtree#treeExistsForTab() + if g:NERDTree.ExistsForTab() return getbufvar(t:NERDTreeBufName, 'NERDTreeRoot') end return {} @@ -211,7 +211,7 @@ endfunction "FUNCTION: TreeFileNode.isRoot() {{{1 "returns 1 if this node is b:NERDTreeRoot function! s:TreeFileNode.isRoot() - if !nerdtree#treeExistsForBuf() + if !g:NERDTree.ExistsForBuf() throw "NERDTree.NoTreeError: No tree exists for the current buffer" endif