summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-03-18 16:37:16 +0000
committerGitHub <noreply@github.com>2018-03-18 16:37:16 +0000
commitb08fdd16b879527885d3d8f9e21ba688b5f18763 (patch)
treee27cb56d84dbe449fff9e3514c87e600feecf849
parent92e6e4d1ba482a4d2d89d850f660c67ccf8a28eb (diff)
parent302f69e933b85628c688a1b16eab5dd2e7976e99 (diff)
downloadale-b08fdd16b879527885d3d8f9e21ba688b5f18763.zip
Merge pull request #1248 from Carpetsmoker/autocmd-fixer
Add ALEFixPre and ALEFixPost events
-rw-r--r--README.md8
-rw-r--r--autoload/ale/fix.vim4
-rw-r--r--doc/ale.txt6
-rw-r--r--test/fix/test_ale_fix.vader15
4 files changed, 28 insertions, 5 deletions
diff --git a/README.md b/README.md
index d5335e2a..1e5a725f 100644
--- a/README.md
+++ b/README.md
@@ -502,15 +502,17 @@ Will give you:
### 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)
-events whenever has a linter is started and has been successfully executed and
-processed. These events can be used to call arbitrary functions before and after
-ALE stops linting.
+events when a lint or fix cycle are started and stopped. These events can be
+used to call arbitrary functions before and after ALE stops linting.
```vim
augroup YourGroup
autocmd!
autocmd User ALELintPre call YourFunction()
autocmd User ALELintPost call YourFunction()
+
+ autocmd User ALEFixPre call YourFunction()
+ autocmd User ALEFixPost call YourFunction()
augroup END
```
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim
index 9111db3d..398f57d0 100644
--- a/autoload/ale/fix.vim
+++ b/autoload/ale/fix.vim
@@ -54,6 +54,8 @@ function! ale#fix#ApplyQueuedFixes() abort
let l:should_lint = l:data.changes_made
endif
+ silent doautocmd <nomodeline> User ALEFixPost
+
" If ALE linting is enabled, check for problems with the file again after
" fixing problems.
if g:ale_enabled
@@ -463,6 +465,8 @@ function! ale#fix#Fix(...) abort
call ale#fix#RemoveManagedFiles(l:buffer)
call ale#fix#InitBufferData(l:buffer, l:fixing_flag)
+ silent doautocmd <nomodeline> User ALEFixPre
+
call s:RunFixer({
\ 'buffer': l:buffer,
\ 'input': g:ale_fix_buffer_data[l:buffer].lines_before,
diff --git a/doc/ale.txt b/doc/ale.txt
index 2e98cd71..b16528f6 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2304,9 +2304,11 @@ b:ale_linted *b:ale_linted*
ALELintPre *ALELintPre-autocmd*
ALELintPost *ALELintPost-autocmd*
+ALEFixPre *ALEFixPre-autocmd*
+ALEFixPost *ALEFixPost-autocmd*
- These |User| autocommands are triggered before and after every lint cycle.
- They can be used to update statuslines, send notifications, etc.
+ These |User| autocommands are triggered before and after every lint or fix
+ cycle. They can be used to update statuslines, send notifications, etc.
The autocmd commands are run with |:silent|, so |:unsilent| is required for
echoing messges.
diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader
index 5b66c92c..0321cbae 100644
--- a/test/fix/test_ale_fix.vader
+++ b/test/fix/test_ale_fix.vader
@@ -17,6 +17,14 @@ Before:
\ 'testft': [],
\}
+ let g:pre_success = 0
+ let g:post_success = 0
+ augroup VaderTest
+ autocmd!
+ autocmd User ALEFixPre let g:pre_success = 1
+ autocmd User ALEFixPost let g:post_success = 1
+ augroup end
+
if !has('win32')
let &shell = '/bin/bash'
endif
@@ -171,6 +179,7 @@ After:
unlet! g:ale_emulate_job_failure
unlet! b:ale_fixers
unlet! b:ale_fix_on_save
+ augroup! VaderTest
delfunction AddCarets
delfunction AddDollars
delfunction DoNothing
@@ -664,3 +673,9 @@ Expect(The lines in the JSON should be used):
x
y
z
+
+Execute(ALEFix should apply autocmds):
+ let g:ale_fixers.testft = ['AddCarets']
+ ALEFix
+ AssertEqual g:pre_success, 1
+ AssertEqual g:post_success, 1