diff options
-rw-r--r-- | autoload/ale/engine.vim | 22 | ||||
-rw-r--r-- | autoload/ale/statusline.vim | 4 | ||||
-rw-r--r-- | plugin/ale.vim | 81 |
3 files changed, 74 insertions, 33 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 55633ae0..34e5ad95 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -166,24 +166,28 @@ function! s:HandleExit(job) abort let g:ale_buffer_info[l:buffer].loclist = g:ale_buffer_info[l:buffer].new_loclist let g:ale_buffer_info[l:buffer].new_loclist = [] + call ale#engine#SetResults(l:buffer, g:ale_buffer_info[l:buffer].loclist) + + " Call user autocommands. This allows users to hook into ALE's lint cycle. + silent doautocmd User ALELint + + " Mark line 200, column 17 with a squiggly line or something + " matchadd('ALEError', '\%200l\%17v') +endfunction + +function! ale#engine#SetResults(buffer, loclist) abort if g:ale_set_quickfix || g:ale_set_loclist - call ale#list#SetLists(g:ale_buffer_info[l:buffer].loclist) + call ale#list#SetLists(a:loclist) endif if g:ale_set_signs - call ale#sign#SetSigns(l:buffer, g:ale_buffer_info[l:buffer].loclist) + call ale#sign#SetSigns(a:buffer, a:loclist) endif if exists('*ale#statusline#Update') " Don't load/run if not already loaded. - call ale#statusline#Update(l:buffer, g:ale_buffer_info[l:buffer].loclist) + call ale#statusline#Update(a:buffer, a:loclist) endif - - " Call user autocommands. This allows users to hook into ALE's lint cycle. - silent doautocmd User ALELint - - " Mark line 200, column 17 with a squiggly line or something - " matchadd('ALEError', '\%200l\%17v') endfunction function! s:HandleExitNeoVim(job, data, event) abort diff --git a/autoload/ale/statusline.vim b/autoload/ale/statusline.vim index c01dd34d..7269ddca 100644 --- a/autoload/ale/statusline.vim +++ b/autoload/ale/statusline.vim @@ -3,6 +3,10 @@ " Update the buffer error/warning count with data from loclist. function! ale#statusline#Update(buffer, loclist) abort + if !has_key(g:ale_buffer_info, a:buffer) + return + endif + let l:errors = 0 let l:warnings = 0 diff --git a/plugin/ale.vim b/plugin/ale.vim index 5c319870..780d37e0 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -49,30 +49,16 @@ let g:ale_lint_delay = get(g:, 'ale_lint_delay', 200) " This flag can be set to 0 to disable linting when text is changed. let g:ale_lint_on_text_changed = get(g:, 'ale_lint_on_text_changed', 1) -if g:ale_lint_on_text_changed - augroup ALERunOnTextChangedGroup - autocmd! - autocmd TextChanged,TextChangedI * call ale#Queue(g:ale_lint_delay) - augroup END -endif " This flag can be set to 0 to disable linting when the buffer is entered. let g:ale_lint_on_enter = get(g:, 'ale_lint_on_enter', 1) -if g:ale_lint_on_enter - augroup ALERunOnEnterGroup - autocmd! - autocmd BufEnter,BufRead * call ale#Queue(300) - augroup END -endif " This flag can be set to 1 to enable linting when a buffer is written. let g:ale_lint_on_save = get(g:, 'ale_lint_on_save', 0) -if g:ale_lint_on_save - augroup ALERunOnSaveGroup - autocmd! - autocmd BufWrite * call ale#Queue(0) - augroup END -endif + +" This flag may be set to 0 to disable ale. After ale is loaded, :ALEToggle +" should be used instead. +let g:ale_enabled = get(g:, 'ale_enabled', 1) " These flags dictates if ale uses the quickfix or the loclist (loclist is the " default, quickfix overrides loclist). @@ -112,12 +98,6 @@ let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning') " This flag can be set to 0 to disable echoing when the cursor moves. let g:ale_echo_cursor = get(g:, 'ale_echo_cursor', 1) -if g:ale_echo_cursor - augroup ALECursorGroup - autocmd! - autocmd CursorMoved,CursorHold * call ale#cursor#EchoCursorWarningWithDelay() - augroup END -endif " String format for statusline " Its a list where: @@ -132,12 +112,64 @@ let g:ale_statusline_format = get(g:, 'ale_statusline_format', let g:ale_warn_about_trailing_whitespace = \ get(g:, 'ale_warn_about_trailing_whitespace', 1) +function! s:ALEInitAuGroups() abort + augroup ALERunOnTextChangedGroup + autocmd! + if g:ale_enabled && g:ale_lint_on_text_changed + autocmd TextChanged,TextChangedI * call ale#Queue(g:ale_lint_delay) + endif + augroup END + + augroup ALERunOnEnterGroup + autocmd! + if g:ale_enabled && g:ale_lint_on_enter + autocmd BufEnter,BufRead * call ale#Queue(300) + endif + augroup END + + augroup ALERunOnSaveGroup + autocmd! + if g:ale_enabled && g:ale_lint_on_save + autocmd BufWrite * call ale#Queue(0) + endif + augroup END + + augroup ALECursorGroup + autocmd! + if g:ale_enabled && g:ale_echo_cursor + autocmd CursorMoved,CursorHold * call ale#cursor#EchoCursorWarningWithDelay() + endif + augroup END +endfunction + +function! s:ALEToggle() abort + let g:ale_enabled = !get(g:, 'ale_enabled') + + if g:ale_enabled + " Lint immediately + call ale#Queue(0) + else + for l:buffer in keys(g:ale_buffer_info) + " Stop jobs and delete stored buffer data + call ale#cleanup#Buffer(l:buffer) + " Clear signs, loclist, quicklist + call ale#engine#SetResults(l:buffer, []) + endfor + endif + + call s:ALEInitAuGroups() +endfunction + +call s:ALEInitAuGroups() + " Define commands for moving through warnings and errors. command! ALEPrevious :call ale#loclist_jumping#Jump('before', 0) command! ALEPreviousWrap :call ale#loclist_jumping#Jump('before', 1) command! ALENext :call ale#loclist_jumping#Jump('after', 0) command! ALENextWrap :call ale#loclist_jumping#Jump('after', 1) +command! ALEToggle :call s:ALEToggle() + " Define command to get information about current filetype. command! ALEInfo :call ale#linter#Info() @@ -146,6 +178,7 @@ nnoremap <silent> <Plug>(ale_previous) :ALEPrevious<Return> nnoremap <silent> <Plug>(ale_previous_wrap) :ALEPreviousWrap<Return> nnoremap <silent> <Plug>(ale_next) :ALENext<Return> nnoremap <silent> <Plug>(ale_next_wrap) :ALENextWrap<Return> +nnoremap <silent> <Plug>(ale_toggle) :ALEToggle<Return> " Housekeeping |