diff --git a/README.md b/README.md index 89bcc255..0292d52c 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ formatting tools, and some Language Server Protocol and `tsserver` features. 5. [How can I show errors or warnings in my statusline?](#faq-statusline) 6. [How can I show errors or warnings in my lightline?](#faq-lightline) 7. [How can I change the format for echo messages?](#faq-echo-format) - 8. [How can I execute some code when ALE stops linting?](#faq-autocmd) + 8. [How can I execute some code when ALE starts or stops linting?](#faq-autocmd) 9. [How can I navigate between errors quickly?](#faq-navigation) 10. [How can I run linters only when I save files?](#faq-lint-on-save) 11. [How can I use the quickfix list instead of the loclist?](#faq-quickfix) @@ -493,15 +493,17 @@ Will give you: -### 5.viii. How can I execute some code when ALE stops linting? +### 5.viii. How can I execute some code when ALE starts or stops linting? ALE runs its own [autocmd](http://vimdoc.sourceforge.net/htmldoc/autocmd.html) -event whenever has a linter has been successfully executed and processed. This -autocmd event can be used to call arbitrary functions after ALE stops linting. +events whenever has a linter is started and has been successfully executed and +processed. This autocmd event can be used to call arbitrary functions before and +after ALE stops linting. ```vim augroup YourGroup autocmd! + autocmd User ALEStartLint call YourFunction() autocmd User ALELint call YourFunction() augroup END ``` diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 150b53c1..895544fe 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -556,6 +556,8 @@ function! s:RunJob(options) abort \ 'output': [], \ 'next_chain_index': l:next_chain_index, \} + + silent doautocmd User ALEStartLint endif if g:ale_history_enabled diff --git a/doc/ale.txt b/doc/ale.txt index 8e8f5f4f..e45cfa92 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2196,6 +2196,12 @@ ALELint *ALELint-autocmd* The autocmd commands are run with |:silent|, so |:unsilent| is required for echoing messges. + +ALEStartLint *ALEStartLint-autocmd* + + This |User| autocommand is triggered by ALE right after it started a new + linting job. + =============================================================================== 10. Special Thanks *ale-special-thanks* diff --git a/test/test_alelint_autocmd.vader b/test/test_alelint_autocmd.vader index 4503005b..bf96abfb 100644 --- a/test/test_alelint_autocmd.vader +++ b/test/test_alelint_autocmd.vader @@ -1,18 +1,41 @@ Before: + let g:start = 0 let g:success = 0 let g:ale_run_synchronously = 1 + function! TestCallback(buffer, output) + return [{ + \ 'lnum': 1, + \ 'col': 3, + \ 'text': 'baz boz', + \}] + endfunction + + call ale#linter#Define('foobar', { + \ 'name': 'testlinter', + \ 'callback': 'TestCallback', + \ 'executable': has('win32') ? 'cmd' : 'true', + \ 'command': has('win32') ? 'echo' : 'true', + \}) + "let g:ale_linters = {'foobar': ['lint_file_linter']} + After: let g:ale_run_synchronously = 0 let g:ale_buffer_info = {} + let g:ale_linters = {} + call ale#linter#Reset() + delfunction TestCallback augroup! VaderTest Execute (Run a lint cycle, and check that a variable is set in the autocmd): + set filetype=foobar augroup VaderTest autocmd! - autocmd User ALELint let g:success = 1 + autocmd User ALEStartLint let g:start = 1 + autocmd User ALELint let g:success = 1 augroup end call ale#Lint() + AssertEqual g:start, 1 AssertEqual g:success, 1