From adc2763e6b1404d1ec365a9e06410c20abf6cd0d Mon Sep 17 00:00:00 2001 From: pekepeke Date: Sat, 6 Dec 2014 17:12:00 +0900 Subject: [PATCH 1/2] compatible gf-user. --- autoload/node.vim | 50 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/autoload/node.vim b/autoload/node.vim index 287344c..ee88065 100644 --- a/autoload/node.vim +++ b/autoload/node.vim @@ -1,5 +1,12 @@ -let node#suffixesadd = [".js", ".json"] -let node#filetypes = ["javascript", "json"] +if !exists('g:node#suffixesadd') + let g:node#suffixesadd = [".js", ".json"] +endif +if !exists('g:node#filetypes') + let g:node#filetypes = ["javascript", "json"] +endif +if !exists('g:node#enable_gf_user') + let g:node#enable_gf_user = 0 +endif function! node#initialize(root) let b:node_root = a:root @@ -8,6 +15,14 @@ function! node#initialize(root) silent doautocmd User Node endfunction +function! node#gf#find() + let path = s:path(expand(''), bufname('%')) + if empty(path) + return 0 + endif + return path +endfunction + function! s:initializeCommands() command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nedit \ exe s:nedit(, bufname("%"), "edit") @@ -30,7 +45,7 @@ function! s:initializeJavaScript() let &l:include = '\NodeGotoFile") + if !g:node#enable_gf_user && !hasmapto("NodeGotoFile") " Split gotofiles don't take a count for the new window's width, but for " opening the nth file. Though Node.vim doesn't support counts atm. nmap gf NodeGotoFile @@ -42,15 +57,8 @@ endfunction function! s:edit(name, from, ...) if empty(a:name) | return | endif - let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h") let command = a:0 == 1 ? a:1 : "edit" - - " If just a plain filename with no directory part, check if it exists: - if a:name !~# '^\v(/|\./|\.\./)' && filereadable(dir . "/" . a:name) - let path = dir . "/" . a:name - else - let path = node#lib#find(a:name, dir) - end + let path = s:path(a:name, a:from) if empty(path) return s:error("E447: Can't find file \"" . a:name . "\" in path") @@ -85,6 +93,21 @@ function! s:complete(arg, cmd, cursor) return filter(matches, filter) endfunction +function! s:path(name, from) + if empty(a:name) | return | endif + let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h") + + " If just a plain filename with no directory part, check if it exists: + if a:name !~# '^\v(/|\./|\.\./)' && filereadable(dir . "/" . a:name) + let path = dir . "/" . a:name + else + let path = node#lib#find(a:name, dir) + end + + return path +endfunction + + function! s:dirname(path) let dirname = fnamemodify(a:path, ":h") if dirname == "." | return "" | endif @@ -102,3 +125,8 @@ function! s:error(msg) echohl NONE let v:errmsg = a:msg endfunction + +if g:node#enable_gf_user + " initialize gf-user + call gf#user#extend('node#gf#find', 1000) +endif From fd00a2fba5a9ff0980dff7649242940d5ef280fd Mon Sep 17 00:00:00 2001 From: pekepeke Date: Tue, 9 Dec 2014 10:39:20 +0900 Subject: [PATCH 2/2] fixes E746 --- autoload/node.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/node.vim b/autoload/node.vim index ee88065..38d3204 100644 --- a/autoload/node.vim +++ b/autoload/node.vim @@ -15,7 +15,7 @@ function! node#initialize(root) silent doautocmd User Node endfunction -function! node#gf#find() +function! node#gf_find() let path = s:path(expand(''), bufname('%')) if empty(path) return 0 @@ -128,5 +128,5 @@ endfunction if g:node#enable_gf_user " initialize gf-user - call gf#user#extend('node#gf#find', 1000) + call gf#user#extend('node#gf_find', 1000) endif