From 993cf528b75153242da78afed75060a34b570c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=C3=ADn=20=C5=98=C3=ADha?= <43958476+anriha@users.noreply.github.com> Date: Mon, 3 Jul 2023 12:04:39 +0200 Subject: [PATCH] plugins/wilder-nvim: init + test (#466) --- plugins/default.nix | 1 + plugins/utils/wilder-nvim.nix | 80 +++++++++++++++++++ .../plugins/utils/wilder-nvim.nix | 19 +++++ 3 files changed, 100 insertions(+) create mode 100644 plugins/utils/wilder-nvim.nix create mode 100644 tests/test-sources/plugins/utils/wilder-nvim.nix diff --git a/plugins/default.nix b/plugins/default.nix index 36333283..092518c3 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -122,6 +122,7 @@ ./utils/emmet.nix ./utils/magma-nvim.nix ./utils/which-key.nix + ./utils/wilder-nvim.nix ./utils/zk.nix ]; } diff --git a/plugins/utils/wilder-nvim.nix b/plugins/utils/wilder-nvim.nix new file mode 100644 index 00000000..80458740 --- /dev/null +++ b/plugins/utils/wilder-nvim.nix @@ -0,0 +1,80 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; let + cfg = config.plugins.wilder-nvim; + helpers = import ../helpers.nix {inherit lib;}; + + boolToInt = value: + if value == null + then null + else if value + then "1" + else "0"; +in { + options.plugins.wilder-nvim = + helpers.extraOptionsOptions + // { + enable = mkEnableOption "wilder-nvim"; + + package = helpers.mkPackageOption "wilder-nvim" pkgs.vimPlugins.wilder-nvim; + + modes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) ''["/" "?"]'' '' + List of modes which wilderw will be active in. + Possible elements: '/', '?' and ':' + ''; + + enableCmdlineEnter = helpers.defaultNullOpts.mkBool true '' + If true calls wilder#enable_cmdline_enter(). + Creates a new |CmdlineEnter| autocmd to which will start wilder + when the cmdline is entered. + ''; + + wildcharm = helpers.defaultNullOpts.mkStr "&wildchar" '' + Key to set the 'wildcharm' option to. can be set to v:false to skip the setting. + ''; + + nextKey = helpers.defaultNullOpts.mkStr "" '' + A key to map to wilder#next() providing next suggestion. + ''; + + prevKey = helpers.defaultNullOpts.mkStr "" '' + A key to map to wilder#prev() providing previous suggestion. + ''; + + acceptKey = helpers.defaultNullOpts.mkStr "" '' + Mapping to bind to wilder#accept_completion(). + ''; + + rejectKey = helpers.defaultNullOpts.mkStr "" '' + Mapping to bind to wilder#reject_completion(). + ''; + + acceptCompletionAutoSelect = helpers.defaultNullOpts.mkBool true '' + The auto_slect option passed to wilder#accept_completion(). + ''; + }; + + config = let + setupOptions = with cfg; { + enable_cmdline_enter = boolToInt enableCmdlineEnter; + inherit modes; + inherit wildcharm; + next_key = nextKey; + previous_key = prevKey; + accept_key = acceptKey; + reject_key = rejectKey; + accept_completion_auto_select = boolToInt acceptCompletionAutoSelect; + }; + in + mkIf cfg.enable { + extraPlugins = [cfg.package]; + + extraConfigLua = '' + require("wilder").setup(${helpers.toLuaObject setupOptions}) + ''; + }; +} diff --git a/tests/test-sources/plugins/utils/wilder-nvim.nix b/tests/test-sources/plugins/utils/wilder-nvim.nix new file mode 100644 index 00000000..6dcaacf1 --- /dev/null +++ b/tests/test-sources/plugins/utils/wilder-nvim.nix @@ -0,0 +1,19 @@ +{ + empty = { + plugins.wilder-nvim.enable = true; + }; + + example = { + plugins.wilder-nvim = { + enable = true; + modes = ["/" ":"]; + enableCmdlineEnter = false; + wildcharm = "k"; + nextKey = "a"; + prevKey = "b"; + acceptKey = "c"; + rejectKey = "d"; + acceptCompletionAutoSelect = false; + }; + }; +}