2023-02-20 11:42:13 +01:00
|
|
|
{
|
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
|
|
|
config,
|
2024-05-26 10:46:36 +01:00
|
|
|
options,
|
2023-02-20 11:42:13 +01:00
|
|
|
...
|
|
|
|
}:
|
2023-11-06 15:04:08 +01:00
|
|
|
{
|
2023-12-02 20:02:53 +01:00
|
|
|
options = {
|
2024-08-30 14:37:41 -05:00
|
|
|
keymaps = lib.mkOption {
|
|
|
|
type = lib.types.listOf helpers.keymaps.deprecatedMapOptionSubmodule;
|
2023-12-02 20:02:53 +01:00
|
|
|
default = [ ];
|
2024-06-09 23:04:27 +02:00
|
|
|
description = "Nixvim keymaps.";
|
2023-12-02 20:02:53 +01:00
|
|
|
example = [
|
|
|
|
{
|
|
|
|
key = "<C-m>";
|
|
|
|
action = "<cmd>make<CR>";
|
|
|
|
options.silent = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2023-09-10 09:59:22 +02:00
|
|
|
|
2024-08-30 14:37:41 -05:00
|
|
|
keymapsOnEvents = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf (lib.types.listOf helpers.keymaps.deprecatedMapOptionSubmodule);
|
2024-03-18 19:41:12 +00:00
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
"InsertEnter" = [
|
|
|
|
{
|
|
|
|
key = "<C-y>";
|
2024-05-26 10:46:36 +01:00
|
|
|
action.__raw = ''require("cmp").mapping.confirm()'';
|
2024-03-18 19:41:12 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
key = "<C-n>";
|
2024-05-26 10:46:36 +01:00
|
|
|
action.__raw = ''require("cmp").mapping.select_next_item()'';
|
2024-03-18 19:41:12 +00:00
|
|
|
}
|
|
|
|
];
|
2023-12-02 20:02:53 +01:00
|
|
|
};
|
2024-03-18 19:41:12 +00:00
|
|
|
description = ''
|
|
|
|
Register keymaps on an event instead of when nvim opens.
|
|
|
|
Keys are the events to register on, and values are lists of keymaps to register on each event.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-09-10 09:59:22 +02:00
|
|
|
|
2024-08-17 22:40:14 +01:00
|
|
|
config = {
|
|
|
|
# Deprecate `lua` keymap option
|
|
|
|
# TODO upgrade to an assertion (removal notice) in 24.11
|
|
|
|
# TODO remove entirely in 25.05?
|
|
|
|
warnings =
|
|
|
|
let
|
|
|
|
# All keymap options that have historically supported the `lua` sub-option
|
|
|
|
keymapOptions =
|
|
|
|
[
|
|
|
|
options.keymaps
|
|
|
|
options.keymapsOnEvents
|
|
|
|
options.plugins.wtf.keymaps.ai
|
|
|
|
options.plugins.wtf.keymaps.search
|
|
|
|
# NOTE: lsp `diagnostic` and `lspBuf` don't use `mapOptionSubmodule` yet
|
|
|
|
# So we only need `lua` deprecation in lsp's `extra` option
|
|
|
|
options.plugins.lsp.keymaps.extra
|
|
|
|
# NOTE: tmux-navigator added `mapOptionSubmodule` support _after_ branching off 24.05
|
|
|
|
options.plugins.tmux-navigator.keymaps
|
|
|
|
]
|
|
|
|
# NOTE: barbar added `mapOptionSubmodule` support shortly _before_ branching off 24.05
|
|
|
|
++ builtins.attrValues (builtins.removeAttrs options.plugins.barbar.keymaps [ "silent" ]);
|
|
|
|
in
|
|
|
|
lib.pipe keymapOptions [
|
|
|
|
(map (opt: (opt.type.getSubOptions opt.loc).lua))
|
2024-08-30 14:37:41 -05:00
|
|
|
(lib.filter (opt: opt.isDefined))
|
2024-08-17 22:40:14 +01:00
|
|
|
(map (opt: ''
|
|
|
|
${"\n"}
|
|
|
|
The `${lib.showOption opt.loc}' option is deprecated and will be removed in 24.11.
|
2024-03-18 19:41:12 +00:00
|
|
|
|
2024-08-17 22:40:14 +01:00
|
|
|
You should use a "raw" `action` instead;
|
2024-05-26 10:46:36 +01:00
|
|
|
e.g. `action.__raw = "<lua code>"` or `action = helpers.mkRaw "<lua code>"`.
|
|
|
|
|
2024-08-17 22:40:14 +01:00
|
|
|
${lib.options.showDefs opt.definitionsWithLocations}
|
|
|
|
''))
|
|
|
|
];
|
2024-05-26 10:46:36 +01:00
|
|
|
|
2024-08-30 14:37:41 -05:00
|
|
|
extraConfigLua = lib.mkIf (config.keymaps != [ ]) ''
|
2024-08-17 22:40:14 +01:00
|
|
|
-- Set up keybinds {{{
|
|
|
|
do
|
2024-12-15 20:32:14 +01:00
|
|
|
local __nixvim_binds = ${lib.nixvim.toLuaObject (map helpers.keymaps.removeDeprecatedMapAttrs config.keymaps)}
|
2024-08-17 22:40:14 +01:00
|
|
|
for i, map in ipairs(__nixvim_binds) do
|
|
|
|
vim.keymap.set(map.mode, map.key, map.action, map.options)
|
2023-09-26 22:41:21 +02:00
|
|
|
end
|
2024-08-17 22:40:14 +01:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
'';
|
2024-03-18 19:41:12 +00:00
|
|
|
|
2024-08-30 14:37:41 -05:00
|
|
|
autoGroups = lib.mapAttrs' (
|
|
|
|
event: mappings: lib.nameValuePair "nixvim_binds_${event}" { clear = true; }
|
2024-08-17 22:40:14 +01:00
|
|
|
) config.keymapsOnEvents;
|
2024-03-18 19:41:12 +00:00
|
|
|
|
2024-08-30 14:37:41 -05:00
|
|
|
autoCmd = lib.mapAttrsToList (event: mappings: {
|
2024-08-17 22:40:14 +01:00
|
|
|
inherit event;
|
|
|
|
group = "nixvim_binds_${event}";
|
|
|
|
callback = helpers.mkRaw ''
|
2024-12-18 12:13:59 -08:00
|
|
|
function(args)
|
2024-08-17 22:40:14 +01:00
|
|
|
do
|
2024-12-15 20:32:14 +01:00
|
|
|
local __nixvim_binds = ${lib.nixvim.toLuaObject (map helpers.keymaps.removeDeprecatedMapAttrs mappings)}
|
2024-12-18 12:13:59 -08:00
|
|
|
|
2024-08-17 22:40:14 +01:00
|
|
|
for i, map in ipairs(__nixvim_binds) do
|
2024-12-20 01:54:02 -08:00
|
|
|
local options = vim.tbl_extend("keep", map.options or {}, { buffer = args.buf })
|
2024-12-18 12:13:59 -08:00
|
|
|
vim.keymap.set(map.mode, map.key, map.action, options)
|
2024-03-18 19:41:12 +00:00
|
|
|
end
|
2024-05-05 19:39:35 +02:00
|
|
|
end
|
2024-08-17 22:40:14 +01:00
|
|
|
end
|
|
|
|
'';
|
|
|
|
desc = "Load keymaps for ${event}";
|
|
|
|
}) config.keymapsOnEvents;
|
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
}
|