aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorluukvbaal <luukvbaal@gmail.com>2024-01-27 02:00:50 +0100
committerGitHub <noreply@github.com>2024-01-26 17:00:50 -0800
commitc2433589dca022a7f40cdcbd0cd1ad8aba6ee4a9 (patch)
tree4ec42e5d42d7c0bb5e674af2e94e1fe3eac2c837 /src
parent0892c080d16776366a2fe289f9083cdc532ec56c (diff)
downloadrneovim-c2433589dca022a7f40cdcbd0cd1ad8aba6ee4a9.tar.gz
rneovim-c2433589dca022a7f40cdcbd0cd1ad8aba6ee4a9.tar.bz2
rneovim-c2433589dca022a7f40cdcbd0cd1ad8aba6ee4a9.zip
feat(ex_cmds): ranged :lua #27167
:{range}lua executes the specified lines in the current buffer as Lua code, regardless of its extension or 'filetype'. Close #27103
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_cmds.lua2
-rw-r--r--src/nvim/lua/executor.c9
-rw-r--r--src/nvim/runtime.c9
3 files changed, 15 insertions, 5 deletions
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 551d228862..1318eda5eb 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -1612,7 +1612,7 @@ module.cmds = {
},
{
command = 'lua',
- flags = bit.bor(RANGE, EXTRA, NEEDARG, CMDWIN, LOCK_OK),
+ flags = bit.bor(RANGE, EXTRA, CMDWIN, LOCK_OK),
addr_type = 'ADDR_LINES',
func = 'ex_lua',
},
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index f48cab6739..3139e924a1 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1649,6 +1649,15 @@ bool nlua_is_deferred_safe(void)
void ex_lua(exarg_T *const eap)
FUNC_ATTR_NONNULL_ALL
{
+ if (eap->addr_count > 0 || *eap->arg == NUL) {
+ if (eap->addr_count > 0 && *eap->arg == NUL) {
+ cmd_source_buffer(eap, true);
+ } else {
+ semsg(_(e_invarg2), "exactly one of {chunk} and {range} required");
+ }
+ return;
+ }
+
size_t len;
char *code = script_get(eap, &len);
if (eap->skip || code == NULL) {
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 3f8e467118..77a22b6fd1 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -1779,7 +1779,7 @@ freeall:
static void cmd_source(char *fname, exarg_T *eap)
{
if (eap != NULL && *fname == NUL) {
- cmd_source_buffer(eap);
+ cmd_source_buffer(eap, false);
} else if (eap != NULL && eap->forceit) {
// ":source!": read Normal mode commands
// Need to execute the commands directly. This is required at least
@@ -1989,7 +1989,7 @@ static int source_using_linegetter(void *cookie, LineGetter fgetline, const char
return retval;
}
-static void cmd_source_buffer(const exarg_T *const eap)
+void cmd_source_buffer(const exarg_T *const eap, bool ex_lua)
FUNC_ATTR_NONNULL_ALL
{
if (curbuf == NULL) {
@@ -2012,9 +2012,10 @@ static void cmd_source_buffer(const exarg_T *const eap)
.buf = ga.ga_data,
.offset = 0,
};
- if (strequal(curbuf->b_p_ft, "lua")
+ if (ex_lua || strequal(curbuf->b_p_ft, "lua")
|| (curbuf->b_fname && path_with_extension(curbuf->b_fname, "lua"))) {
- nlua_source_using_linegetter(get_str_line, (void *)&cookie, ":source (no file)");
+ char *name = ex_lua ? ":lua (no file)" : ":source (no file)";
+ nlua_source_using_linegetter(get_str_line, (void *)&cookie, name);
} else {
source_using_linegetter((void *)&cookie, get_str_line, ":source (no file)");
}