Module bex.autoload.command
:command support.
Provides overrides for bex.cmd.command.
The last argument, the replacement text, may be a callable instead of a string. If so, it will be called with a table corresponding to the escape sequences defined by Vim, e.g.:
{
args = "arg1 arg2 ...", -- arguments as a raw string
fargs = {"arg1", "arg2", ...}, -- arguments as a parsed list
bang = false, -- command invoked with !
count = 5, -- count argument
line1 = 22, -- first line of range
line2 = 45, -- second line of range
range = 2, -- arity of range (0, 1, 2)
mods = { -- enabled modifiers (verbose, topleft, etc.)
verbose = true
}
}
To use a function for custom completion, pass "-complete=custom" or
"-complete=customlist" followed by the callable as arguments.
It will be invoked with the usual A, L, P arguments specified in
the Vim documentation. The following trivial example completes all arguments
as foobar. The command itself simply prints its argument table:
bex.cmd.command(
'-complete=custom', function(a, l, p) return "foobar" end,
'-nargs=*',
"MyCommand", function(args) print(vim.inspect(args)) end)