Skip to content

Commit 168768b

Browse files
committed
Lint on InsertLeave, not in insert mode by default
b:ale_lint_on_insert_leave is now supported as tests need it. These defaults are saner and cause fewer issues for users by default.
1 parent 8b46fa3 commit 168768b

7 files changed

+31
-18
lines changed

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,10 @@ while you type. ALE uses a timeout which is cancelled and reset every time you
722722
type, and this delay can be increased so linters are run less often. See
723723
`:help g:ale_lint_delay` for more information.
724724

725-
If you don't wish to run linters while you type, you can disable that
726-
behaviour. Set `g:ale_lint_on_text_changed` to `never` or `normal`. You won't
727-
get as frequent error checking, but ALE shouldn't block your ability to edit a
728-
document after you save a file, so the asynchronous nature of the plugin will
729-
still be an advantage.
725+
If you don't wish to run linters while you type, you can disable that behaviour.
726+
Set `g:ale_lint_on_text_changed` to `never`. You won't get as frequent error
727+
checking, but ALE shouldn't block your ability to edit a document after you save
728+
a file, so the asynchronous nature of the plugin will still be an advantage.
730729

731730
If you are still concerned, you can turn the automatic linting off altogether,
732731
including the option `g:ale_lint_on_enter`, and you can run ALE manually with

autoload/ale/events.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function! ale#events#Init() abort
128128
endif
129129

130130
if g:ale_lint_on_insert_leave
131-
autocmd InsertLeave * call ale#Queue(0)
131+
autocmd InsertLeave * if ale#Var(str2nr(expand('<abuf>')), 'lint_on_insert_leave') | call ale#Queue(0) | endif
132132
endif
133133

134134
if g:ale_echo_cursor || g:ale_cursor_detail

doc/ale.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ have even saved your changes. ALE will check your code in the following
8484
circumstances, which can be configured with the associated options.
8585

8686
* When you modify a buffer. - |g:ale_lint_on_text_changed|
87-
* On leaving insert mode. (off by default) - |g:ale_lint_on_insert_leave|
87+
* On leaving insert mode. - |g:ale_lint_on_insert_leave|
8888
* When you open a new or modified buffer. - |g:ale_lint_on_enter|
8989
* When you save a buffer. - |g:ale_lint_on_save|
9090
* When the filetype changes for a buffer. - |g:ale_lint_on_filetype_changed|
@@ -953,7 +953,7 @@ g:ale_lint_on_save *g:ale_lint_on_save*
953953
g:ale_lint_on_text_changed *g:ale_lint_on_text_changed*
954954

955955
Type: |String|
956-
Default: `'always'`
956+
Default: `'normal'`
957957

958958
This option controls how ALE will check your files as you make changes.
959959
The following values can be used.
@@ -978,6 +978,7 @@ g:ale_lint_on_text_changed *g:ale_lint_on_text_changed*
978978

979979

980980
g:ale_lint_on_insert_leave *g:ale_lint_on_insert_leave*
981+
*b:ale_lint_on_insert_leave*
981982

982983
Type: |Number|
983984
Default: `0`
@@ -992,6 +993,10 @@ g:ale_lint_on_insert_leave *g:ale_lint_on_insert_leave*
992993
" Make using Ctrl+C do the same as Escape, to trigger autocmd commands
993994
inoremap <C-c> <Esc>
994995
<
996+
A buffer-local version of this setting `b:ale_lint_on_insert_leave` can be
997+
set to `0` to disable linting when leaving insert mode. The setting must
998+
be enabled globally to be enabled locally.
999+
9951000
You should set this setting once before ALE is loaded, and restart Vim if
9961001
you want to change your preferences. See |ale-lint-settings-on-startup|.
9971002

plugin/ale.vim

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ let g:ale_linter_aliases = get(g:, 'ale_linter_aliases', {})
7171
let g:ale_lint_delay = get(g:, 'ale_lint_delay', 200)
7272

7373
" This flag can be set to 'never' to disable linting when text is changed.
74-
" This flag can also be set to 'insert' or 'normal' to lint when text is
75-
" changed only in insert or normal mode respectively.
76-
let g:ale_lint_on_text_changed = get(g:, 'ale_lint_on_text_changed', 'always')
74+
" This flag can also be set to 'always' or 'insert' to lint when text is
75+
" changed in both normal and insert mode, or only in insert mode respectively.
76+
let g:ale_lint_on_text_changed = get(g:, 'ale_lint_on_text_changed', 'normal')
7777

