New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix systemlist() #1135
Fix systemlist() #1135
Conversation
Hi thinca, 2016-9-30(Fri) 1:39:34 UTC+9 thinca:
Good patch👍
If you want to run from test_alot.vim as follows: Best regards, |
b510aee
to
3f9c1ba
Compare
@h-east Thank you for your advice! |
Hi thinca, 2016-9-30(Fri) 12:01:55 UTC+9 thinca:
You need select one of the two patches.
Best regards, |
@h-east oops, sorry and thanks! |
:help systemlist() says: > Output is the same as readfile() will output with {binary} argument > set to "b". And :help readfile() says: > When {binary} contains "b" binary mode is used: > - When the last line ends in a NL an extra empty list item is > added. > - No CR characters are removed. systemlist() doesn't satisfy the first matter. ```vim :echo systemlist('echo hello') " => ['hello'] " `echo` command outputs text with NL, " so this should be ['hello', ''] ``` This change fixes the above problem.
3f9c1ba
to
5b2d022
Compare
I updated the patch, and all tests passed. |
This is todolisted. 2ec618c#diff-38d7929bd26d74d92ceddf984bbfc8dbR152
Currently, we can't know the result of command ends with NL. echo systemlist('echo hello')
" => ['hello']
echo systemlist('echo -n hello')
" => ['hello'] Therefore I think this change is needed. |
Sadly, your patch won't change that: echo systemlist('echo hello; echo')
" => ['hello', ''] |
I would suggest to copy encode_list_write from Neovim: /// Msgpack callback for writing to readfile()-style list
int encode_list_write(void *const data, const char *const buf, const size_t len)
FUNC_ATTR_NONNULL_ARG(1)
{
if (len == 0) {
return 0;
}
list_T *const list = (list_T *) data;
const char *const end = buf + len;
const char *line_end = buf;
listitem_T *li = list->lv_last;
// Continue the last list element
if (li != NULL) {
line_end = xmemscan(buf, NL, len);
if (line_end != buf) {
const size_t line_length = (size_t)(line_end - buf);
char *str = (char *)li->li_tv.vval.v_string;
const size_t li_len = (str == NULL ? 0 : strlen(str));
li->li_tv.vval.v_string = xrealloc(str, li_len + line_length + 1);
str = (char *)li->li_tv.vval.v_string + li_len;
memcpy(str, buf, line_length);
str[line_length] = 0;
memchrsub(str, NUL, NL, line_length);
}
line_end++;
}
while (line_end < end) {
const char *line_start = line_end;
line_end = xmemscan(line_start, NL, (size_t) (end - line_start));
char *str = NULL;
if (line_end != line_start) {
const size_t line_length = (size_t)(line_end - line_start);
str = xmemdupz(line_start, line_length);
memchrsub(str, NUL, NL, line_length);
}
tv_list_append_allocated_string(list, str);
line_end++;
}
if (line_end == end) {
tv_list_append_allocated_string(list, NULL);
}
return 0;
} This function was tested also with input like |
thinca wrote:
I can't think of a situation where it matters. Shell output is normally ARTHUR: Shut up! Will you shut up! /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \ |
@brammool This is essential for things like using the output of |
Nikolai Pavlov wrote:
I think it's rare to read a binary file. We can make it possible, but Also, compared to readfile() there is no way to handle the input as Also, if we change this now it's not backwards compatible. The extra I think we should add an argument that indicates binary or not-binary, "Hegel was right when he said that we learn from history that man can /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \ |
Isn't it possible to do the same with system('cmd')->split('\n', 1) ? |
Closing this, because the solution is not backwards compatible. |
:help systemlist() says:
And :help readfile() says:
systemlist() doesn't satisfy the first matter.
This change fixes the above problem.