plugins/todo-comments: Allow to pass keymap options (#599)

This re-uses the keymap options defined in the keymaps module to allow
to define the options of todo-comments key mappings.

Fixes #598
Co-authored-by: gaetan@glepage.com
This commit is contained in:
traxys 2023-11-06 15:53:26 +01:00 committed by GitHub
parent 229fe85d6b
commit e45be89f12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 12 deletions

View file

@ -15,6 +15,13 @@ with lib; let
todoTelescope = "TodoTelescope"; todoTelescope = "TodoTelescope";
}; };
in { in {
imports = [
(
mkRemovedOptionModule
["plugins" "todo-comments" "keymapsSilent"]
"Use `plugins.todo-comments.keymaps.<COMMAND>.options.silent`."
)
];
options = { options = {
plugins.todo-comments = plugins.todo-comments =
helpers.extraOptionsOptions helpers.extraOptionsOptions
@ -182,16 +189,11 @@ in {
''; '';
}; };
# Keyboard shortcuts for :Todo* commands
keymapsSilent = mkOption {
type = types.bool;
description = "Whether todo-comments keymaps should be silent.";
default = false;
};
keymaps = let keymaps = let
mkKeymapOption = optionName: funcName: mkKeymapOption = optionName: funcName:
helpers.mkCompositeOption "Keymap settings for the `:${funcName}` function." { helpers.mkCompositeOption
"Keymap settings for the `:${funcName}` function."
{
key = mkOption { key = mkOption {
type = types.str; type = types.str;
description = "Key for the `${funcName}` function."; description = "Key for the `${funcName}` function.";
@ -213,6 +215,8 @@ in {
default = null; default = null;
example = "TODO,FIX"; example = "TODO,FIX";
}; };
options = helpers.keymaps.mapConfigOptions;
}; };
in in
mapAttrs mkKeymapOption commands; mapAttrs mkKeymapOption commands;
@ -279,9 +283,12 @@ in {
(keymap != null) (keymap != null)
{ {
mode = "n"; mode = "n";
inherit (keymap) key; inherit
(keymap)
key
options
;
action = ":${funcName}${cwd}${keywords}<CR>"; action = ":${funcName}${cwd}${keywords}<CR>";
options.silent = cfg.keymapsSilent;
} }
) )
commands commands

View file

@ -89,14 +89,13 @@
pattern = ''\b(KEYWORDS):''; pattern = ''\b(KEYWORDS):'';
}; };
keymapsSilent = true;
keymaps = { keymaps = {
todoQuickFix.key = "<C-a>"; todoQuickFix.key = "<C-a>";
todoLocList = { todoLocList = {
key = "<C-f>"; key = "<C-f>";
cwd = "~/projects/foobar"; cwd = "~/projects/foobar";
keywords = "TODO,FIX"; keywords = "TODO,FIX";
options.silent = true;
}; };
todoTrouble = { todoTrouble = {
key = "<C-t>"; key = "<C-t>";
@ -109,4 +108,21 @@
}; };
}; };
}; };
keymapsOptions = {
plugins.todo-comments = {
enable = true;
keymaps = {
todoTrouble = {
key = "<C-f>";
keywords = "TODO,FIX";
options = {
desc = "Description for todoTrouble";
silent = true;
};
};
};
};
};
} }