2017-10-28 19:36:16 +01:00
|
|
|
function! s:EnablePreamble() abort
|
|
|
|
" Set pattern options again, if enabled.
|
2018-05-28 19:19:20 +01:00
|
|
|
if get(g:, 'ale_pattern_options_enabled', 0)
|
2017-12-01 17:12:16 +00:00
|
|
|
call ale#pattern_options#SetOptions(bufnr(''))
|
2017-10-28 19:36:16 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
" Lint immediately, including running linters against the file.
|
|
|
|
call ale#Queue(0, 'lint_file')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:DisablePostamble() abort
|
|
|
|
" Remove highlights for the current buffer now.
|
|
|
|
if g:ale_set_highlights
|
|
|
|
call ale#highlight#UpdateHighlights()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2017-10-29 17:03:29 +00:00
|
|
|
function! s:CleanupEveryBuffer() abort
|
|
|
|
for l:key in keys(g:ale_buffer_info)
|
|
|
|
" The key could be a filename or a buffer number, so try and
|
|
|
|
" convert it to a number. We need a number for the other
|
|
|
|
" functions.
|
|
|
|
let l:buffer = str2nr(l:key)
|
|
|
|
|
|
|
|
if l:buffer > 0
|
|
|
|
" Stop all jobs and clear the results for everything, and delete
|
|
|
|
" all of the data we stored for the buffer.
|
|
|
|
call ale#engine#Cleanup(l:buffer)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2017-10-28 15:41:14 +01:00
|
|
|
function! ale#toggle#Toggle() abort
|
|
|
|
let g:ale_enabled = !get(g:, 'ale_enabled')
|
|
|
|
|
|
|
|
if g:ale_enabled
|
2017-10-28 19:36:16 +01:00
|
|
|
call s:EnablePreamble()
|
2018-03-25 12:57:08 +01:00
|
|
|
|
|
|
|
if g:ale_set_balloons
|
|
|
|
call ale#balloon#Enable()
|
|
|
|
endif
|
2017-10-28 15:41:14 +01:00
|
|
|
else
|
2017-10-29 17:03:29 +00:00
|
|
|
call s:CleanupEveryBuffer()
|
2017-10-28 19:36:16 +01:00
|
|
|
call s:DisablePostamble()
|
2018-03-25 12:57:08 +01:00
|
|
|
|
|
|
|
if has('balloon_eval')
|
|
|
|
call ale#balloon#Disable()
|
|
|
|
endif
|
2017-10-28 15:41:14 +01:00
|
|
|
endif
|
|
|
|
|
2018-06-19 20:31:58 +01:00
|
|
|
call ale#events#Init()
|
2017-10-28 15:41:14 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale#toggle#Enable() abort
|
|
|
|
if !g:ale_enabled
|
|
|
|
call ale#toggle#Toggle()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale#toggle#Disable() abort
|
|
|
|
if g:ale_enabled
|
|
|
|
call ale#toggle#Toggle()
|
|
|
|
endif
|
|
|
|
endfunction
|
2017-10-28 19:36:16 +01:00
|
|
|
|
2017-10-29 17:03:29 +00:00
|
|
|
function! ale#toggle#Reset() abort
|
|
|
|
call s:CleanupEveryBuffer()
|
|
|
|
call ale#highlight#UpdateHighlights()
|
|
|
|
endfunction
|
|
|
|
|
2017-10-28 19:36:16 +01:00
|
|
|
function! ale#toggle#ToggleBuffer(buffer) abort
|
|
|
|
" Get the new value for the toggle.
|
|
|
|
let l:enabled = !getbufvar(a:buffer, 'ale_enabled', 1)
|
|
|
|
|
|
|
|
" Disabling ALE globally removes autocmd events, so we cannot enable
|
|
|
|
" linting locally when linting is disabled globally
|
|
|
|
if l:enabled && !g:ale_enabled
|
2017-11-15 12:00:08 +00:00
|
|
|
execute 'echom ''ALE cannot be enabled locally when disabled globally'''
|
2017-10-28 19:36:16 +01:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call setbufvar(a:buffer, 'ale_enabled', l:enabled)
|
|
|
|
|
|
|
|
if l:enabled
|
|
|
|
call s:EnablePreamble()
|
|
|
|
else
|
|
|
|
" Stop all jobs and clear the results for everything, and delete
|
|
|
|
" all of the data we stored for the buffer.
|
|
|
|
call ale#engine#Cleanup(a:buffer)
|
|
|
|
call s:DisablePostamble()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale#toggle#EnableBuffer(buffer) abort
|
|
|
|
" ALE is enabled by default for all buffers.
|
|
|
|
if !getbufvar(a:buffer, 'ale_enabled', 1)
|
|
|
|
call ale#toggle#ToggleBuffer(a:buffer)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale#toggle#DisableBuffer(buffer) abort
|
|
|
|
if getbufvar(a:buffer, 'ale_enabled', 1)
|
|
|
|
call ale#toggle#ToggleBuffer(a:buffer)
|
|
|
|
endif
|
|
|
|
endfunction
|
2017-10-29 17:03:29 +00:00
|
|
|
|
|
|
|
function! ale#toggle#ResetBuffer(buffer) abort
|
|
|
|
call ale#engine#Cleanup(a:buffer)
|
|
|
|
call ale#highlight#UpdateHighlights()
|
|
|
|
endfunction
|