From b809855174ee9174118f575277a50fdd62d85816 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Tue, 13 Jun 2023 09:39:54 +0200 Subject: [PATCH] plugins/cursorline: init + test --- plugins/default.nix | 1 + plugins/utils/cursorline.nix | 65 +++++++++++++++++++ .../test-sources/plugins/utils/cursorline.nix | 24 +++++++ 3 files changed, 90 insertions(+) create mode 100644 plugins/utils/cursorline.nix create mode 100644 tests/test-sources/plugins/utils/cursorline.nix diff --git a/plugins/default.nix b/plugins/default.nix index b4be2a5a..49f84144 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -78,6 +78,7 @@ ./utils/comment-nvim.nix ./utils/commentary.nix ./utils/conjure.nix + ./utils/cursorline.nix ./utils/easyescape.nix ./utils/endwise.nix ./utils/floaterm.nix diff --git a/plugins/utils/cursorline.nix b/plugins/utils/cursorline.nix new file mode 100644 index 00000000..54a4337a --- /dev/null +++ b/plugins/utils/cursorline.nix @@ -0,0 +1,65 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; let + cfg = config.plugins.cursorline; + helpers = import ../helpers.nix {inherit lib;}; +in { + options.plugins.cursorline = + helpers.extraOptionsOptions + // { + enable = mkEnableOption "nvim-cursorline"; + + package = helpers.mkPackageOption "nvim-cursorline" pkgs.vimPlugins.nvim-cursorline; + + cursorline = { + enable = + helpers.defaultNullOpts.mkBool true + "Show / hide cursorline in connection with cursor moving."; + + timeout = + helpers.defaultNullOpts.mkInt 1000 + "Time (in ms) after which the cursorline appears."; + + number = + helpers.defaultNullOpts.mkBool false + "Whether to also highlight the line number."; + }; + cursorword = { + enable = helpers.defaultNullOpts.mkBool true "Underlines the word under the cursor."; + + minLength = helpers.defaultNullOpts.mkInt 3 "Minimum length for underlined words."; + + hl = + helpers.defaultNullOpts.mkNullable + types.attrs + "{underline = true;}" + "Highliht definition map for cursorword highlighting."; + }; + }; + + config = let + options = + { + cursorline = with cfg.cursorline; { + inherit enable timeout number; + }; + cursorword = with cfg.cursorword; { + inherit enable; + min_length = minLength; + inherit hl; + }; + } + // cfg.extraOptions; + in + mkIf cfg.enable { + extraPlugins = [cfg.package]; + + extraConfigLua = '' + require('nvim-cursorline').setup(${helpers.toLuaObject options}) + ''; + }; +} diff --git a/tests/test-sources/plugins/utils/cursorline.nix b/tests/test-sources/plugins/utils/cursorline.nix new file mode 100644 index 00000000..3118c4e0 --- /dev/null +++ b/tests/test-sources/plugins/utils/cursorline.nix @@ -0,0 +1,24 @@ +{ + empty = { + plugins.cursorline.enable = true; + }; + + defaults = { + plugins.cursorline = { + enable = true; + + cursorline = { + enable = true; + timeout = 1000; + number = false; + }; + cursorword = { + enable = true; + minLength = 3; + hl = { + underline = true; + }; + }; + }; + }; +}