plugins/spider: add plugin + test (#330)

This commit is contained in:
Gaétan Lepage 2023-04-16 11:09:59 +02:00 committed by GitHub
parent a9e3ff3f73
commit 3b1df35a8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 0 deletions

View file

@ -87,6 +87,7 @@
./utils/project-nvim.nix
./utils/presence-nvim.nix
./utils/specs.nix
./utils/spider.nix
./utils/startify.nix
./utils/surround.nix
./utils/tmux-navigator.nix

79
plugins/utils/spider.nix Normal file
View file

@ -0,0 +1,79 @@
{
pkgs,
config,
lib,
...
}:
with lib; let
pluginName = "spider";
cfg = config.plugins.${pluginName};
helpers = import ../helpers.nix {inherit lib;};
in {
options.plugins.${pluginName} =
helpers.extraOptionsOptions
// {
enable = mkEnableOption pluginName;
package = helpers.mkPackageOption pluginName pkgs.vimPlugins.nvim-spider;
skipInsignificantPunctuation =
helpers.defaultNullOpts.mkBool true "Whether to skip unsignificant punctuation.";
keymaps = {
silent = mkOption {
type = types.bool;
description = "Whether ${pluginName} keymaps should be silent.";
default = false;
};
motions = mkOption {
type = types.attrsOf types.str;
description = ''
Mappings for spider motions.
The keys are the motion and the values are the keyboard shortcuts.
The shortcut might not necessarily be the same as the motion name.
'';
default = {};
example = {
w = "w";
e = "e";
b = "b";
g = "ge";
};
};
};
};
config = let
setupOptions =
{
inherit (cfg) skipInsignificantPunctuation;
}
// cfg.extraOptions;
mappings =
mapAttrs'
(motion: key: {
name = key;
value = {
action = "function() require('spider').motion('${motion}') end";
lua = true;
inherit (cfg.keymaps) silent;
desc = "Spider-${motion}";
};
})
cfg.keymaps.motions;
in
mkIf cfg.enable {
extraPlugins = [cfg.package];
maps =
genAttrs
["normal" "operator" "visualOnly"]
(mode: mappings);
extraConfigLua = ''
require("${pluginName}").setup(${helpers.toLuaObject setupOptions})
'';
};
}

View file

@ -0,0 +1,22 @@
{
empty = {
plugins.spider.enable = true;
};
example = {
plugins.spider = {
enable = true;
skipInsignificantPunctuation = true;
keymaps = {
silent = true;
motions = {
w = "w";
e = "e";
b = "b";
g = "ge";
};
};
};
};
}