2023-02-20 11:42:13 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
helpers = import ../lib/helpers.nix {inherit lib;};
|
|
|
|
in {
|
2022-09-18 11:19:23 +01:00
|
|
|
options = {
|
2023-09-10 09:59:22 +02:00
|
|
|
maps =
|
|
|
|
mapAttrs
|
|
|
|
(
|
|
|
|
modeName: modeProps: let
|
|
|
|
desc = modeProps.desc or modeName;
|
|
|
|
in
|
|
|
|
mkOption {
|
|
|
|
description = "Mappings for ${desc} mode";
|
|
|
|
type = with types;
|
|
|
|
attrsOf
|
|
|
|
(
|
|
|
|
either
|
|
|
|
str
|
|
|
|
(
|
2023-10-02 15:44:06 +02:00
|
|
|
helpers.keymaps.mkMapOptionSubmodule
|
2023-09-10 09:59:22 +02:00
|
|
|
{
|
|
|
|
defaultMode = modeProps.short;
|
|
|
|
withKeyOpt = false;
|
|
|
|
flatConfig = true;
|
2023-10-02 15:44:06 +02:00
|
|
|
actionIsOptional = config.plugins.which-key.enable;
|
2023-09-10 09:59:22 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
default = {};
|
|
|
|
}
|
|
|
|
)
|
2023-10-02 15:44:06 +02:00
|
|
|
helpers.keymaps.modes;
|
2022-09-18 11:19:23 +01:00
|
|
|
|
2023-09-10 09:59:22 +02:00
|
|
|
keymaps = mkOption {
|
2023-10-02 15:44:06 +02:00
|
|
|
type =
|
|
|
|
types.listOf
|
|
|
|
(helpers.keymaps.mkMapOptionSubmodule {
|
|
|
|
actionIsOptional = config.plugins.which-key.enable;
|
|
|
|
});
|
2023-09-10 09:59:22 +02:00
|
|
|
default = [];
|
|
|
|
example = [
|
|
|
|
{
|
|
|
|
key = "<C-m>";
|
|
|
|
action = "<cmd>make<CR>";
|
|
|
|
options.silent = true;
|
|
|
|
}
|
|
|
|
];
|
2022-09-18 11:19:23 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-09-10 09:59:22 +02:00
|
|
|
config = {
|
|
|
|
warnings =
|
|
|
|
optional
|
|
|
|
(
|
|
|
|
any
|
|
|
|
(modeMaps: modeMaps != {})
|
|
|
|
(attrValues config.maps)
|
|
|
|
)
|
|
|
|
''
|
|
|
|
The `maps` option will be deprecated in the near future.
|
|
|
|
Please, use the new `keymaps` option which works as follows:
|
|
|
|
|
|
|
|
keymaps = [
|
|
|
|
{
|
|
|
|
# Default mode is "" which means normal-visual-op
|
|
|
|
key = "<C-m>";
|
|
|
|
action = ":!make<CR>";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
# Mode can be a string or a list of strings
|
|
|
|
mode = "n";
|
|
|
|
key = "<leader>p";
|
|
|
|
action = "require('my-plugin').do_stuff";
|
|
|
|
lua = true;
|
|
|
|
# Note that all of the mapping options are now under the `options` attrs
|
|
|
|
options = {
|
|
|
|
silent = true;
|
|
|
|
desc = "My plugin does stuff";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
'';
|
|
|
|
|
|
|
|
extraConfigLua = let
|
|
|
|
modeMapsAsList =
|
|
|
|
flatten
|
|
|
|
(
|
|
|
|
mapAttrsToList
|
|
|
|
(
|
|
|
|
modeOptionName: modeProps:
|
|
|
|
mapAttrsToList
|
|
|
|
(
|
|
|
|
key: action:
|
|
|
|
(
|
|
|
|
if isString action
|
|
|
|
then {
|
|
|
|
mode = modeProps.short;
|
|
|
|
inherit action;
|
|
|
|
lua = false;
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
inherit
|
|
|
|
(action)
|
|
|
|
action
|
|
|
|
lua
|
|
|
|
mode
|
|
|
|
;
|
|
|
|
}
|
|
|
|
// {
|
|
|
|
options =
|
|
|
|
getAttrs
|
2023-10-02 15:44:06 +02:00
|
|
|
(attrNames helpers.keymaps.mapConfigOptions)
|
2023-09-10 09:59:22 +02:00
|
|
|
action;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
// {inherit key;}
|
|
|
|
)
|
|
|
|
config.maps.${modeOptionName}
|
|
|
|
)
|
2023-10-02 15:44:06 +02:00
|
|
|
helpers.keymaps.modes
|
2023-09-10 09:59:22 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
mappings = let
|
|
|
|
normalizeMapping = keyMapping: {
|
|
|
|
inherit
|
|
|
|
(keyMapping)
|
|
|
|
mode
|
|
|
|
key
|
|
|
|
;
|
|
|
|
|
|
|
|
action =
|
|
|
|
if keyMapping.lua
|
|
|
|
then helpers.mkRaw keyMapping.action
|
|
|
|
else keyMapping.action;
|
|
|
|
|
|
|
|
options =
|
|
|
|
if keyMapping.options == {}
|
|
|
|
then helpers.emptyTable
|
|
|
|
else keyMapping.options;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
map normalizeMapping
|
|
|
|
(config.keymaps ++ modeMapsAsList);
|
|
|
|
in
|
2023-05-20 16:26:36 +05:30
|
|
|
optionalString (mappings != [])
|
2023-09-26 22:41:21 +02:00
|
|
|
''
|
|
|
|
-- Set up keybinds {{{
|
|
|
|
do
|
|
|
|
local __nixvim_binds = ${helpers.toLuaObject mappings}
|
|
|
|
for i, map in ipairs(__nixvim_binds) do
|
|
|
|
vim.keymap.set(map.mode, map.key, map.action, map.options)
|
2023-05-20 16:26:36 +05:30
|
|
|
end
|
2023-09-26 22:41:21 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
'';
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
}
|