mirror of
https://github.com/neovim/neovim.git
synced 2025-10-02 16:08:36 +00:00
Merge pull request #20991 from famiu/feat/api/nvim_cmd/command-name
feat(api): add command name to Lua command callback opts
This commit is contained in:
@@ -1757,6 +1757,7 @@ nvim_create_user_command({name}, {command}, {*opts})
|
|||||||
executed. When called from Lua, the command can also be a
|
executed. When called from Lua, the command can also be a
|
||||||
Lua function. The function is called with a single table
|
Lua function. The function is called with a single table
|
||||||
argument that contains the following keys:
|
argument that contains the following keys:
|
||||||
|
• name: (string) Command name
|
||||||
• args: (string) The args passed to the command, if any
|
• args: (string) The args passed to the command, if any
|
||||||
|<args>|
|
|<args>|
|
||||||
• fargs: (table) The args split by unescaped whitespace
|
• fargs: (table) The args split by unescaped whitespace
|
||||||
|
@@ -884,6 +884,7 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin
|
|||||||
/// @param command Replacement command to execute when this user command is executed. When called
|
/// @param command Replacement command to execute when this user command is executed. When called
|
||||||
/// from Lua, the command can also be a Lua function. The function is called with a
|
/// from Lua, the command can also be a Lua function. The function is called with a
|
||||||
/// single table argument that contains the following keys:
|
/// single table argument that contains the following keys:
|
||||||
|
/// - name: (string) Command name
|
||||||
/// - args: (string) The args passed to the command, if any |<args>|
|
/// - args: (string) The args passed to the command, if any |<args>|
|
||||||
/// - fargs: (table) The args split by unescaped whitespace (when more than one
|
/// - fargs: (table) The args split by unescaped whitespace (when more than one
|
||||||
/// argument is allowed), if any |<f-args>|
|
/// argument is allowed), if any |<f-args>|
|
||||||
|
@@ -1985,6 +1985,9 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview)
|
|||||||
nlua_pushref(lstate, preview ? cmd->uc_preview_luaref : cmd->uc_luaref);
|
nlua_pushref(lstate, preview ? cmd->uc_preview_luaref : cmd->uc_luaref);
|
||||||
|
|
||||||
lua_newtable(lstate);
|
lua_newtable(lstate);
|
||||||
|
lua_pushstring(lstate, cmd->uc_name);
|
||||||
|
lua_setfield(lstate, -2, "name");
|
||||||
|
|
||||||
lua_pushboolean(lstate, eap->forceit == 1);
|
lua_pushboolean(lstate, eap->forceit == 1);
|
||||||
lua_setfield(lstate, -2, "bang");
|
lua_setfield(lstate, -2, "bang");
|
||||||
|
|
||||||
|
@@ -114,6 +114,7 @@ describe('nvim_create_user_command', function()
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithLuaCallback",
|
||||||
args = [[this\ is a\ test]],
|
args = [[this\ is a\ test]],
|
||||||
fargs = {"this ", "is", "a test"},
|
fargs = {"this ", "is", "a test"},
|
||||||
bang = false,
|
bang = false,
|
||||||
@@ -150,6 +151,7 @@ describe('nvim_create_user_command', function()
|
|||||||
]=])
|
]=])
|
||||||
|
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithLuaCallback",
|
||||||
args = [[this includes\ a backslash: \\]],
|
args = [[this includes\ a backslash: \\]],
|
||||||
fargs = {"this", "includes a", "backslash:", "\\"},
|
fargs = {"this", "includes a", "backslash:", "\\"},
|
||||||
bang = false,
|
bang = false,
|
||||||
@@ -186,6 +188,7 @@ describe('nvim_create_user_command', function()
|
|||||||
]=])
|
]=])
|
||||||
|
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithLuaCallback",
|
||||||
args = "a\\b",
|
args = "a\\b",
|
||||||
fargs = {"a\\b"},
|
fargs = {"a\\b"},
|
||||||
bang = false,
|
bang = false,
|
||||||
@@ -222,6 +225,7 @@ describe('nvim_create_user_command', function()
|
|||||||
]=])
|
]=])
|
||||||
|
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithLuaCallback",
|
||||||
args = 'h\tey ',
|
args = 'h\tey ',
|
||||||
fargs = {[[h]], [[ey]]},
|
fargs = {[[h]], [[ey]]},
|
||||||
bang = true,
|
bang = true,
|
||||||
@@ -258,6 +262,7 @@ describe('nvim_create_user_command', function()
|
|||||||
]=])
|
]=])
|
||||||
|
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithLuaCallback",
|
||||||
args = "h",
|
args = "h",
|
||||||
fargs = {"h"},
|
fargs = {"h"},
|
||||||
bang = false,
|
bang = false,
|
||||||
@@ -294,6 +299,7 @@ describe('nvim_create_user_command', function()
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithLuaCallback",
|
||||||
args = "",
|
args = "",
|
||||||
fargs = {}, -- fargs works without args
|
fargs = {}, -- fargs works without args
|
||||||
bang = false,
|
bang = false,
|
||||||
@@ -342,6 +348,7 @@ describe('nvim_create_user_command', function()
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithOneOrNoArg",
|
||||||
args = "hello I'm one argument",
|
args = "hello I'm one argument",
|
||||||
fargs = {"hello I'm one argument"}, -- Doesn't split args
|
fargs = {"hello I'm one argument"}, -- Doesn't split args
|
||||||
bang = false,
|
bang = false,
|
||||||
@@ -379,6 +386,7 @@ describe('nvim_create_user_command', function()
|
|||||||
|
|
||||||
-- f-args is an empty table if no args were passed
|
-- f-args is an empty table if no args were passed
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithOneOrNoArg",
|
||||||
args = "",
|
args = "",
|
||||||
fargs = {},
|
fargs = {},
|
||||||
bang = false,
|
bang = false,
|
||||||
@@ -427,6 +435,7 @@ describe('nvim_create_user_command', function()
|
|||||||
})
|
})
|
||||||
]]
|
]]
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithNoArgs",
|
||||||
args = "",
|
args = "",
|
||||||
fargs = {},
|
fargs = {},
|
||||||
bang = false,
|
bang = false,
|
||||||
@@ -463,6 +472,7 @@ describe('nvim_create_user_command', function()
|
|||||||
]])
|
]])
|
||||||
-- register can be specified
|
-- register can be specified
|
||||||
eq({
|
eq({
|
||||||
|
name = "CommandWithNoArgs",
|
||||||
args = "",
|
args = "",
|
||||||
fargs = {},
|
fargs = {},
|
||||||
bang = false,
|
bang = false,
|
||||||
|
Reference in New Issue
Block a user