@@ -12,36 +12,16 @@ function! s:detect(dir)
1212 let is_node = 0
1313 let is_node = is_node || filereadable (dir . " /package.json" )
1414 let is_node = is_node || isdirectory (dir . " /node_modules" )
15- if is_node | return node#initialize (dir ) | endif
15+ if is_node | call node#javascript () | return node#initialize (dir ) | endif
1616
1717 let parent = fnamemodify (dir , " :h" )
1818 if parent == dir | return | endif
1919 let dir = parent
2020 endwhile
2121endfunction
2222
23- function ! s: permutate (ft )
24- " Don't know right now how to detect javascript.jsx and other permutations
25- " without precomputing them in advance. Please let me know if you do.
26- return [a: ft , a: ft . " .*" , " *." . a: ft , " *." . a: ft . " .*" ]
27- endfunction
28-
29- function ! s: flatten (list )
30- let values = []
31- for value in a: list
32- if type (value) == type ([]) | call extend (values , value)
33- else | add (values , value)
34- endif
35- endfor
36- return values
37- endfunction
38-
3923augroup Node
4024 au !
41- au VimEnter * if empty (expand (" <amatch>" )) | call s: detect (getcwd ()) | endif
42- au BufRead ,BufNewFile * call s: detect (expand (" <amatch>:p" ))
43-
44- let s: filetype_patterns = s: flatten (map (s: filetypes , " <SID>permutate(v:val)" ))
45- let s: filetype_patterns_joined = join (s: filetype_patterns , " ," )
46- execute " au FileType " s: filetype_patterns_joined " call node#javascript()"
25+ let s: filetype_patterns_joined = join (s: filetypes , " ," )
26+ execute " au FileType " s: filetype_patterns_joined ' call <SID>detect(expand("\<afile>:p"))'
4727augroup end
0 commit comments