mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-10 04:23:51 -05:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9243367ba3 |
2
Makefile
2
Makefile
@@ -7,4 +7,4 @@ test:
|
|||||||
@ scripts/test
|
@ scripts/test
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
@ echo "packages.yaml\nheuristics.yaml\nscripts/test\nscripts/build\nscripts/test_extensions.vim" | DEV=1 entr bash -c 'make && make test'
|
@ (ls && find scripts) | DEV=1 entr bash -c 'make && make test'
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ set cpo&vim
|
|||||||
|
|
||||||
func! polyglot#Heuristics()
|
func! polyglot#Heuristics()
|
||||||
" Try to detect filetype from shebang
|
" Try to detect filetype from shebang
|
||||||
let l:filetype = polyglot#Shebang()
|
let filetype = polyglot#Shebang()
|
||||||
if l:filetype != ""
|
if filetype != ""
|
||||||
exec "setf " . l:filetype
|
exec "setf " . filetype
|
||||||
return
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
return 0
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let s:interpreters = {
|
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\+\)'
|
let s:r_env = '^\%(\' . s:r_envflag . '\s\+\)*\(\S\+\)'
|
||||||
|
|
||||||
func! polyglot#Shebang()
|
func! polyglot#Shebang()
|
||||||
let l:line1 = getline(1)
|
let line1 = getline(1)
|
||||||
|
|
||||||
if l:line1 !~# "^#!"
|
if line1 !~# "^#!"
|
||||||
return
|
return
|
||||||
endif
|
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
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let [_, l:path, l:rest; __] = l:pathrest
|
let [_, path, rest; __] = pathrest
|
||||||
|
|
||||||
let l:script = split(l:path, "/")[-1]
|
let script = split(path, "/")[-1]
|
||||||
|
|
||||||
if l:script == "env"
|
if len(script) == 0
|
||||||
let l:argspath = matchlist(l:rest, s:r_env)
|
|
||||||
if len(l:argspath) == 0
|
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l:script = l:argspath[1]
|
if script == "env"
|
||||||
|
let argspath = matchlist(rest, s:r_env)
|
||||||
|
if len(argspath) == 0
|
||||||
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if has_key(s:interpreters, l:script)
|
let script = argspath[1]
|
||||||
return s:interpreters[l:script]
|
endif
|
||||||
|
|
||||||
|
if has_key(s:interpreters, script)
|
||||||
|
return s:interpreters[script]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
for interpreter in keys(s:interpreters)
|
for interpreter in keys(s:interpreters)
|
||||||
if l:script =~# '^' . interpreter
|
if script =~# '^' . interpreter
|
||||||
return s:interpreters[interpreter]
|
return s:interpreters[interpreter]
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|||||||
@@ -1911,12 +1911,11 @@ endif
|
|||||||
|
|
||||||
" end filetypes
|
" end filetypes
|
||||||
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
au BufNewFile,BufRead,StdinReadPost *
|
au BufNewFile,BufRead,StdinReadPost *
|
||||||
\ if !did_filetype() && expand("<afile>") !~ g:ft_ignore_pat
|
\ if !did_filetype() && expand("<afile>") !~ g:ft_ignore_pat
|
||||||
\ | call polyglot#Heuristics() | endif
|
\ | call polyglot#Heuristics() | endif
|
||||||
|
|
||||||
|
augroup END
|
||||||
|
|
||||||
if !has_key(s:disabled_packages, 'autoindent')
|
if !has_key(s:disabled_packages, 'autoindent')
|
||||||
" Code below re-implements sleuth for vim-polyglot
|
" Code below re-implements sleuth for vim-polyglot
|
||||||
@@ -2088,10 +2087,10 @@ if !has_key(s:disabled_packages, 'autoindent')
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
augroup polyglot
|
augroup polyglot-sleuth
|
||||||
autocmd!
|
au!
|
||||||
autocmd FileType * call s:detect_indent()
|
au FileType * call s:detect_indent()
|
||||||
autocmd User Flags call Hoist('buffer', 5, 'SleuthIndicator')
|
au User Flags call Hoist('buffer', 5, 'SleuthIndicator')
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
command! -bar -bang Sleuth call s:detect_indent()
|
command! -bar -bang Sleuth call s:detect_indent()
|
||||||
@@ -2109,7 +2108,17 @@ func! s:verify()
|
|||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
autocmd VimEnter * call s:verify()
|
au VimEnter * call s:verify()
|
||||||
|
|
||||||
|
func! s:observe_filetype()
|
||||||
|
augroup polyglot-observer
|
||||||
|
au! CursorHold,CursorHoldI <buffer>
|
||||||
|
\ if polyglot#Heuristics() | au! polyglot-observer CursorHold,CursorHoldI | endif
|
||||||
|
augroup END
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
au BufEnter * if &ft == "" && expand("<afile>") !~ g:ft_ignore_pat
|
||||||
|
\ | call s:observe_filetype() | endif
|
||||||
|
|
||||||
" restore Vi compatibility settings
|
" restore Vi compatibility settings
|
||||||
let &cpo = s:cpo_save
|
let &cpo = s:cpo_save
|
||||||
|
|||||||
@@ -559,8 +559,10 @@ def generate_ftdetect(packages, heuristics)
|
|||||||
let l:filetype = polyglot#Shebang()
|
let l:filetype = polyglot#Shebang()
|
||||||
if l:filetype != ""
|
if l:filetype != ""
|
||||||
exec "setf " . l:filetype
|
exec "setf " . l:filetype
|
||||||
return
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
return 0
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let s:interpreters = {
|
let s:interpreters = {
|
||||||
|
|||||||
Reference in New Issue
Block a user