From 01b011d38e2af0e11f03d34d80d4cfae497732da Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Fri, 22 Dec 2017 08:45:57 -0500 Subject: [PATCH] Have "finAndRevealPath()" fail on no file If a file does not exist for the current buffer, this function should fail with a clear warning message. Here, I improved the messages that this function prints so that it fails gracefully when no path can be determined in the calling context. --- autoload/nerdtree/ui_glue.vim | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 910ead3..e2dc96a 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -261,18 +261,19 @@ function! s:displayHelp() call b:NERDTree.ui.centerView() endfunction -" FUNCTION: s:findAndRevealPath(path) {{{1 -function! s:findAndRevealPath(path) - let l:path = a:path +" FUNCTION: s:findAndRevealPath(pathStr) {{{1 +function! s:findAndRevealPath(pathStr) + let l:pathStr = !empty(a:pathStr) ? a:pathStr : expand('%:p') - if empty(l:path) - let l:path = expand('%:p') + if empty(l:pathStr) + call nerdtree#echoWarning('no file for the current buffer') + return endif - + try - let l:pathObj = g:NERDTreePath.New(l:path) + let l:pathObj = g:NERDTreePath.New(l:pathStr) catch /^NERDTree.InvalidArgumentsError/ - call nerdtree#echo('no file for the current buffer') + call nerdtree#echoWarning('invalid path') return endtry