aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSiddhant Gupta <dpsrkp.sid@gmail.com>2019-10-06 13:37:54 -0700
committerJustin M. Keyes <justinkz@gmail.com>2019-12-01 16:09:24 -0800
commit6aa03e86da041284b5f27a59f73cef0991fc577e (patch)
tree201627e8f546d1f7b4567e2794d514bfeaaed163 /src
parent70b606166640d043fc7b78a52b89ff1bba798b6a (diff)
downloadrneovim-6aa03e86da041284b5f27a59f73cef0991fc577e.tar.gz
rneovim-6aa03e86da041284b5f27a59f73cef0991fc577e.tar.bz2
rneovim-6aa03e86da041284b5f27a59f73cef0991fc577e.zip
API: nvim_source
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/vim.c10
-rw-r--r--src/nvim/ex_cmds2.c40
2 files changed, 49 insertions, 1 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index e4a9bd64ff..ee36ae28e6 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -25,6 +25,7 @@
#include "nvim/highlight.h"
#include "nvim/window.h"
#include "nvim/types.h"
+#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/screen.h"
#include "nvim/memline.h"
@@ -72,6 +73,15 @@ void api_vim_free_all_mem(void)
map_free(String, handle_T)(namespace_ids);
}
+void nvim_source(String command, Error *err)
+ FUNC_API_SINCE(5)
+{
+ try_start();
+ do_source_str((char_u *)command.data);
+ update_screen(VALID);
+ try_end(err);
+}
+
/// Executes an ex-command.
///
/// On execution error: fails with VimL error, does not update v:errmsg.
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.
///