Skip to content

Commit

Permalink
plugins/todo-comments: Allow to pass keymap options (#599)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
traxys authored Nov 6, 2023
1 parent 229fe85 commit e45be89
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
27 changes: 17 additions & 10 deletions plugins/utils/todo-comments.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ with lib; let
todoTelescope = "TodoTelescope";
};
in {
imports = [
(
mkRemovedOptionModule
["plugins" "todo-comments" "keymapsSilent"]
"Use `plugins.todo-comments.keymaps.<COMMAND>.options.silent`."
)
];
options = {
plugins.todo-comments =
helpers.extraOptionsOptions
Expand Down Expand Up @@ -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
mkKeymapOption = optionName: funcName:
helpers.mkCompositeOption "Keymap settings for the `:${funcName}` function." {
helpers.mkCompositeOption
"Keymap settings for the `:${funcName}` function."
{
key = mkOption {
type = types.str;
description = "Key for the `${funcName}` function.";
Expand All @@ -213,6 +215,8 @@ in {
default = null;
example = "TODO,FIX";
};

options = helpers.keymaps.mapConfigOptions;
};
in
mapAttrs mkKeymapOption commands;
Expand Down Expand Up @@ -279,9 +283,12 @@ in {
(keymap != null)
{
mode = "n";
inherit (keymap) key;
inherit
(keymap)
key
options
;
action = ":${funcName}${cwd}${keywords}<CR>";
options.silent = cfg.keymapsSilent;
}
)
commands
Expand Down
20 changes: 18 additions & 2 deletions tests/test-sources/plugins/utils/todo-comments.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@
pattern = ''\b(KEYWORDS):'';
};

keymapsSilent = true;

keymaps = {
todoQuickFix.key = "<C-a>";
todoLocList = {
key = "<C-f>";
cwd = "~/projects/foobar";
keywords = "TODO,FIX";
options.silent = true;
};
todoTrouble = {
key = "<C-t>";
Expand All @@ -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;
};
};
};
};
};
}

0 comments on commit e45be89

Please sign in to comment.