add ALEToggle command (#303)

* add ALEToggle command

* stop active jobs when toggled off

* small logic cleanup & ensure ale can be ran manually while toggled off
This commit is contained in:
Daniel Lupu 2017-02-09 20:47:14 +02:00 committed by w0rp
parent 943fe9b4b0
commit 6dfed8576e
3 changed files with 77 additions and 36 deletions

View File

@ -166,18 +166,7 @@ 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 = []
if g:ale_set_quickfix || g:ale_set_loclist
call ale#list#SetLists(g:ale_buffer_info[l:buffer].loclist)
endif
if g:ale_set_signs
call ale#sign#SetSigns(l:buffer, g:ale_buffer_info[l:buffer].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)
endif
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
@ -186,6 +175,21 @@ function! s:HandleExit(job) abort
" 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(a:loclist)
endif
if g:ale_set_signs
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(a:buffer, a:loclist)
endif
endfunction
function! s:HandleExitNeoVim(job, data, event) abort
call s:HandleExit(a:job)
endfunction

View File

@ -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

View File

@ -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