diff options
| author | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-10 15:40:27 +0200 | 
|---|---|---|
| committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-10 15:40:27 +0200 | 
| commit | 9243367ba376050621e4c05e8f0439742c1f0f82 (patch) | |
| tree | da72230c3a5258fe2be8c90ef0301ac1edd7d547 /autoload | |
| parent | 1eed30b2af57538496943da09e298a6facc33002 (diff) | |
| download | vim-polyglot-9243367ba376050621e4c05e8f0439742c1f0f82.tar.gz vim-polyglot-9243367ba376050621e4c05e8f0439742c1f0f82.zip | |
Automatically detect script filetype when typingv4.10.0
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/polyglot.vim | 40 | 
1 files changed, 23 insertions, 17 deletions
| diff --git a/autoload/polyglot.vim b/autoload/polyglot.vim index d54cb87e..d89108aa 100644 --- a/autoload/polyglot.vim +++ b/autoload/polyglot.vim @@ -4,11 +4,13 @@ set cpo&vim  func! polyglot#Heuristics()    " Try to detect filetype from shebang -  let l:filetype = polyglot#Shebang() -  if l:filetype != "" -    exec "setf " . l:filetype -    return +  let filetype = polyglot#Shebang() +  if filetype != "" +    exec "setf " . filetype +    return 1    endif + +  return 0  endfunc  let s:interpreters = { @@ -86,37 +88,41 @@ let s:r_envflag = '%(\S\+=\S\+\|-[iS]\|--ignore-environment\|--split-string\)'  let s:r_env = '^\%(\' . s:r_envflag . '\s\+\)*\(\S\+\)'  func! polyglot#Shebang() -  let l:line1 = getline(1) +  let line1 = getline(1) -  if l:line1 !~# "^#!" +  if line1 !~# "^#!"      return    endif -  let l:pathrest = matchlist(l:line1, s:r_hashbang) +  let pathrest = matchlist(line1, s:r_hashbang) -  if len(l:pathrest) == 0 +  if len(pathrest) == 0      return     endif -  let [_, l:path, l:rest; __] = l:pathrest +  let [_, path, rest; __] = pathrest + +  let script = split(path, "/")[-1] -  let l:script = split(l:path, "/")[-1] +  if len(script) == 0 +    return +  endif -  if l:script == "env" -    let l:argspath = matchlist(l:rest, s:r_env) -    if len(l:argspath) == 0 +  if script == "env" +    let argspath = matchlist(rest, s:r_env) +    if len(argspath) == 0        return      endif -    let l:script = l:argspath[1] +    let script = argspath[1]    endif -  if has_key(s:interpreters, l:script) -    return s:interpreters[l:script] +  if has_key(s:interpreters, script) +    return s:interpreters[script]    endif    for interpreter in keys(s:interpreters) -    if l:script =~# '^' . interpreter +    if script =~# '^' . interpreter        return s:interpreters[interpreter]      endif    endfor | 
