aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/executor.c
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@protonmail.com>2022-05-08 17:39:45 +0600
committerFamiu Haque <famiuhaque@protonmail.com>2022-05-11 13:12:16 +0600
commitdfcc58466505f7fb5f62d636a67facaeea143285 (patch)
treea8aa50a698d1f18fbc800b1c54a35169184c6c3b /src/nvim/lua/executor.c
parent77863b8e96324bc9e575af7f3f1b7e5de90fbadb (diff)
downloadrneovim-dfcc58466505f7fb5f62d636a67facaeea143285.tar.gz
rneovim-dfcc58466505f7fb5f62d636a67facaeea143285.tar.bz2
rneovim-dfcc58466505f7fb5f62d636a67facaeea143285.zip
feat(api): add `nvim_cmd`
Adds the API function `nvim_cmd` which allows executing an Ex-command through a Dictionary which can have the same values as the return value of `nvim_parse_cmd()`. This makes it much easier to do things like passing arguments with a space to commands that otherwise may not allow it, or to make commands interpret certain characters literally when they otherwise would not.
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r--src/nvim/lua/executor.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 1da868c137..7d08481a7b 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1863,8 +1863,8 @@ void nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap)
if (cmd->uc_argt & EX_NOSPC) {
// Commands where nargs = 1 or "?" fargs is the same as args
lua_rawseti(lstate, -2, 1);
- } else {
- // Commands with more than one possible argument we split
+ } else if (eap->args == NULL) {
+ // For commands with more than one possible argument, split if argument list isn't available.
lua_pop(lstate, 1); // Pop the reference of opts.args
size_t length = STRLEN(eap->arg);
size_t end = 0;
@@ -1881,6 +1881,13 @@ void nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap)
}
}
xfree(buf);
+ } else {
+ // If argument list is available, just use it.
+ lua_pop(lstate, 1);
+ for (size_t i = 0; i < eap->argc; i++) {
+ lua_pushlstring(lstate, eap->args[i], eap->arglens[i]);
+ lua_rawseti(lstate, -2, (int)i + 1);
+ }
}
lua_setfield(lstate, -2, "fargs");