Check for error; remove code duplication

This commit is contained in:
Jason Franklin 2018-09-10 08:46:42 -04:00
parent 7c8c811f00
commit 7e00a9971e
2 changed files with 10 additions and 12 deletions

View File

@ -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

View File

@ -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)