From e67ef112c8782d006d687f90465ff9610d3c999b Mon Sep 17 00:00:00 2001 From: Gilad Peleg Date: Sun, 9 Apr 2017 08:37:20 +0300 Subject: [PATCH 1/2] Join autocommands and simplify augroup Node --- plugin/node.vim | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/plugin/node.vim b/plugin/node.vim index a541292..c57ab37 100644 --- a/plugin/node.vim +++ b/plugin/node.vim @@ -1,8 +1,7 @@ if exists("g:loaded_node") || &cp || v:version < 700 | finish | endif let g:loaded_node = 1 -let s:filetypes = ["javascript", "json", "jsx"] -if exists("g:node_filetypes") | let s:filetypes = g:node_filetypes | endif +let s:filetypes = get(g:, 'node_filetypes', ["javascript", "json", "jsx"]) function! s:detect(dir) if exists("b:node_root") | return | endif @@ -20,28 +19,15 @@ function! s:detect(dir) endwhile endfunction -function! s:permutate(ft) - " Don't know right now how to detect javascript.jsx and other permutations - " without precomputing them in advance. Please let me know if you do. - return [a:ft, a:ft . ".*", "*." . a:ft, "*." . a:ft . ".*"] -endfunction - -function! s:flatten(list) - let values = [] - for value in a:list - if type(value) == type([]) | call extend(values, value) - else | add(values, value) - endif - endfor - return values -endfunction - augroup Node au! au VimEnter * if empty(expand("")) | call s:detect(getcwd()) | endif au BufRead,BufNewFile * call s:detect(expand(":p")) - let s:filetype_patterns = s:flatten(map(s:filetypes, "permutate(v:val)")) - let s:filetype_patterns_joined = join(s:filetype_patterns, ",") - execute "au FileType " s:filetype_patterns_joined " call node#javascript()" + let s:joined_filetypes = join(s:filetypes, ',') + " Match multiple patterns of filetypes + execute "au FileType {" s:joined_filetypes "} call node#javascript()" + execute "au FileType *.{" s:joined_filetypes "} call node#javascript()" + execute "au FileType {" s:joined_filetypes "}.* call node#javascript()" + execute "au FileType *.{" s:joined_filetypes "}.* call node#javascript()" augroup end From a2a05be400e07e3c2221f1226717a026cdac1b67 Mon Sep 17 00:00:00 2001 From: Gilad Peleg Date: Sun, 9 Apr 2017 09:24:07 +0300 Subject: [PATCH 2/2] Concat braces --- plugin/node.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/node.vim b/plugin/node.vim index c57ab37..e6ca77b 100644 --- a/plugin/node.vim +++ b/plugin/node.vim @@ -26,8 +26,8 @@ augroup Node let s:joined_filetypes = join(s:filetypes, ',') " Match multiple patterns of filetypes - execute "au FileType {" s:joined_filetypes "} call node#javascript()" - execute "au FileType *.{" s:joined_filetypes "} call node#javascript()" - execute "au FileType {" s:joined_filetypes "}.* call node#javascript()" - execute "au FileType *.{" s:joined_filetypes "}.* call node#javascript()" + execute "au FileType {" . s:joined_filetypes . "} call node#javascript()" + execute "au FileType *.{" . s:joined_filetypes . "} call node#javascript()" + execute "au FileType {" . s:joined_filetypes . "}.* call node#javascript()" + execute "au FileType *.{" . s:joined_filetypes . "}.* call node#javascript()" augroup end