aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-04-13 00:49:37 +0200
committerGitHub <noreply@github.com>2018-04-13 00:49:37 +0200
commit1c3a849881f45e2acb08ce99e5b33dd753f61d5d (patch)
tree8afb04002f3c2de7d381588f3b2c0803bdc9f32a /src
parent5e18550ddde07ce90111f7bda17d86608fbb8619 (diff)
downloadrneovim-1c3a849881f45e2acb08ce99e5b33dd753f61d5d.tar.gz
rneovim-1c3a849881f45e2acb08ce99e5b33dd753f61d5d.tar.bz2
rneovim-1c3a849881f45e2acb08ce99e5b33dd753f61d5d.zip
API/nvim_command_output: handle :echon capture (#8265)
ref https://github.com/neovim/python-client/pull/290
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/vim.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 962081cc23..07ec6e8c27 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -239,15 +239,17 @@ String nvim_command_output(String command, Error *err)
}
if (capture_local.ga_len > 1) {
- // redir always(?) prepends a newline; remove it.
- char *s = capture_local.ga_data;
- assert(s[0] == '\n');
- memmove(s, s + 1, (size_t)capture_local.ga_len);
- s[capture_local.ga_len - 1] = '\0';
- return (String) { // Caller will free the memory.
- .data = s,
- .size = (size_t)(capture_local.ga_len - 1),
+ String s = (String){
+ .data = capture_local.ga_data,
+ .size = (size_t)capture_local.ga_len,
};
+ // redir usually (except :echon) prepends a newline.
+ if (s.data[0] == '\n') {
+ memmove(s.data, s.data + 1, s.size);
+ s.data[s.size - 1] = '\0';
+ s.size = s.size - 1;
+ }
+ return s; // Caller will free the memory.
}
theend: