diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-03-20 21:11:10 +0100 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-03-22 09:10:04 +0100 |
commit | a92b38934a2d00c13ee4d1969d994da15e0857ab (patch) | |
tree | f201f6bb3718b4788403b986664e596f809d5a98 /src/nvim/lua/executor.c | |
parent | 4cba53e09e6e9d9cf06e87431146b9707347bcd6 (diff) | |
download | rneovim-a92b38934a2d00c13ee4d1969d994da15e0857ab.tar.gz rneovim-a92b38934a2d00c13ee4d1969d994da15e0857ab.tar.bz2 rneovim-a92b38934a2d00c13ee4d1969d994da15e0857ab.zip |
feat(lua): allow `:=expr` as a shorter version of `:lua =expr`
existing behavior of
:=
and
:[range]=
are unchanged. `|` is still allowed with this usage.
However,
:=p
and similar are changed in a way which could be construed as a breaking
change. Allowing |ex-flags| for := in the first place was a mistake as
any form of := DOES NOT MOVE THE CURSOR. So it would print one line number
and then print a completely different line contents after that.
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 9 |
1 files changed, 5 insertions, 4 deletions
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; } |