Bug:
systemlist() does not return/cuts off last lines that are blank.
Example function demonstrating problem:
function TestSystemList()
let l:lines=['','', 'ABC', '', '']
echo "Using as input the lines:"
echo l:lines
let l:syslist=systemlist("cat", l:lines) " return lines exactly as given
echo "Calling systemlist("cat", l:lines) returns:"
echo l:syslist
let l:sysblock=system("cat", l:lines)
echo "Calling system("cat", l:lines) returns:"
echo l:sysblock
echo " (which includes all the lines)"
let l:split1=split(l:sysblock, "\n", 1)
echo "Using split(l:sysblock, "\n", 1) shows all the lines:"
echo l:split1
let l:split2=split(l:sysblock, "\n")
echo "Using split(l:sysblock, "\n") cuts off preceeding blank lines and the last line:"
echo l:split2
echo "systemlist() appears to be losing only the trailing line"
endfunction
Motivation:
A file that ends with multiple blank lines loses lines after a similar
systemlist() call:
Line 1:ABC
Line 2:
Line 3:
Proposed fixes:
A. clearly document that systemlist() does not preserve terminating
blank lines, advise using system() and split(...{keepempty})
B. (preferred by me) change systemlist() behavior to preserve last blank lines
Running:
Linux computer_name 4.9.0-4-amd64 #1 SMP Debian 4.9.65-3+deb9u1
(2017-12-23) x86_64 GNU/Linux
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 30 2017 18:21:38)
Included patches: 1-197, 322, 377-378, 550, 703, 706-707
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
This is now an issue of backwards compatibility, so Neovim team has already decided on the third option: add an argument which determines whether trailing newlines are to be preserved. Note that systemlist() was initially designed to get binary contents, but I made a bug during the implementation which was not fixed in time, so option A is not actually valid; meanwhile you can actually achieve intended behaviour either by using constructs like echo systemlist('bincmd ; echo') or like call system('bincmd > fname') | echo readfile('fname', 'b') | call delete('fname').
Why should it remove more? In the current state it is rather convenient to get newline-separated text contents, even though it was not actual intention: normally under those circumstances you have exactly one trailing newline (because text is not newline-separated, but newline-terminated) and not many of them. And I actually find behaviour of $() (if you think this has something to do with that) extremely annoying: should I want to preserve newline I am out of the most convenient option of VAR="$(cmd ; echo)" and need to use VAR="$(cmd ; echo A)"; VAR="${VAR%A}" instead, but I never saw myself in a situation when command outputs a bunch of newlines which I want to remove.