nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit c2dd750860288b8cf81f6bd5ff49dc5ee76a34d5
parent fd14757c04f894919e014629fcec91de3c34892c
Author: Martin Grenfell <martin.grenfell@gmail.com>
Date:   Thu, 17 Jul 2014 20:27:21 +0100

move nerdtree#treeExists.* methods into the NERDTree class

Diffstat:
Mautoload/nerdtree.vim | 12------------
Mautoload/nerdtree/ui_glue.vim | 2+-
Mlib/nerdtree/creator.vim | 6+++---
Mlib/nerdtree/key_map.vim | 2+-
Mlib/nerdtree/nerdtree.vim | 18+++++++++++++++++-
Mlib/nerdtree/tree_file_node.vim | 4++--
6 files changed, 24 insertions(+), 20 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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