mirror of
https://github.com/neovim/neovim.git
synced 2025-09-23 03:28:33 +00:00
Merge pull request #18792 from famiu/feat/nvim_create_user_command/smods
feat(api): pass structured modifiers to commands
This commit is contained in:
@@ -743,6 +743,9 @@ nvim_create_user_command({name}, {command}, {*opts})
|
|||||||
specified |<reg>|
|
specified |<reg>|
|
||||||
• mods: (string) Command modifiers, if any
|
• mods: (string) Command modifiers, if any
|
||||||
|<mods>|
|
|<mods>|
|
||||||
|
• smods: (table) Command modifiers in a
|
||||||
|
structured format. Has the same structure as
|
||||||
|
the "mods" key of |nvim_parse_cmd()|.
|
||||||
{opts} Optional command attributes. See
|
{opts} Optional command attributes. See
|
||||||
|command-attributes| for more details. To use
|
|command-attributes| for more details. To use
|
||||||
boolean attributes (such as |:command-bang| or
|
boolean attributes (such as |:command-bang| or
|
||||||
|
@@ -2501,6 +2501,8 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *
|
|||||||
/// - count: (number) Any count supplied |<count>|
|
/// - count: (number) Any count supplied |<count>|
|
||||||
/// - reg: (string) The optional register, if specified |<reg>|
|
/// - reg: (string) The optional register, if specified |<reg>|
|
||||||
/// - mods: (string) Command modifiers, if any |<mods>|
|
/// - mods: (string) Command modifiers, if any |<mods>|
|
||||||
|
/// - smods: (table) Command modifiers in a structured format. Has the same
|
||||||
|
/// structure as the "mods" key of |nvim_parse_cmd()|.
|
||||||
/// @param opts Optional command attributes. See |command-attributes| for more details. To use
|
/// @param opts Optional command attributes. See |command-attributes| for more details. To use
|
||||||
/// boolean attributes (such as |:command-bang| or |:command-bar|) set the value to
|
/// boolean attributes (such as |:command-bang| or |:command-bar|) set the value to
|
||||||
/// "true". In addition to the string options listed in |:command-complete|, the
|
/// "true". In addition to the string options listed in |:command-complete|, the
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#include "nvim/undo.h"
|
#include "nvim/undo.h"
|
||||||
#include "nvim/version.h"
|
#include "nvim/version.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
|
#include "nvim/window.h"
|
||||||
|
|
||||||
static int in_fast_callback = 0;
|
static int in_fast_callback = 0;
|
||||||
|
|
||||||
@@ -1913,6 +1914,61 @@ void nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap)
|
|||||||
lua_pushstring(lstate, buf);
|
lua_pushstring(lstate, buf);
|
||||||
lua_setfield(lstate, -2, "mods");
|
lua_setfield(lstate, -2, "mods");
|
||||||
|
|
||||||
|
lua_newtable(lstate); // smods table
|
||||||
|
|
||||||
|
lua_pushinteger(lstate, cmdmod.tab);
|
||||||
|
lua_setfield(lstate, -2, "tab");
|
||||||
|
lua_pushinteger(lstate, p_verbose);
|
||||||
|
lua_setfield(lstate, -2, "verbose");
|
||||||
|
|
||||||
|
if (cmdmod.split & WSP_ABOVE) {
|
||||||
|
lua_pushstring(lstate, "aboveleft");
|
||||||
|
} else if (cmdmod.split & WSP_BELOW) {
|
||||||
|
lua_pushstring(lstate, "belowright");
|
||||||
|
} else if (cmdmod.split & WSP_TOP) {
|
||||||
|
lua_pushstring(lstate, "topleft");
|
||||||
|
} else if (cmdmod.split & WSP_BOT) {
|
||||||
|
lua_pushstring(lstate, "botright");
|
||||||
|
} else {
|
||||||
|
lua_pushstring(lstate, "");
|
||||||
|
}
|
||||||
|
lua_setfield(lstate, -2, "split");
|
||||||
|
|
||||||
|
lua_pushboolean(lstate, cmdmod.split & WSP_VERT);
|
||||||
|
lua_setfield(lstate, -2, "vertical");
|
||||||
|
lua_pushboolean(lstate, msg_silent != 0);
|
||||||
|
lua_setfield(lstate, -2, "silent");
|
||||||
|
lua_pushboolean(lstate, emsg_silent != 0);
|
||||||
|
lua_setfield(lstate, -2, "emsg_silent");
|
||||||
|
lua_pushboolean(lstate, eap->did_sandbox);
|
||||||
|
lua_setfield(lstate, -2, "sandbox");
|
||||||
|
lua_pushboolean(lstate, cmdmod.save_ei != NULL);
|
||||||
|
lua_setfield(lstate, -2, "noautocmd");
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool *set;
|
||||||
|
char *name;
|
||||||
|
} mod_entry_T;
|
||||||
|
static mod_entry_T mod_entries[] = {
|
||||||
|
{ &cmdmod.browse, "browse" },
|
||||||
|
{ &cmdmod.confirm, "confirm" },
|
||||||
|
{ &cmdmod.hide, "hide" },
|
||||||
|
{ &cmdmod.keepalt, "keepalt" },
|
||||||
|
{ &cmdmod.keepjumps, "keepjumps" },
|
||||||
|
{ &cmdmod.keepmarks, "keepmarks" },
|
||||||
|
{ &cmdmod.keeppatterns, "keeppatterns" },
|
||||||
|
{ &cmdmod.lockmarks, "lockmarks" },
|
||||||
|
{ &cmdmod.noswapfile, "noswapfile" }
|
||||||
|
};
|
||||||
|
|
||||||
|
// The modifiers that are simple flags
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(mod_entries); i++) {
|
||||||
|
lua_pushboolean(lstate, *mod_entries[i].set);
|
||||||
|
lua_setfield(lstate, -2, mod_entries[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_setfield(lstate, -2, "smods");
|
||||||
|
|
||||||
if (nlua_pcall(lstate, 1, 0)) {
|
if (nlua_pcall(lstate, 1, 0)) {
|
||||||
nlua_error(lstate, _("Error executing Lua callback: %.*s"));
|
nlua_error(lstate, _("Error executing Lua callback: %.*s"));
|
||||||
}
|
}
|
||||||
|
@@ -120,6 +120,25 @@ describe('nvim_create_user_command', function()
|
|||||||
line1 = 1,
|
line1 = 1,
|
||||||
line2 = 1,
|
line2 = 1,
|
||||||
mods = "",
|
mods = "",
|
||||||
|
smods = {
|
||||||
|
browse = false,
|
||||||
|
confirm = false,
|
||||||
|
emsg_silent = false,
|
||||||
|
hide = false,
|
||||||
|
keepalt = false,
|
||||||
|
keepjumps = false,
|
||||||
|
keepmarks = false,
|
||||||
|
keeppatterns = false,
|
||||||
|
lockmarks = false,
|
||||||
|
noautocmd = false,
|
||||||
|
noswapfile = false,
|
||||||
|
sandbox = false,
|
||||||
|
silent = false,
|
||||||
|
split = "",
|
||||||
|
tab = 0,
|
||||||
|
verbose = 0,
|
||||||
|
vertical = false,
|
||||||
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
count = 2,
|
count = 2,
|
||||||
reg = "",
|
reg = "",
|
||||||
@@ -135,6 +154,25 @@ describe('nvim_create_user_command', function()
|
|||||||
line1 = 1,
|
line1 = 1,
|
||||||
line2 = 1,
|
line2 = 1,
|
||||||
mods = "",
|
mods = "",
|
||||||
|
smods = {
|
||||||
|
browse = false,
|
||||||
|
confirm = false,
|
||||||
|
emsg_silent = false,
|
||||||
|
hide = false,
|
||||||
|
keepalt = false,
|
||||||
|
keepjumps = false,
|
||||||
|
keepmarks = false,
|
||||||
|
keeppatterns = false,
|
||||||
|
lockmarks = false,
|
||||||
|
noautocmd = false,
|
||||||
|
noswapfile = false,
|
||||||
|
sandbox = false,
|
||||||
|
silent = false,
|
||||||
|
split = "",
|
||||||
|
tab = 0,
|
||||||
|
verbose = 0,
|
||||||
|
vertical = false,
|
||||||
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
count = 2,
|
count = 2,
|
||||||
reg = "",
|
reg = "",
|
||||||
@@ -150,6 +188,25 @@ describe('nvim_create_user_command', function()
|
|||||||
line1 = 1,
|
line1 = 1,
|
||||||
line2 = 1,
|
line2 = 1,
|
||||||
mods = "",
|
mods = "",
|
||||||
|
smods = {
|
||||||
|
browse = false,
|
||||||
|
confirm = false,
|
||||||
|
emsg_silent = false,
|
||||||
|
hide = false,
|
||||||
|
keepalt = false,
|
||||||
|
keepjumps = false,
|
||||||
|
keepmarks = false,
|
||||||
|
keeppatterns = false,
|
||||||
|
lockmarks = false,
|
||||||
|
noautocmd = false,
|
||||||
|
noswapfile = false,
|
||||||
|
sandbox = false,
|
||||||
|
silent = false,
|
||||||
|
split = "",
|
||||||
|
tab = 0,
|
||||||
|
verbose = 0,
|
||||||
|
vertical = false,
|
||||||
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
count = 2,
|
count = 2,
|
||||||
reg = "",
|
reg = "",
|
||||||
@@ -165,6 +222,25 @@ describe('nvim_create_user_command', function()
|
|||||||
line1 = 10,
|
line1 = 10,
|
||||||
line2 = 10,
|
line2 = 10,
|
||||||
mods = "botright",
|
mods = "botright",
|
||||||
|
smods = {
|
||||||
|
browse = false,
|
||||||
|
confirm = false,
|
||||||
|
emsg_silent = false,
|
||||||
|
hide = false,
|
||||||
|
keepalt = false,
|
||||||
|
keepjumps = false,
|
||||||
|
keepmarks = false,
|
||||||
|
keeppatterns = false,
|
||||||
|
lockmarks = false,
|
||||||
|
noautocmd = false,
|
||||||
|
noswapfile = false,
|
||||||
|
sandbox = false,
|
||||||
|
silent = false,
|
||||||
|
split = "botright",
|
||||||
|
tab = 0,
|
||||||
|
verbose = 0,
|
||||||
|
vertical = false,
|
||||||
|
},
|
||||||
range = 1,
|
range = 1,
|
||||||
count = 10,
|
count = 10,
|
||||||
reg = "",
|
reg = "",
|
||||||
@@ -180,6 +256,25 @@ describe('nvim_create_user_command', function()
|
|||||||
line1 = 1,
|
line1 = 1,
|
||||||
line2 = 42,
|
line2 = 42,
|
||||||
mods = "",
|
mods = "",
|
||||||
|
smods = {
|
||||||
|
browse = false,
|
||||||
|
confirm = false,
|
||||||
|
emsg_silent = false,
|
||||||
|
hide = false,
|
||||||
|
keepalt = false,
|
||||||
|
keepjumps = false,
|
||||||
|
keepmarks = false,
|
||||||
|
keeppatterns = false,
|
||||||
|
lockmarks = false,
|
||||||
|
noautocmd = false,
|
||||||
|
noswapfile = false,
|
||||||
|
sandbox = false,
|
||||||
|
silent = false,
|
||||||
|
split = "",
|
||||||
|
tab = 0,
|
||||||
|
verbose = 0,
|
||||||
|
vertical = false,
|
||||||
|
},
|
||||||
range = 1,
|
range = 1,
|
||||||
count = 42,
|
count = 42,
|
||||||
reg = "",
|
reg = "",
|
||||||
@@ -195,6 +290,25 @@ describe('nvim_create_user_command', function()
|
|||||||
line1 = 1,
|
line1 = 1,
|
||||||
line2 = 1,
|
line2 = 1,
|
||||||
mods = "",
|
mods = "",
|
||||||
|
smods = {
|
||||||
|
browse = false,
|
||||||
|
confirm = false,
|
||||||
|
emsg_silent = false,
|
||||||
|
hide = false,
|
||||||
|
keepalt = false,
|
||||||
|
keepjumps = false,
|
||||||
|
keepmarks = false,
|
||||||
|
keeppatterns = false,
|
||||||
|
lockmarks = false,
|
||||||
|
noautocmd = false,
|
||||||
|
noswapfile = false,
|
||||||
|
sandbox = false,
|
||||||
|
silent = false,
|
||||||
|
split = "",
|
||||||
|
tab = 0,
|
||||||
|
verbose = 0,
|
||||||
|
vertical = false,
|
||||||
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
count = 2,
|
count = 2,
|
||||||
reg = "",
|
reg = "",
|
||||||
@@ -222,6 +336,25 @@ describe('nvim_create_user_command', function()
|
|||||||
line1 = 1,
|
line1 = 1,
|
||||||
line2 = 1,
|
line2 = 1,
|
||||||
mods = "",
|
mods = "",
|
||||||
|
smods = {
|
||||||
|
browse = false,
|
||||||
|
confirm = false,
|
||||||
|
emsg_silent = false,
|
||||||
|
hide = false,
|
||||||
|
keepalt = false,
|
||||||
|
keepjumps = false,
|
||||||
|
keepmarks = false,
|
||||||
|
keeppatterns = false,
|
||||||
|
lockmarks = false,
|
||||||
|
noautocmd = false,
|
||||||
|
noswapfile = false,
|
||||||
|
sandbox = false,
|
||||||
|
silent = false,
|
||||||
|
split = "",
|
||||||
|
tab = 0,
|
||||||
|
verbose = 0,
|
||||||
|
vertical = false,
|
||||||
|
},
|
||||||
range = 0,
|
range = 0,
|
||||||
count = 2,
|
count = 2,
|
||||||
reg = "",
|
reg = "",
|
||||||
|
Reference in New Issue
Block a user