nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit 7e00a9971e16ccf88362ecf0d52fcd31c31582f2
parent 7c8c811f00f9e8f792a88a271f7f79ab0bdd7e85
Author: Jason Franklin <j_fra@fastmail.us>
Date:   Mon, 10 Sep 2018 08:46:42 -0400

Check for error; remove code duplication

Diffstat:
Mautoload/nerdtree/ui_glue.vim | 13++-----------
Mplugin/NERD_tree.vim | 9++++++++-
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim
@@ -142,18 +142,9 @@ function! s:chRoot(node)
 endfunction
 
 " FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1
-" changes the current root to CWD
+" Change the NERDTree root to match the current working directory.
 function! nerdtree#ui_glue#chRootCwd()
-    try
-        let cwd = g:NERDTreePath.New(getcwd())
-    catch /^NERDTree.InvalidArgumentsError/
-        call nerdtree#echo("current directory does not exist.")
-        return
-    endtry
-    if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str()
-       return
-    endif
-    call s:chRoot(g:NERDTreeDirNode.New(cwd, b:NERDTree))
+    NERDTreeCWD
 endfunction
 
 " FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1
diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim
@@ -202,7 +202,14 @@ function! NERDTreeFocus()
 endfunction
 
 function! NERDTreeCWD()
-    let l:cwdPath = g:NERDTreePath.New(getcwd())
+
+    try
+        let l:cwdPath = g:NERDTreePath.New(getcwd())
+    catch /^NERDTree.InvalidArgumentsError/
+        call nerdtree#echoWarning('current directory does not exist')
+        return
+    endtry
+
     call NERDTreeFocus()
 
     if b:NERDTree.root.path.equals(l:cwdPath)