From 593f5215cb1df010451675c19f2ad5c5481ccee3 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sun, 4 Aug 2024 10:36:55 +0200 Subject: [PATCH] plugins/firenvim: init --- plugins/default.nix | 1 + plugins/utils/firenvim.nix | 89 +++++++++++++++++++ tests/test-sources/plugins/utils/firenvim.nix | 28 ++++++ 3 files changed, 118 insertions(+) create mode 100644 plugins/utils/firenvim.nix create mode 100644 tests/test-sources/plugins/utils/firenvim.nix diff --git a/plugins/default.nix b/plugins/default.nix index 8784db90..fe713c4c 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -167,6 +167,7 @@ ./utils/easyescape.nix ./utils/emmet.nix ./utils/endwise.nix + ./utils/firenvim.nix ./utils/flash.nix ./utils/floaterm.nix ./utils/fzf-lua.nix diff --git a/plugins/utils/firenvim.nix b/plugins/utils/firenvim.nix new file mode 100644 index 00000000..1b717e81 --- /dev/null +++ b/plugins/utils/firenvim.nix @@ -0,0 +1,89 @@ +{ + lib, + config, + pkgs, + ... +}: +let + inherit (lib.nixvim) defaultNullOpts; + types = lib.nixvim.nixvimTypes; +in +lib.nixvim.neovim-plugin.mkNeovimPlugin config { + name = "firenvim"; + defaultPackage = pkgs.vimPlugins.firenvim; + + maintainers = with lib.maintainers; [ GaetanLepage ]; + + settingsOptions = { + globalSettings = defaultNullOpts.mkAttrsOf' { + type = types.anything; + pluginDefault = { }; + example = { + alt = "all"; + }; + description = "Default settings that apply to all URLs."; + }; + + localSettings = defaultNullOpts.mkAttrsOf' { + type = with types; attrsOf anything; + pluginDefault = { }; + example = { + ".*" = { + cmdline = "neovim"; + content = "text"; + priority = 0; + selector = "textarea"; + takeover = "always"; + }; + "https?://[^/]+\\.co\\.uk/" = { + takeover = "never"; + priority = 1; + }; + }; + description = '' + Map regular expressions that are tested against the full URL to settings that are used for + all URLs matched by that pattern. + + When multiple patterns match a URL, the pattern with the highest "priority" value is used. + + Note: regular expressions use the [JavaScript flavor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions). + ''; + }; + }; + + settingsExample = { + globalSettings.alt = "all"; + localSettings = { + ".*" = { + cmdline = "neovim"; + content = "text"; + priority = 0; + selector = "textarea"; + takeover = "always"; + }; + "https?://[^/]+\\.co\\.uk/" = { + takeover = "never"; + priority = 1; + }; + }; + }; + + settingsDescription = '' + Options fed to the `vim.g.firenvim_config` table. + ''; + + callSetup = false; + extraConfig = cfg: { + warnings = + lib.optional + ( + config.performance.combinePlugins.enable + && !(lib.elem "firenvim" config.performance.combinePlugins.standalonePlugins) + ) + '' + Nixvim (plugins.firenvim): Using `performance.combinePlugins` breaks `firenvim`. + Add this plugin to `performance.combinePlugins.standalonePlugins` to prevent any issue. + ''; + globals.firenvim_config = lib.modules.mkAliasAndWrapDefsWithPriority lib.id cfg.settings; + }; +} diff --git a/tests/test-sources/plugins/utils/firenvim.nix b/tests/test-sources/plugins/utils/firenvim.nix new file mode 100644 index 00000000..c49e193f --- /dev/null +++ b/tests/test-sources/plugins/utils/firenvim.nix @@ -0,0 +1,28 @@ +{ + empty = { + plugins.firenvim.enable = true; + }; + + example = { + plugins.firenvim = { + enable = true; + + settings = { + globalSettings.alt = "all"; + localSettings = { + ".*" = { + cmdline = "neovim"; + content = "text"; + priority = 0; + selector = "textarea"; + takeover = "always"; + }; + "https?://[^/]+\\.co\\.uk/" = { + takeover = "never"; + priority = 1; + }; + }; + }; + }; + }; +}