From a42a4a4fb6780aace58f4594239987e12787a6a2 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 8 Nov 2024 13:22:50 +0300 Subject: [PATCH] binds/which-key: migrate to setupOpts --- .../utility/binds/which-key/config.nix | 29 ++++-------- .../utility/binds/which-key/default.nix | 2 +- .../utility/binds/which-key/which-key.nix | 47 +++++++++++++++++-- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/modules/plugins/utility/binds/which-key/config.nix b/modules/plugins/utility/binds/which-key/config.nix index d7296880..e4d03cbe 100644 --- a/modules/plugins/utility/binds/which-key/config.nix +++ b/modules/plugins/utility/binds/which-key/config.nix @@ -4,33 +4,20 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.strings) optionalString; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.binds.whichKey; in { config = mkIf cfg.enable { - vim.startPlugins = ["which-key"]; + vim = { + startPlugins = ["which-key"]; - vim.pluginRC.whichkey = entryAnywhere '' - local wk = require("which-key") - wk.setup ({ - key_labels = { - [""] = "SPACE", - [""] = "SPACE", - [""] = "RETURN", - [""] = "TAB", - }, - - ${optionalString config.vim.ui.borders.plugins.which-key.enable '' - window = { - border = ${toLuaObject config.vim.ui.borders.plugins.which-key.style}, - }, - ''} - }) - - wk.register(${toLuaObject cfg.register}) - ''; + pluginRC.whichkey = entryAnywhere '' + local wk = require("which-key") + wk.setup (${toLuaObject cfg.setupOpts}) + wk.register(${toLuaObject cfg.register}) + ''; + }; }; } diff --git a/modules/plugins/utility/binds/which-key/default.nix b/modules/plugins/utility/binds/which-key/default.nix index 20c9cdf5..7ae329b8 100644 --- a/modules/plugins/utility/binds/which-key/default.nix +++ b/modules/plugins/utility/binds/which-key/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./which-key.nix ./config.nix diff --git a/modules/plugins/utility/binds/which-key/which-key.nix b/modules/plugins/utility/binds/which-key/which-key.nix index 3851cd9b..c4bb1d70 100644 --- a/modules/plugins/utility/binds/which-key/which-key.nix +++ b/modules/plugins/utility/binds/which-key/which-key.nix @@ -1,14 +1,51 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) attrsOf nullOr str; +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) attrsOf nullOr str attrs enum bool; + inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.binds.whichKey = { enable = mkEnableOption "which-key keybind helper menu"; - register = mkOption { - description = "Register label for which-key keybind helper menu"; type = attrsOf (nullOr str); default = {}; + description = "Register label for which-key keybind helper menu"; + }; + + setupOpts = mkPluginSetupOption "which-key" { + preset = mkOption { + type = enum ["classic" "modern" "helix"]; + default = "modern"; + description = "The default preset for the which-key window"; + }; + + notify = mkOption { + type = bool; + default = true; + description = "Show a warning when issues were detected with mappings"; + }; + + replace = mkOption { + type = attrs; + default = { + "" = "SPACE"; + "" = "SPACE"; + "" = "RETURN"; + "" = "TAB"; + }; + description = "Functions/Lua Patterns for formatting the labels"; + }; + + win = { + border = mkOption { + type = str; + default = config.vim.ui.borders.plugins.which-key.style; + description = "Which-key window border style"; + }; + }; }; }; }