2023-05-23 13:30:30 +01:00
|
|
|
{
|
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
|
|
|
config,
|
2023-05-23 13:30:30 +01:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
commandAttributes = types.submodule {
|
|
|
|
options = {
|
|
|
|
command = mkOption {
|
|
|
|
type = types.str;
|
2024-02-11 12:51:34 +00:00
|
|
|
description = "The command to run.";
|
2023-05-23 13:30:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
nargs = helpers.mkNullOrOption (types.enum ["0" "1" "*" "?" "+"]) ''
|
|
|
|
The number of arguments to expect, see :h command-nargs.
|
|
|
|
'';
|
2024-01-01 23:33:53 +01:00
|
|
|
complete = helpers.mkNullOrOption (with types; either str helpers.nixvimTypes.rawLua) ''
|
2023-05-23 13:30:30 +01:00
|
|
|
Tab-completion behaviour, see :h command-complete.
|
|
|
|
'';
|
|
|
|
range = helpers.mkNullOrOption (with types; oneOf [bool int (enum ["%"])]) ''
|
|
|
|
Whether the command accepts a range, see :h command-range.
|
|
|
|
'';
|
|
|
|
count = helpers.mkNullOrOption (with types; either bool int) ''
|
|
|
|
Whether the command accepts a count, see :h command-range.
|
|
|
|
'';
|
|
|
|
addr = helpers.mkNullOrOption types.str ''
|
|
|
|
Whether special characters relate to other things, see :h command-addr.
|
|
|
|
'';
|
2024-02-11 12:51:34 +00:00
|
|
|
bang = helpers.defaultNullOpts.mkBool false "Whether this command can take a bang (!).";
|
|
|
|
bar = helpers.defaultNullOpts.mkBool false "Whether this command can be followed by a \"|\" and another command.";
|
|
|
|
register = helpers.defaultNullOpts.mkBool false "The first argument to the command can be an optional register.";
|
|
|
|
keepscript = helpers.defaultNullOpts.mkBool false "Do not use the location of where the user command was defined for verbose messages, use the location of where the command was invoked.";
|
|
|
|
force = helpers.defaultNullOpts.mkBool false "Overwrite an existing user command.";
|
|
|
|
desc = helpers.defaultNullOpts.mkStr "" "A description of the command.";
|
2023-05-23 13:30:30 +01:00
|
|
|
|
|
|
|
# TODO: command-preview, need to grab a function here.
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.userCommands = mkOption {
|
|
|
|
type = types.attrsOf commandAttributes;
|
|
|
|
default = {};
|
2024-02-11 12:51:34 +00:00
|
|
|
description = "A list of user commands to add to the configuration.";
|
2023-05-23 13:30:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = let
|
|
|
|
cleanupCommand = _: cmd: {
|
|
|
|
inherit (cmd) command;
|
|
|
|
options = filterAttrs (name: _: name != "command") cmd;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
mkIf (config.userCommands != {}) {
|
|
|
|
extraConfigLua = helpers.wrapDo ''
|
|
|
|
local cmds = ${helpers.toLuaObject (mapAttrs cleanupCommand config.userCommands)};
|
|
|
|
for name,cmd in pairs(cmds) do
|
2024-01-20 14:45:30 +01:00
|
|
|
vim.api.nvim_create_user_command(name, cmd.command, cmd.options or {})
|
2023-05-23 13:30:30 +01:00
|
|
|
end
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|