summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2021-08-06 21:34:38 +0200
committerBram Moolenaar <Bram@vim.org>2021-08-06 21:34:38 +0200
commit11328bc7df0ecc47f4025a10bb86882a659e9994 (patch)
treeb079094f517cb0059686d866ee691bc3bfbd4c03 /src/evalfunc.c
parent5671f3f076573fa9133bc210d6580067698d9a1b (diff)
patch 8.2.3300: Lua: can only execute on Vim command at a timev8.2.3300
Problem: Lua: can only execute on Vim command at a time. Not easy to get the Vim version. Solution: Make vim.command() accept multiple lines. Add vim.version(). (Yegappan Lakshmanan, closes #8716)
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index af46d150a2..7006afa498 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -3365,6 +3365,48 @@ execute_redir_str(char_u *value, int value_len)
}
/*
+ * Get next line from a string containing NL separated lines.
+ * Called by do_cmdline() to get the next line.
+ * Returns an allocated string, or NULL when at the end of the string.
+ */
+ static char_u *
+get_str_line(
+ int c UNUSED,
+ void *cookie,
+ int indent UNUSED,
+ getline_opt_T options UNUSED)
+{
+ char_u *start = *(char_u **)cookie;
+ char_u *line;
+ char_u *p;
+
+ p = start;
+ if (p == NULL || *p == NUL)
+ return NULL;
+ p = vim_strchr(p, '\n');
+ if (p == NULL)
+ line = vim_strsave(start);
+ else
+ {
+ line = vim_strnsave(start, p - start);
+ p++;
+ }
+
+ *(char_u **)cookie = p;
+ return line;
+}
+
+/*
+ * Execute a series of Ex commands in 'str'
+ */
+ void
+execute_cmds_from_string(char_u *str)
+{
+ do_cmdline(NULL, get_str_line, (void *)&str,
+ DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT|DOCMD_KEYTYPED);
+}
+
+/*
* Get next line from a list.
* Called by do_cmdline() to get the next line.
* Returns allocated string, or NULL for end of function.