#3319 - Try to modify buffers later for ALEFix
This commit is contained in:
parent
7d4ce4e6aa
commit
dd9ad9b5be
3 changed files with 31 additions and 22 deletions
|
@ -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)
|
||||
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!
|
||||
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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue