summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorDaniel Lupu <lupu.daniel.f@gmail.com>2017-02-09 20:47:14 +0200
committerw0rp <w0rp@users.noreply.github.com>2017-02-09 18:47:14 +0000
commit6dfed8576e881c71f242c6d8d9a2502f0bb50f99 (patch)
tree0ee224fb962a694de39820d64a9b8b6a59febd00 /plugin
parent943fe9b4b0faa2d011694cea113b0ef44713a586 (diff)
downloadale-6dfed8576e881c71f242c6d8d9a2502f0bb50f99.zip
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
Diffstat (limited to 'plugin')
-rw-r--r--plugin/ale.vim81
1 files changed, 57 insertions, 24 deletions
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