mirror of https://github.com/dense-analysis/ale
Merge pull request #3144 from jamescdavis/dont_append_newline_when_noeol
don't append a newline to temp file when buffer is noeol and nofixeol is set
This commit is contained in:
commit
2b2403a20d
|
@ -423,7 +423,10 @@ function! ale#util#Writefile(buffer, lines, filename) abort
|
|||
\ ? map(copy(a:lines), 'substitute(v:val, ''\r*$'', ''\r'', '''')')
|
||||
\ : a:lines
|
||||
|
||||
call writefile(l:corrected_lines, a:filename, 'S') " no-custom-checks
|
||||
" Set binary flag if buffer doesn't have eol and nofixeol to avoid appending newline
|
||||
let l:flags = !getbufvar(a:buffer, '&eol') && exists('+fixeol') && !&fixeol ? 'bS' : 'S'
|
||||
|
||||
call writefile(l:corrected_lines, a:filename, l:flags) " no-custom-checks
|
||||
endfunction
|
||||
|
||||
if !exists('s:patial_timers')
|
||||
|
|
|
@ -69,3 +69,49 @@ Execute(Unix file lines should be written as normal):
|
|||
AssertEqual
|
||||
\ ['first', 'second', 'third', ''],
|
||||
\ readfile(g:new_line_test_file, 'b')
|
||||
|
||||
Execute(Newline at end of file should be preserved even when nofixeol):
|
||||
call ale#test#SetFilename(g:new_line_test_file)
|
||||
|
||||
setlocal buftype=
|
||||
noautocmd :w
|
||||
noautocmd :e! ++ff=unix
|
||||
set eol
|
||||
set nofixeol
|
||||
|
||||
call ale#util#Writefile(bufnr(''), getline(1, '$'), g:new_line_test_file)
|
||||
|
||||
AssertEqual
|
||||
\ ['first', 'second', 'third', ''],
|
||||
\ readfile(g:new_line_test_file, 'b')
|
||||
|
||||
Execute(Newline should not be appended on write when noeol and nofixeol):
|
||||
call ale#test#SetFilename(g:new_line_test_file)
|
||||
|
||||
setlocal buftype=
|
||||
noautocmd :w
|
||||
noautocmd :e! ++ff=unix
|
||||
set noeol
|
||||
set nofixeol
|
||||
|
||||
call ale#util#Writefile(bufnr(''), getline(1, '$'), g:new_line_test_file)
|
||||
|
||||
AssertEqual
|
||||
\ ['first', 'second', 'third'],
|
||||
\ readfile(g:new_line_test_file, 'b')
|
||||
|
||||
Execute(Newline should be appended on write when noeol and fixeol):
|
||||
call ale#test#SetFilename(g:new_line_test_file)
|
||||
|
||||
setlocal buftype=
|
||||
noautocmd :w
|
||||
noautocmd :e! ++ff=unix
|
||||
set noeol
|
||||
set fixeol
|
||||
|
||||
call ale#util#Writefile(bufnr(''), getline(1, '$'), g:new_line_test_file)
|
||||
|
||||
AssertEqual
|
||||
\ ['first', 'second', 'third', ''],
|
||||
\ readfile(g:new_line_test_file, 'b')
|
||||
|
||||
|
|
Loading…
Reference in New Issue