diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-10-06 19:40:36 -0700 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-12-01 16:09:24 -0800 |
commit | 276c2da28616d7a4f504c328dbb8857d38ab7a4a (patch) | |
tree | 31f2d03921e6a44d5c5cc971f04295c53033cc10 /src | |
parent | 0a8d145075d3ce5fffe2df190992f624ae931809 (diff) | |
download | rneovim-276c2da28616d7a4f504c328dbb8857d38ab7a4a.tar.gz rneovim-276c2da28616d7a4f504c328dbb8857d38ab7a4a.tar.bz2 rneovim-276c2da28616d7a4f504c328dbb8857d38ab7a4a.zip |
API: nvim_source: fix multiline input
- DOCMD_REPEAT is needed to source all lines of input.
- Fix ":verbose set {option}?" by handling SID_STR in get_scriptname().
closes #8722
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 16 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 95f6de94a4..10ece6bc22 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -77,7 +77,7 @@ void nvim_source(String command, Error *err) FUNC_API_SINCE(7) { try_start(); - do_source_str((char_u *)command.data); + do_source_str(command.data); try_end(err); } diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index edfa3fea9a..eec689a28d 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3020,6 +3020,11 @@ typedef struct { size_t offset; } GetStrLineCookie; +/// Get one full line from a sourced string (in-memory, no file). +/// Called by do_cmdline() when it's called from do_source_str(). +/// +/// @return pointer to allocated line, or NULL for end-of-file or +/// some error. static char_u *get_str_line(int c, void *cookie, int ident) { GetStrLineCookie *p = cookie; @@ -3034,18 +3039,19 @@ static char_u *get_str_line(int c, void *cookie, int ident) char *dst; dst = xstpncpy(buf, (char *)p->buf+p->offset, i - p->offset); if ((uint32_t)(dst - buf) != i - p->offset) { - smsg(_("nvim_source error parsing command %s"), p->buf); + smsg(_(":source error parsing command %s"), p->buf); + return NULL; } buf[i-p->offset]='\0'; p->offset = i + 1; return (char_u *)xstrdup(buf); } -int do_source_str(char_u *cmd) +int do_source_str(const char *cmd) { int retval; GetStrLineCookie cookie = { - .buf = cmd, + .buf = (char_u *)cmd, .offset = 0, }; const sctx_T save_current_sctx = current_sctx; @@ -3053,7 +3059,7 @@ int do_source_str(char_u *cmd) current_sctx.sc_seq = 0; current_sctx.sc_lnum = 0; retval = do_cmdline(NULL, get_str_line, (void *)&cookie, - DOCMD_NOWAIT); + DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); current_sctx = save_current_sctx; return retval; } @@ -3402,6 +3408,8 @@ char_u *get_scriptname(LastSet last_set, bool *should_free) _("API client (channel id %" PRIu64 ")"), last_set.channel_id); return IObuff; + case SID_STR: + return (char_u *)_(":source (no file)"); default: *should_free = true; return home_replace_save(NULL, |