diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-03-22 10:59:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-22 10:59:38 +0100 |
commit | c45b5e2c5b0f02742099ebccc44462fe4203e99c (patch) | |
tree | 13811fb22e65a99413aa5373c41e8c77d99ca779 /src | |
parent | 48ce2ef912cbbe43b85b45a8a97f8d240318718a (diff) | |
parent | a92b38934a2d00c13ee4d1969d994da15e0857ab (diff) | |
download | rneovim-c45b5e2c5b0f02742099ebccc44462fe4203e99c.tar.gz rneovim-c45b5e2c5b0f02742099ebccc44462fe4203e99c.tar.bz2 rneovim-c45b5e2c5b0f02742099ebccc44462fe4203e99c.zip |
Merge pull request #22743 from bfredl/luaequals
feat(lua): allow `:=expr` as a shorter version of `:lua =expr`
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/cmdexpand.c | 1 | ||||
-rw-r--r-- | src/nvim/ex_cmds.lua | 2 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 9 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 9 |
4 files changed, 14 insertions, 7 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 220cb4cf93..bce28fa449 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2141,6 +2141,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa return set_context_in_scriptnames_cmd(xp, arg); case CMD_lua: + case CMD_equal: xp->xp_context = EXPAND_LUA; break; diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index c8b6ceab69..2fd50a18d3 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -3319,7 +3319,7 @@ module.cmds = { { command='=', enum='CMD_equal', - flags=bit.bor(RANGE, TRLBAR, DFLALL, FLAGS, CMDWIN, LOCK_OK), + flags=bit.bor(RANGE, EXTRA, DFLALL, ARGOPT, CMDWIN, LOCK_OK), addr_type='ADDR_LINES', func='ex_equal', }, diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 7b94e3184b..6a259b75fb 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5658,8 +5658,13 @@ static void ex_pwd(exarg_T *eap) /// ":=". static void ex_equal(exarg_T *eap) { - smsg("%" PRId64, (int64_t)eap->line2); - ex_may_print(eap); + if (*eap->arg != NUL && *eap->arg != '|') { + // equivalent to :lua= expr + ex_lua(eap); + } else { + eap->nextcmd = find_nextcmd(eap->arg); + smsg("%" PRId64, (int64_t)eap->line2); + } } static void ex_sleep(exarg_T *eap) diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 3616f1f69f..7e331a097f 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1621,14 +1621,15 @@ void ex_lua(exarg_T *const eap) xfree(code); return; } - // When =expr is used transform it to print(vim.inspect(expr)) - if (code[0] == '=') { - len += sizeof("vim.print()") - sizeof("="); + // When =expr is used transform it to vim.print(expr) + if (eap->cmdidx == CMD_equal || code[0] == '=') { + size_t off = (eap->cmdidx == CMD_equal) ? 0 : 1; + len += sizeof("vim.print()") - 1 - off; // code_buf needs to be 1 char larger then len for null byte in the end. // lua nlua_typval_exec doesn't expect null terminated string so len // needs to end before null byte. char *code_buf = xmallocz(len); - vim_snprintf(code_buf, len + 1, "vim.print(%s)", code + 1); + vim_snprintf(code_buf, len + 1, "vim.print(%s)", code + off); xfree(code); code = code_buf; } |