]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/toggle.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / toggle.vim
1 function! s:EnablePreamble() abort
2     " Set pattern options again, if enabled.
3     if get(g:, 'ale_pattern_options_enabled', 0)
4         call ale#pattern_options#SetOptions(bufnr(''))
5     endif
6
7     " Lint immediately, including running linters against the file.
8     call ale#Queue(0, 'lint_file')
9 endfunction
10
11 function! s:DisablePostamble() abort
12     " Remove highlights for the current buffer now.
13     if g:ale_set_highlights
14         call ale#highlight#UpdateHighlights()
15     endif
16
17     if g:ale_virtualtext_cursor isnot# 'disabled' && g:ale_virtualtext_cursor != 0
18         call ale#virtualtext#Clear(bufnr(''))
19     endif
20 endfunction
21
22 function! ale#toggle#Toggle() abort
23     let g:ale_enabled = !get(g:, 'ale_enabled')
24
25     if g:ale_enabled
26         call s:EnablePreamble()
27
28         if g:ale_set_balloons
29             call ale#balloon#Enable()
30         endif
31     else
32         call ale#engine#CleanupEveryBuffer()
33         call s:DisablePostamble()
34
35         if exists('*ale#balloon#Disable')
36             call ale#balloon#Disable()
37         endif
38     endif
39
40     call ale#events#Init()
41 endfunction
42
43 function! ale#toggle#Enable() abort
44     if !g:ale_enabled
45         call ale#toggle#Toggle()
46     endif
47 endfunction
48
49 function! ale#toggle#Disable() abort
50     if g:ale_enabled
51         call ale#toggle#Toggle()
52     endif
53 endfunction
54
55 function! ale#toggle#Reset() abort
56     call ale#engine#CleanupEveryBuffer()
57     call ale#highlight#UpdateHighlights()
58 endfunction
59
60 function! ale#toggle#ToggleBuffer(buffer) abort
61     " Get the new value for the toggle.
62     let l:enabled = !getbufvar(a:buffer, 'ale_enabled', 1)
63
64     " Disabling ALE globally removes autocmd events, so we cannot enable
65     " linting locally when linting is disabled globally
66     if l:enabled && !g:ale_enabled
67         " no-custom-checks
68         echom 'ALE cannot be enabled locally when disabled globally'
69
70         return
71     endif
72
73     call setbufvar(a:buffer, 'ale_enabled', l:enabled)
74
75     if l:enabled
76         call s:EnablePreamble()
77     else
78         " Stop all jobs and clear the results for everything, and delete
79         " all of the data we stored for the buffer.
80         call ale#engine#Cleanup(a:buffer)
81         call s:DisablePostamble()
82     endif
83 endfunction
84
85 function! ale#toggle#EnableBuffer(buffer) abort
86     " ALE is enabled by default for all buffers.
87     if !getbufvar(a:buffer, 'ale_enabled', 1)
88         call ale#toggle#ToggleBuffer(a:buffer)
89     endif
90 endfunction
91
92 function! ale#toggle#DisableBuffer(buffer) abort
93     if getbufvar(a:buffer, 'ale_enabled', 1)
94         call ale#toggle#ToggleBuffer(a:buffer)
95     endif
96 endfunction
97
98 function! ale#toggle#ResetBuffer(buffer) abort
99     call ale#engine#Cleanup(a:buffer)
100     call ale#highlight#UpdateHighlights()
101 endfunction