Add options to facilitate linting only in normal mode (#425)

* [#420] Add options to facilitate linting only in normal mode

ale_lint_on_text_changed:
Allow setting to 'insert' or 'normal' to lint when text is changed only in
insert or normal mode respectively.

ale_lint_on_insert_leave:
This flag can be set to 1 to enable linting when leaving insert mode.

* [#420] Test updated global options

Ale should
- bind to TextChanged events when g:ale_lint_on_text_changed = 1
- bind to TextChanged events when g:ale_lint_on_text_changed = 'always'
- bind to InsertLeave event when g:ale_lint_on_insert_leave = 1
This commit is contained in:
taylorskalyo
2017-03-30 18:21:37 -04:00
committed by w0rp
parent 3a74d242f9
commit 36f9631512
5 changed files with 113 additions and 18 deletions

View File

@@ -69,8 +69,13 @@ let g:ale_linter_aliases = get(g:, 'ale_linter_aliases', {})
" jobs for linting until enough time has passed after editing is done.
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)
" This flag can be set to 'never' to disable linting when text is changed.
" This flag can also be set to 'insert' or 'normal' to lint when text is
" changed only in insert or normal mode respectively.
let g:ale_lint_on_text_changed = get(g:, 'ale_lint_on_text_changed', 'always')
" This flag can be set to 1 to enable linting when leaving insert mode.
let g:ale_lint_on_insert_leave = get(g:, 'ale_lint_on_insert_leave', 0)
" 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)
@@ -149,11 +154,17 @@ let g:ale_history_enabled = get(g:, 'ale_history_enabled', 1)
" A flag for storing the full output of commands in the history.
let g:ale_history_log_output = get(g:, 'ale_history_log_output', 0)
function! s:ALEInitAuGroups() abort
function! 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)
if g:ale_enabled
if g:ale_lint_on_text_changed ==? 'always' || g:ale_lint_on_text_changed == 1
autocmd TextChanged,TextChangedI * call ale#Queue(g:ale_lint_delay)
elseif g:ale_lint_on_text_changed ==? 'normal'
autocmd TextChanged * call ale#Queue(g:ale_lint_delay)
elseif g:ale_lint_on_text_changed ==? 'insert'
autocmd TextChangedI * call ale#Queue(g:ale_lint_delay)
endif
endif
augroup END
@@ -178,6 +189,13 @@ function! s:ALEInitAuGroups() abort
endif
augroup END
augroup ALERunOnInsertLeave
autocmd!
if g:ale_enabled && g:ale_lint_on_insert_leave
autocmd InsertLeave * call ale#Queue(0, 'lint_file')
endif
augroup END
augroup ALECursorGroup
autocmd!
if g:ale_enabled && g:ale_echo_cursor
@@ -193,6 +211,7 @@ function! s:ALEInitAuGroups() abort
augroup! ALERunOnTextChangedGroup
augroup! ALERunOnEnterGroup
augroup! ALERunOnSaveGroup
augroup! ALERunOnInsertLeave
augroup! ALECursorGroup
endif
endfunction
@@ -219,10 +238,10 @@ function! s:ALEToggle() abort
endif
endif
call s:ALEInitAuGroups()
call ALEInitAuGroups()
endfunction
call s:ALEInitAuGroups()
call ALEInitAuGroups()
" Define commands for moving through warnings and errors.
command! -bar ALEPrevious :call ale#loclist_jumping#Jump('before', 0)