From 9243367ba376050621e4c05e8f0439742c1f0f82 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Thu, 10 Sep 2020 15:40:27 +0200 Subject: Automatically detect script filetype when typing --- ftdetect/polyglot.vim | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'ftdetect') diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 5a95caa1..0fa71e9c 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -1911,12 +1911,11 @@ endif " end filetypes -augroup END - au BufNewFile,BufRead,StdinReadPost * \ if !did_filetype() && expand("") !~ g:ft_ignore_pat \ | call polyglot#Heuristics() | endif +augroup END if !has_key(s:disabled_packages, 'autoindent') " Code below re-implements sleuth for vim-polyglot @@ -2088,10 +2087,10 @@ if !has_key(s:disabled_packages, 'autoindent') endif endfunction - augroup polyglot - autocmd! - autocmd FileType * call s:detect_indent() - autocmd User Flags call Hoist('buffer', 5, 'SleuthIndicator') + augroup polyglot-sleuth + au! + au FileType * call s:detect_indent() + au User Flags call Hoist('buffer', 5, 'SleuthIndicator') augroup END command! -bar -bang Sleuth call s:detect_indent() @@ -2109,7 +2108,17 @@ func! s:verify() endif endfunc -autocmd VimEnter * call s:verify() +au VimEnter * call s:verify() + +func! s:observe_filetype() + augroup polyglot-observer + au! CursorHold,CursorHoldI + \ if polyglot#Heuristics() | au! polyglot-observer CursorHold,CursorHoldI | endif + augroup END +endfunc + +au BufEnter * if &ft == "" && expand("") !~ g:ft_ignore_pat + \ | call s:observe_filetype() | endif " restore Vi compatibility settings let &cpo = s:cpo_save -- cgit v1.2.3