From 3b1df35a8c14ed38fdc82c665640bb22ca014f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Sun, 16 Apr 2023 11:09:59 +0200 Subject: [PATCH] plugins/spider: add plugin + test (#330) --- plugins/default.nix | 1 + plugins/utils/spider.nix | 79 +++++++++++++++++++++ tests/test-sources/plugins/utils/spider.nix | 22 ++++++ 3 files changed, 102 insertions(+) create mode 100644 plugins/utils/spider.nix create mode 100644 tests/test-sources/plugins/utils/spider.nix diff --git a/plugins/default.nix b/plugins/default.nix index d85bcd89..1903a3d5 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -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 diff --git a/plugins/utils/spider.nix b/plugins/utils/spider.nix new file mode 100644 index 00000000..8bb4b401 --- /dev/null +++ b/plugins/utils/spider.nix @@ -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}) + ''; + }; +} diff --git a/tests/test-sources/plugins/utils/spider.nix b/tests/test-sources/plugins/utils/spider.nix new file mode 100644 index 00000000..b1eed91d --- /dev/null +++ b/tests/test-sources/plugins/utils/spider.nix @@ -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"; + }; + }; + }; + }; +}