mirror of
https://github.com/dense-analysis/ale
synced 2025-01-31 04:24:05 +00:00
Rename ale#fix#SetBufferContents to ale#util#SetBufferContents
This commit is contained in:
parent
c8c142b881
commit
40890cfcf3
@ -112,7 +112,7 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
|
||||
if a:should_save
|
||||
call ale#util#Writefile(l:buffer, l:lines, a:filename)
|
||||
else
|
||||
call ale#fix#SetBufferContents(l:buffer, l:lines)
|
||||
call ale#util#SetBufferContents(l:buffer, l:lines)
|
||||
endif
|
||||
|
||||
if l:is_current_buffer
|
||||
|
@ -12,7 +12,7 @@ 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#fix#SetBufferContents(a:buffer, l:data.output)
|
||||
let l:new_lines = ale#util#SetBufferContents(a:buffer, l:data.output)
|
||||
|
||||
if l:data.should_save
|
||||
if a:buffer is bufnr('')
|
||||
@ -46,43 +46,6 @@ function! ale#fix#ApplyQueuedFixes(buffer) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Sets buffer contents to lines
|
||||
function! ale#fix#SetBufferContents(buffer, lines) abort
|
||||
let l:has_bufline_api = exists('*deletebufline') && exists('*setbufline')
|
||||
|
||||
if !l:has_bufline_api && a:buffer isnot bufnr('')
|
||||
return
|
||||
endif
|
||||
|
||||
" If the file is in DOS mode, we have to remove carriage returns from
|
||||
" the ends of lines before calling setline(), or we will see them
|
||||
" twice.
|
||||
let l:new_lines = getbufvar(a:buffer, '&fileformat') is# 'dos'
|
||||
\ ? map(copy(a:lines), 'substitute(v:val, ''\r\+$'', '''', '''')')
|
||||
\ : a:lines
|
||||
let l:first_line_to_remove = len(l:new_lines) + 1
|
||||
|
||||
" 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)
|
||||
call deletebufline(a:buffer, l:first_line_to_remove, '$')
|
||||
" Fall back on setting lines the old way, for the current buffer.
|
||||
else
|
||||
let l:old_line_length = line('$')
|
||||
|
||||
if l:old_line_length >= l:first_line_to_remove
|
||||
let l:save = winsaveview()
|
||||
silent execute
|
||||
\ l:first_line_to_remove . ',' . l:old_line_length . 'd_'
|
||||
call winrestview(l:save)
|
||||
endif
|
||||
|
||||
call setline(1, l:new_lines)
|
||||
endif
|
||||
|
||||
return l:new_lines
|
||||
endfunction
|
||||
|
||||
function! ale#fix#ApplyFixes(buffer, output) abort
|
||||
let l:data = g:ale_fix_buffer_data[a:buffer]
|
||||
let l:data.output = a:output
|
||||
|
@ -480,3 +480,40 @@ endfunction
|
||||
function! ale#util#Input(message, value) abort
|
||||
return input(a:message, a:value)
|
||||
endfunction
|
||||
|
||||
" Sets buffer contents to lines
|
||||
function! ale#util#SetBufferContents(buffer, lines) abort
|
||||
let l:has_bufline_api = exists('*deletebufline') && exists('*setbufline')
|
||||
|
||||
if !l:has_bufline_api && a:buffer isnot bufnr('')
|
||||
return
|
||||
endif
|
||||
|
||||
" If the file is in DOS mode, we have to remove carriage returns from
|
||||
" the ends of lines before calling setline(), or we will see them
|
||||
" twice.
|
||||
let l:new_lines = getbufvar(a:buffer, '&fileformat') is# 'dos'
|
||||
\ ? map(copy(a:lines), 'substitute(v:val, ''\r\+$'', '''', '''')')
|
||||
\ : a:lines
|
||||
let l:first_line_to_remove = len(l:new_lines) + 1
|
||||
|
||||
" 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)
|
||||
call deletebufline(a:buffer, l:first_line_to_remove, '$')
|
||||
" Fall back on setting lines the old way, for the current buffer.
|
||||
else
|
||||
let l:old_line_length = line('$')
|
||||
|
||||
if l:old_line_length >= l:first_line_to_remove
|
||||
let l:save = winsaveview()
|
||||
silent execute
|
||||
\ l:first_line_to_remove . ',' . l:old_line_length . 'd_'
|
||||
call winrestview(l:save)
|
||||
endif
|
||||
|
||||
call setline(1, l:new_lines)
|
||||
endif
|
||||
|
||||
return l:new_lines
|
||||
endfunction
|
||||
|
Loading…
Reference in New Issue
Block a user