diff options
author | Siddhant Gupta <dpsrkp.sid@gmail.com> | 2019-10-06 13:37:54 -0700 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-12-01 16:09:24 -0800 |
commit | 6aa03e86da041284b5f27a59f73cef0991fc577e (patch) | |
tree | 201627e8f546d1f7b4567e2794d514bfeaaed163 /src/nvim/ex_cmds2.c | |
parent | 70b606166640d043fc7b78a52b89ff1bba798b6a (diff) | |
download | rneovim-6aa03e86da041284b5f27a59f73cef0991fc577e.tar.gz rneovim-6aa03e86da041284b5f27a59f73cef0991fc577e.tar.bz2 rneovim-6aa03e86da041284b5f27a59f73cef0991fc577e.zip |
API: nvim_source
Diffstat (limited to 'src/nvim/ex_cmds2.c')
-rw-r--r-- | src/nvim/ex_cmds2.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 84291b3637..904a3d10e5 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1193,7 +1193,7 @@ static void script_dump_profile(FILE *fd) /// profiled. bool prof_def_func(void) { - if (current_sctx.sc_sid > 0) { + if (current_sctx.sc_sid > 0 && current_SID < 999999) { return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force; } return false; @@ -3015,6 +3015,44 @@ static FILE *fopen_noinh_readbin(char *filename) return fdopen(fd_tmp, READBIN); } +typedef struct { + char_u *buf; + size_t offset; +} GetStrLineCookie; + +static char_u *get_str_line(int c, void *cookie, int ident) +{ + GetStrLineCookie *p = cookie; + size_t i = p->offset; + if (strlen((char *)p->buf) <= p->offset) { + return NULL; + } + while (!(p->buf[i] == '\n' || p->buf[i] == '\0')) { + i++; + } + char buf[2046]; + 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); + } + buf[i-p->offset]='\0'; + p->offset = i + 1; + return (char_u *)xstrdup(buf); +} + +int do_source_str(char_u *cmd) +{ + int retval; + GetStrLineCookie cookie = { + .buf = cmd, + .offset = 0, + }; + current_SID = 999999; + retval = do_cmdline(NULL, get_str_line, (void *)&cookie, + DOCMD_NOWAIT); + return retval; +} /// Read the file "fname" and execute its lines as EX commands. /// |