mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
Merge pull request #18896 from famiu/fix/nvim_create_user_command/smods
fix(nvim_create_user_command): make `smods` work with `nvim_cmd`
This commit is contained in:
@@ -1241,11 +1241,13 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (HAS_KEY(mods.verbose)) {
|
if (HAS_KEY(mods.verbose)) {
|
||||||
if (mods.verbose.type != kObjectTypeInteger || mods.verbose.data.integer <= 0) {
|
if (mods.verbose.type != kObjectTypeInteger) {
|
||||||
VALIDATION_ERROR("'mods.verbose' must be a non-negative Integer");
|
VALIDATION_ERROR("'mods.verbose' must be a Integer");
|
||||||
}
|
} else if (mods.verbose.data.integer >= 0) {
|
||||||
|
// Silently ignore negative integers to allow mods.verbose to be set to -1.
|
||||||
cmdinfo.verbose = mods.verbose.data.integer;
|
cmdinfo.verbose = mods.verbose.data.integer;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool vertical;
|
bool vertical;
|
||||||
OBJ_TO_BOOL(vertical, mods.vertical, false, "'mods.vertical'");
|
OBJ_TO_BOOL(vertical, mods.vertical, false, "'mods.vertical'");
|
||||||
@@ -1256,7 +1258,9 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error
|
|||||||
VALIDATION_ERROR("'mods.split' must be a String");
|
VALIDATION_ERROR("'mods.split' must be a String");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STRCMP(mods.split.data.string.data, "aboveleft") == 0
|
if (*mods.split.data.string.data == NUL) {
|
||||||
|
// Empty string, do nothing.
|
||||||
|
} else if (STRCMP(mods.split.data.string.data, "aboveleft") == 0
|
||||||
|| STRCMP(mods.split.data.string.data, "leftabove") == 0) {
|
|| STRCMP(mods.split.data.string.data, "leftabove") == 0) {
|
||||||
cmdinfo.cmdmod.split |= WSP_ABOVE;
|
cmdinfo.cmdmod.split |= WSP_ABOVE;
|
||||||
} else if (STRCMP(mods.split.data.string.data, "belowright") == 0
|
} else if (STRCMP(mods.split.data.string.data, "belowright") == 0
|
||||||
|
@@ -1919,7 +1919,8 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview)
|
|||||||
|
|
||||||
lua_pushinteger(lstate, cmdmod.tab);
|
lua_pushinteger(lstate, cmdmod.tab);
|
||||||
lua_setfield(lstate, -2, "tab");
|
lua_setfield(lstate, -2, "tab");
|
||||||
lua_pushinteger(lstate, p_verbose);
|
|
||||||
|
lua_pushinteger(lstate, eap->verbose_save != -1 ? p_verbose : -1);
|
||||||
lua_setfield(lstate, -2, "verbose");
|
lua_setfield(lstate, -2, "verbose");
|
||||||
|
|
||||||
if (cmdmod.split & WSP_ABOVE) {
|
if (cmdmod.split & WSP_ABOVE) {
|
||||||
@@ -1937,9 +1938,9 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview)
|
|||||||
|
|
||||||
lua_pushboolean(lstate, cmdmod.split & WSP_VERT);
|
lua_pushboolean(lstate, cmdmod.split & WSP_VERT);
|
||||||
lua_setfield(lstate, -2, "vertical");
|
lua_setfield(lstate, -2, "vertical");
|
||||||
lua_pushboolean(lstate, msg_silent != 0);
|
lua_pushboolean(lstate, eap->save_msg_silent != -1 ? (msg_silent != 0) : 0);
|
||||||
lua_setfield(lstate, -2, "silent");
|
lua_setfield(lstate, -2, "silent");
|
||||||
lua_pushboolean(lstate, emsg_silent != 0);
|
lua_pushboolean(lstate, eap->did_esilent);
|
||||||
lua_setfield(lstate, -2, "emsg_silent");
|
lua_setfield(lstate, -2, "emsg_silent");
|
||||||
lua_pushboolean(lstate, eap->did_sandbox);
|
lua_pushboolean(lstate, eap->did_sandbox);
|
||||||
lua_setfield(lstate, -2, "sandbox");
|
lua_setfield(lstate, -2, "sandbox");
|
||||||
|
@@ -136,7 +136,7 @@ describe('nvim_create_user_command', function()
|
|||||||
silent = false,
|
silent = false,
|
||||||
split = "",
|
split = "",
|
||||||
tab = 0,
|
tab = 0,
|
||||||
verbose = 0,
|
verbose = -1,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
},
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
@@ -170,7 +170,7 @@ describe('nvim_create_user_command', function()
|
|||||||
silent = false,
|
silent = false,
|
||||||
split = "",
|
split = "",
|
||||||
tab = 0,
|
tab = 0,
|
||||||
verbose = 0,
|
verbose = -1,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
},
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
@@ -204,7 +204,7 @@ describe('nvim_create_user_command', function()
|
|||||||
silent = false,
|
silent = false,
|
||||||
split = "",
|
split = "",
|
||||||
tab = 0,
|
tab = 0,
|
||||||
verbose = 0,
|
verbose = -1,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
},
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
@@ -238,7 +238,7 @@ describe('nvim_create_user_command', function()
|
|||||||
silent = false,
|
silent = false,
|
||||||
split = "botright",
|
split = "botright",
|
||||||
tab = 0,
|
tab = 0,
|
||||||
verbose = 0,
|
verbose = -1,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
},
|
},
|
||||||
range = 1,
|
range = 1,
|
||||||
@@ -272,7 +272,7 @@ describe('nvim_create_user_command', function()
|
|||||||
silent = false,
|
silent = false,
|
||||||
split = "",
|
split = "",
|
||||||
tab = 0,
|
tab = 0,
|
||||||
verbose = 0,
|
verbose = -1,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
},
|
},
|
||||||
range = 1,
|
range = 1,
|
||||||
@@ -306,7 +306,7 @@ describe('nvim_create_user_command', function()
|
|||||||
silent = false,
|
silent = false,
|
||||||
split = "",
|
split = "",
|
||||||
tab = 0,
|
tab = 0,
|
||||||
verbose = 0,
|
verbose = -1,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
},
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
@@ -352,7 +352,7 @@ describe('nvim_create_user_command', function()
|
|||||||
silent = false,
|
silent = false,
|
||||||
split = "",
|
split = "",
|
||||||
tab = 0,
|
tab = 0,
|
||||||
verbose = 0,
|
verbose = -1,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
},
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
@@ -418,6 +418,16 @@ describe('nvim_create_user_command', function()
|
|||||||
vim.api.nvim_create_user_command('💩', 'echo "hi"', {})
|
vim.api.nvim_create_user_command('💩', 'echo "hi"', {})
|
||||||
]]))
|
]]))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('smods can be used with nvim_cmd', function()
|
||||||
|
exec_lua[[
|
||||||
|
vim.api.nvim_create_user_command('MyEcho', function(opts)
|
||||||
|
vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {})
|
||||||
|
end, {})
|
||||||
|
]]
|
||||||
|
|
||||||
|
eq("3", meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true }))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('nvim_del_user_command', function()
|
describe('nvim_del_user_command', function()
|
||||||
|
Reference in New Issue
Block a user