Set up one BufEnter event used for everything, and add tests for linting when the filetype changes

This commit is contained in:
w0rp 2017-08-14 23:31:46 +01:00
parent 1680f7af63
commit 5af82312fb
6 changed files with 89 additions and 22 deletions

View file

@ -218,27 +218,26 @@ function! ALEInitAuGroups() abort
augroup ALERunOnEnterGroup
autocmd!
if g:ale_enabled
" Handle everything that needs to happen when buffers are entered.
autocmd BufEnter * call ale#events#EnterEvent(str2nr(expand('<abuf>')))
endif
if g:ale_enabled && g:ale_lint_on_enter
autocmd BufWinEnter,BufRead * call ale#Queue(0, 'lint_file', str2nr(expand('<abuf>')))
" Track when the file is changed outside of Vim.
autocmd FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand('<abuf>')))
" If the file has been changed, then check it again on enter.
autocmd BufEnter * call ale#events#EnterEvent(str2nr(expand('<abuf>')))
endif
augroup END
augroup ALERunOnFiletypeChangeGroup
autocmd!
if g:ale_enabled && g:ale_lint_on_filetype_changed
" Set the filetype after a buffer is opened or read.
autocmd BufEnter,BufRead * let b:ale_original_filetype = &filetype
" Only start linting if the FileType actually changes after
" opening a buffer. The FileType will fire when buffers are opened.
autocmd FileType *
\ if has_key(b:, 'ale_original_filetype')
\ && b:ale_original_filetype isnot# expand('<amatch>')
\| call ale#Queue(300, 'lint_file')
\| endif
autocmd FileType * call ale#events#FileTypeEvent(
\ str2nr(expand('<abuf>')),
\ expand('<amatch>')
\)
endif
augroup END