From 12960b966f7c7b19c56936856ce30942f655d58f Mon Sep 17 00:00:00 2001 From: zhenyangze Date: Sat, 9 Dec 2017 16:58:18 +0800 Subject: [PATCH 1/2] change NERDTreeFind with args --- autoload/nerdtree/ui_glue.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index dbc34e5..338f5e9 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -262,9 +262,15 @@ function! s:displayHelp() endfunction " FUNCTION: s:findAndRevealPath() {{{1 -function! s:findAndRevealPath() +function! s:findAndRevealPath(userPath) + if len(a:userPath) == 0 + let s:userPath = expand("%:p") + else + let s:userPath = a:userPath + endif + try - let p = g:NERDTreePath.New(expand("%:p")) + let p = g:NERDTreePath.New(s:userPath) catch /^NERDTree.InvalidArgumentsError/ call nerdtree#echo("no file for the current buffer") return @@ -587,7 +593,7 @@ function! nerdtree#ui_glue#setupCommands() command! -n=0 -bar NERDTreeClose :call g:NERDTree.Close() command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreateTabTree('') command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror() - command! -n=0 -bar NERDTreeFind call s:findAndRevealPath() + command! -n=? -complete=dir -bar NERDTreeFind call s:findAndRevealPath('') command! -n=0 -bar NERDTreeFocus call NERDTreeFocus() command! -n=0 -bar NERDTreeCWD call NERDTreeCWD() endfunction From 21297404190e4a273d1afa318df121a49add580a Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Sat, 9 Dec 2017 11:09:10 -0500 Subject: [PATCH 2/2] Add style improvements Function-local variables, instead of script-local variables, should be used here. In addition, "empty()" is a better choice for testing for the absence of an argument. Finally, the use of "else" is removed. The docstring is also updated to include the new argument. --- autoload/nerdtree/ui_glue.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 338f5e9..60cc5dd 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -261,16 +261,16 @@ function! s:displayHelp() call b:NERDTree.ui.centerView() endfunction -" FUNCTION: s:findAndRevealPath() {{{1 -function! s:findAndRevealPath(userPath) - if len(a:userPath) == 0 - let s:userPath = expand("%:p") - else - let s:userPath = a:userPath +" FUNCTION: s:findAndRevealPath(path) {{{1 +function! s:findAndRevealPath(path) + let l:path = a:path + + if empty(l:path) + let l:path = expand('%:p') endif try - let p = g:NERDTreePath.New(s:userPath) + let p = g:NERDTreePath.New(l:path) catch /^NERDTree.InvalidArgumentsError/ call nerdtree#echo("no file for the current buffer") return