summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-06-19 20:31:58 +0100
committerw0rp <devw0rp@gmail.com>2018-06-19 20:31:58 +0100
commitfd261d7a171686a395b0c31cbc1c97e24cf24290 (patch)
treee06d770d647f63f15fc13a443e2785194aada5e3
parent3a5887df2c5b51de56629d27d9e8e7fbe38d11f6 (diff)
downloadale-fd261d7a171686a395b0c31cbc1c97e24cf24290.zip
Move the initialization of augroups to then events file
-rw-r--r--autoload/ale/autocmd.vim77
-rw-r--r--autoload/ale/events.vim79
-rw-r--r--autoload/ale/toggle.vim2
-rw-r--r--plugin/ale.vim2
-rw-r--r--test/test_autocmd_commands.vader4
5 files changed, 83 insertions, 81 deletions
diff --git a/autoload/ale/autocmd.vim b/autoload/ale/autocmd.vim
deleted file mode 100644
index 8570adaa..00000000
--- a/autoload/ale/autocmd.vim
+++ /dev/null
@@ -1,77 +0,0 @@
-function! ale#autocmd#InitAuGroups() abort
- " This value used to be a Boolean as a Number, and is now a String.
- let l:text_changed = '' . g:ale_lint_on_text_changed
-
- augroup ALEPatternOptionsGroup
- autocmd!
- autocmd BufEnter,BufRead * call ale#pattern_options#SetOptions(str2nr(expand('<abuf>')))
- augroup END
-
- augroup ALERunOnTextChangedGroup
- autocmd!
- if g:ale_enabled
- if l:text_changed is? 'always' || l:text_changed is# '1'
- autocmd TextChanged,TextChangedI * call ale#Queue(g:ale_lint_delay)
- elseif l:text_changed is? 'normal'
- autocmd TextChanged * call ale#Queue(g:ale_lint_delay)
- elseif l:text_changed is? 'insert'
- autocmd TextChangedI * call ale#Queue(g:ale_lint_delay)
- endif
- endif
- augroup END
-
- augroup ALERunOnEnterGroup
- autocmd!
- if g:ale_enabled
- " Handle everything that needs to happen when buffers are entered.
- autocmd BufEnter * call ale#events#EnterEvent(str2nr(expand('<abuf>')))
- endif
- if g:ale_enabled && g:ale_lint_on_enter
- autocmd BufWinEnter,BufRead * call ale#Queue(0, 'lint_file', str2nr(expand('<abuf>')))
- " Track when the file is changed outside of Vim.
- autocmd FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand('<abuf>')))
- endif
- augroup END
-
- augroup ALERunOnFiletypeChangeGroup
- autocmd!
- if g:ale_enabled && g:ale_lint_on_filetype_changed
- " Only start linting if the FileType actually changes after
- " opening a buffer. The FileType will fire when buffers are opened.
- autocmd FileType * call ale#events#FileTypeEvent(
- \ str2nr(expand('<abuf>')),
- \ expand('<amatch>')
- \)
- endif
- augroup END
-
- augroup ALERunOnSaveGroup
- autocmd!
- autocmd BufWritePost * call ale#events#SaveEvent(str2nr(expand('<abuf>')))
- augroup END
-
- augroup ALERunOnInsertLeave
- autocmd!
- if g:ale_enabled && g:ale_lint_on_insert_leave
- autocmd InsertLeave * 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()
- " Look for a warning to echo as soon as we leave Insert mode.
- " The script's position variable used when moving the cursor will
- " not be changed here.
- autocmd InsertLeave * call ale#cursor#EchoCursorWarning()
- endif
- augroup END
-
- if !g:ale_enabled
- augroup! ALERunOnTextChangedGroup
- augroup! ALERunOnEnterGroup
- augroup! ALERunOnInsertLeave
- augroup! ALECursorGroup
- endif
-endfunction
diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim
index 3d2aa32d..a12ca049 100644
--- a/autoload/ale/events.vim
+++ b/autoload/ale/events.vim
@@ -1,4 +1,5 @@
" Author: w0rp <devw0rp@gmail.com>
+" Description: ALE functions for autocmd events.
function! ale#events#QuitEvent(buffer) abort
" Remember when ALE is quitting for BufWrite, etc.
@@ -67,3 +68,81 @@ function! ale#events#FileChangedEvent(buffer) abort
call s:LintOnEnter(a:buffer)
endif
endfunction
+
+function! ale#events#Init() abort
+ " This value used to be a Boolean as a Number, and is now a String.
+ let l:text_changed = '' . g:ale_lint_on_text_changed
+
+ augroup ALEPatternOptionsGroup
+ autocmd!
+ autocmd BufEnter,BufRead * call ale#pattern_options#SetOptions(str2nr(expand('<abuf>')))
+ augroup END
+
+ augroup ALERunOnTextChangedGroup
+ autocmd!
+ if g:ale_enabled
+ if l:text_changed is? 'always' || l:text_changed is# '1'
+ autocmd TextChanged,TextChangedI * call ale#Queue(g:ale_lint_delay)
+ elseif l:text_changed is? 'normal'
+ autocmd TextChanged * call ale#Queue(g:ale_lint_delay)
+ elseif l:text_changed is? 'insert'
+ autocmd TextChangedI * call ale#Queue(g:ale_lint_delay)
+ endif
+ endif
+ augroup END
+
+ augroup ALERunOnEnterGroup
+ autocmd!
+ if g:ale_enabled
+ " Handle everything that needs to happen when buffers are entered.
+ autocmd BufEnter * call ale#events#EnterEvent(str2nr(expand('<abuf>')))
+ endif
+ if g:ale_enabled && g:ale_lint_on_enter
+ autocmd BufWinEnter,BufRead * call ale#Queue(0, 'lint_file', str2nr(expand('<abuf>')))
+ " Track when the file is changed outside of Vim.
+ autocmd FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand('<abuf>')))
+ endif
+ augroup END
+
+ augroup ALERunOnFiletypeChangeGroup
+ autocmd!
+ if g:ale_enabled && g:ale_lint_on_filetype_changed
+ " Only start linting if the FileType actually changes after
+ " opening a buffer. The FileType will fire when buffers are opened.
+ autocmd FileType * call ale#events#FileTypeEvent(
+ \ str2nr(expand('<abuf>')),
+ \ expand('<amatch>')
+ \)
+ endif
+ augroup END
+
+ augroup ALERunOnSaveGroup
+ autocmd!
+ autocmd BufWritePost * call ale#events#SaveEvent(str2nr(expand('<abuf>')))
+ augroup END
+
+ augroup ALERunOnInsertLeave
+ autocmd!
+ if g:ale_enabled && g:ale_lint_on_insert_leave
+ autocmd InsertLeave * 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()
+ " Look for a warning to echo as soon as we leave Insert mode.
+ " The script's position variable used when moving the cursor will
+ " not be changed here.
+ autocmd InsertLeave * call ale#cursor#EchoCursorWarning()
+ endif
+ augroup END
+
+ if !g:ale_enabled
+ augroup! ALERunOnTextChangedGroup
+ augroup! ALERunOnEnterGroup
+ augroup! ALERunOnInsertLeave
+ augroup! ALECursorGroup
+ endif
+endfunction
diff --git a/autoload/ale/toggle.vim b/autoload/ale/toggle.vim
index d8472cd8..6b1affc4 100644
--- a/autoload/ale/toggle.vim
+++ b/autoload/ale/toggle.vim
@@ -48,7 +48,7 @@ function! ale#toggle#Toggle() abort
endif
endif
- call ale#autocmd#InitAuGroups()
+ call ale#events#Init()
endfunction
function! ale#toggle#Enable() abort
diff --git a/plugin/ale.vim b/plugin/ale.vim
index d9f1216e..2ea30a30 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -221,7 +221,7 @@ nnoremap <silent> <Plug>(ale_find_references) :ALEFindReferences<Return>
nnoremap <silent> <Plug>(ale_hover) :ALEHover<Return>
" Set up autocmd groups now.
-call ale#autocmd#InitAuGroups()
+call ale#events#Init()
" Housekeeping
diff --git a/test/test_autocmd_commands.vader b/test/test_autocmd_commands.vader
index 63e704bd..f82577f4 100644
--- a/test/test_autocmd_commands.vader
+++ b/test/test_autocmd_commands.vader
@@ -1,6 +1,6 @@
Before:
function! CheckAutocmd(group)
- call ale#autocmd#InitAuGroups()
+ call ale#events#Init()
redir => l:output
execute 'silent! autocmd ' . a:group
@@ -59,7 +59,7 @@ After:
call ale#completion#Disable()
endif
- call ale#autocmd#InitAuGroups()
+ call ale#events#Init()
Execute (g:ale_lint_on_text_changed = 0 should bind no events):
let g:ale_lint_on_text_changed = 0