diff options
author | w0rp <devw0rp@gmail.com> | 2020-08-29 12:33:17 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2020-08-29 12:33:17 +0100 |
commit | dd9ad9b5be84bea7105a91bb7e15c308cfe2c57f (patch) | |
tree | 8598f9fd43789ef477110873245d9144a2390b65 | |
parent | 7d4ce4e6aa960a6052a16d90322566d6f4fddb7c (diff) | |
download | ale-dd9ad9b5be84bea7105a91bb7e15c308cfe2c57f.zip |
#3319 - Try to modify buffers later for ALEFix
-rw-r--r-- | autoload/ale/fix.vim | 31 | ||||
-rw-r--r-- | autoload/ale/util.vim | 11 | ||||
-rw-r--r-- | test/fix/test_ale_fix.vader | 13 |
3 files changed, 32 insertions, 23 deletions
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 3ad0a433..b04ab18f 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -15,22 +15,29 @@ function! ale#fix#ApplyQueuedFixes(buffer) abort call remove(g:ale_fix_buffer_data, a:buffer) - if l:data.changes_made - let l:new_lines = ale#util#SetBufferContents(a:buffer, l:data.output) - - if l:data.should_save - if a:buffer is bufnr('') - if empty(&buftype) - noautocmd :w! + try + if l:data.changes_made + let l:new_lines = ale#util#SetBufferContents(a:buffer, l:data.output) + + if l:data.should_save + if a:buffer is bufnr('') + if empty(&buftype) + noautocmd :w! + else + set nomodified + endif else - set nomodified + call writefile(l:new_lines, expand('#' . a:buffer . ':p')) " no-custom-checks + call setbufvar(a:buffer, '&modified', 0) endif - else - call writefile(l:new_lines, expand('#' . a:buffer . ':p')) " no-custom-checks - call setbufvar(a:buffer, '&modified', 0) endif endif - endif + catch /E21/ + " If we cannot modify the buffer now, try again later. + let g:ale_fix_buffer_data[a:buffer] = l:data + + return + endtry if l:data.should_save let l:should_lint = ale#Var(a:buffer, 'fix_on_save') diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index 05f11993..1f396377 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -505,13 +505,6 @@ function! ale#util#SetBufferContents(buffer, lines) abort \ : a:lines let l:first_line_to_remove = len(l:new_lines) + 1 - " We'll temporarily make a buffer modifiable, to force edits. - let l:modifiable = getbufvar(a:buffer, '&modifiable') - - if !l:modifiable - call setbufvar(a:buffer, '&modifiable', 1) - endif - " Use a Vim API for setting lines in other buffers, if available. if l:has_bufline_api call setbufline(a:buffer, 1, l:new_lines) @@ -530,9 +523,5 @@ function! ale#util#SetBufferContents(buffer, lines) abort call setline(1, l:new_lines) endif - if !l:modifiable - call setbufvar(a:buffer, '&modifiable', 0) - endif - return l:new_lines endfunction diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index e8a9dd7a..62643da2 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -727,6 +727,19 @@ Expect(There should be only two lines): a b +Execute(ALEFix should modify a buffer that is not modifiable, if it becomes modifable later): + let g:ale_fixers.testft = ['RemoveLastLineOneArg'] + + set nomodifiable + ALEFix + call ale#test#FlushJobs() + set modifiable + call ale#fix#ApplyQueuedFixes(bufnr('')) + +Expect(There should be only two lines): + a + b + Execute(b:ale_fix_on_save = 1 should override g:ale_fix_on_save = 0): let g:ale_fix_on_save = 0 let b:ale_fix_on_save = 1 |