7878
" This flag can be set to 1 to enable linting when leaving insert mode.
79-
let g:ale_lint_on_insert_leave = get(g:, 'ale_lint_on_insert_leave', 0)
79+
let g:ale_lint_on_insert_leave = get(g:, 'ale_lint_on_insert_leave', 1)
8080

8181
" This flag can be set to 0 to disable linting when the buffer is entered.
8282
let g:ale_lint_on_enter = get(g:, 'ale_lint_on_enter', 1)

test/test_ale_info.vader

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Before:
3131
let g:ale_completion_enabled = 0
3232
let g:ale_completion_max_suggestions = 50
3333
let g:ale_history_log_output = 1
34-
let g:ale_lint_on_insert_leave = 0
35-
let g:ale_lint_on_text_changed = 'always'
34+
let g:ale_lint_on_insert_leave = 1
35+
let g:ale_lint_on_text_changed = 'normal'
3636
let g:ale_lsp_error_messages = {}
3737
let g:ale_maximum_file_size = 0
3838
let g:ale_pattern_options = {}
@@ -88,9 +88,9 @@ Before:
8888
\ 'let g:ale_lint_delay = 200',
8989
\ 'let g:ale_lint_on_enter = 1',
9090
\ 'let g:ale_lint_on_filetype_changed = 1',
91-
\ 'let g:ale_lint_on_insert_leave = 0',
91+
\ 'let g:ale_lint_on_insert_leave = 1',
9292
\ 'let g:ale_lint_on_save = 1',
93-
\ 'let g:ale_lint_on_text_changed = ''always''',
93+
\ 'let g:ale_lint_on_text_changed = ''normal''',
9494
\ 'let g:ale_linter_aliases = {}',
9595
\ 'let g:ale_linters = {}',
9696
\ 'let g:ale_linters_explicit = 0',

test/test_autocmd_commands.vader

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Execute (All events should be set up when everything is on):
8787
\ 'CursorMoved * if exists(''*ale#engine#Cleanup'') | call ale#cursor#EchoCursorWarningWithDelay() | endif',
8888
\ 'FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand(''<abuf>'')))',
8989
\ 'FileType * call ale#events#FileTypeEvent( str2nr(expand(''<abuf>'')), expand(''<amatch>''))',
90-
\ 'InsertLeave * call ale#Queue(0)',
90+
\ 'InsertLeave * if ale#Var(str2nr(expand(''<abuf>'')), ''lint_on_insert_leave'') | call ale#Queue(0) | endif',
9191
\ 'InsertLeave if exists(''*ale#engine#Cleanup'') | call ale#cursor#EchoCursorWarning() | endif',
9292
\ 'TextChanged * call ale#Queue(g:ale_lint_delay)',
9393
\ 'TextChangedI * call ale#Queue(g:ale_lint_delay)',
@@ -158,7 +158,7 @@ Execute (g:ale_lint_on_insert_leave = 1 should bind InsertLeave):
158158

159159
AssertEqual
160160
\ [
161-
\ 'InsertLeave * call ale#Queue(0)',
161+
\ 'InsertLeave * if ale#Var(str2nr(expand(''<abuf>'')), ''lint_on_insert_leave'') | call ale#Queue(0) | endif',
162162
\ ],
163163
\ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertLeave''')
164164

test/test_cursor_warnings.vader

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Before:
22
Save g:ale_echo_msg_format
33
Save g:ale_echo_cursor
4+
Save b:ale_lint_on_insert_leave
5+
6+
let g:ale_echo_msg_format = '%code: %%s'
7+
let b:ale_lint_on_insert_leave = 0
48

59
" We should prefer the error message at column 10 instead of the warning.
610
let g:ale_buffer_info = {
@@ -91,6 +95,9 @@ Before:
9195
return empty(l:lines) ? '' : l:lines[-1]
9296
endfunction
9397

98+
call ale#linter#Reset()
99+
call ale#linter#PreventLoading('javascript')
100+
94101
After:
95102
Restore
96103

@@ -117,6 +124,8 @@ After:
117124
noautocmd :q!
118125
endif
119126

127+
call ale#linter#Reset()
128+
120129
Given javascript(A Javscript file with warnings/errors):
121130
var x = 3 + 12345678
122131
var x = 5*2 + parseInt("10");

0 commit comments

Comments
 (0)