diff --git a/plugins/default.nix b/plugins/default.nix index bd05d822..025922cd 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -29,6 +29,7 @@ ./utils/telescope.nix ./utils/nvim-autopairs.nix ./utils/intellitab.nix + ./utils/specs.nix ./languages/treesitter.nix ./languages/nix.nix diff --git a/plugins/utils/specs.nix b/plugins/utils/specs.nix new file mode 100644 index 00000000..46c1cca4 --- /dev/null +++ b/plugins/utils/specs.nix @@ -0,0 +1,139 @@ +{ pkgs, config, lib, ... }: +with lib; +let + cfg = config.programs.nixvim.plugins.specs; + helpers = import ../helpers.nix { inherit lib; }; +in { + options.programs.nixvim.plugins.specs = { + enable = mkEnableOption "Enable specs-nvim"; + + show_jumps = mkOption { + type = types.bool; + default = true; + }; + + min_jump = mkOption { + type = types.int; + default = 30; + }; + + delay = mkOption { + type = types.int; + default = 0; + description = "Delay in miliseconds"; + }; + + increment = mkOption { + type = types.int; + default = 10; + description = "Increment in miliseconds"; + }; + + blend = mkOption { + type = types.int; + default = 10; + }; + + width = mkOption { + type = types.int; + default = 10; + }; + + fader = mkOption { + type = types.submodule { + options = { + builtin = mkOption { + type = types.nullOr (types.enum [ + "linear_fader" + "exp_fader" + "pulse_fader" + "empty_fader" + ]); + default = "linear_fader"; + }; + + custom = mkOption { + type = types.lines; + default = ""; + example = '' + function(blend, cnt) + if cnt > 100 then + return 80 + else return nil end + end + ''; + }; + }; + }; + default = { builtin = "linear_fader"; }; + }; + + resizer = mkOption { + type = types.submodule { + options = { + builtin = mkOption { + type = types.nullOr + (types.enum [ "shrink_resizer" "slide_resizer" "empty_resizer" ]); + default = "shrink_resizer"; + }; + + custom = mkOption { + type = types.lines; + default = ""; + example = '' + function(width, ccol, cnt) + if width-cnt > 0 then + return {width+cnt, ccol} + else return nil end + end + ''; + }; + }; + }; + default = { builtin = "shrink_resizer"; }; + }; + + ignored_filetypes = mkOption { + type = with types; listOf string; + default = [ ]; + }; + + ignored_buffertypes = mkOption { + type = with types; listOf string; + default = [ "nofile" ]; + }; + + }; + config = let + setup = helpers.toLuaObject { + inherit (cfg) show_jumps min_jump; + ignore_filetypes = attrsets.listToAttrs + (lib.lists.map (x: attrsets.nameValuePair x true) + cfg.ignored_filetypes); + ignore_buftypes = attrsets.listToAttrs + (lib.lists.map (x: attrsets.nameValuePair x true) + cfg.ignored_buffertypes); + popup = { + inherit (cfg) blend width; + delay_ms = cfg.delay; + inc_ms = cfg.increment; + fader = helpers.mkRaw (if cfg.fader.builtin == null then + cfg.fader.custom + else + ''require("specs").${cfg.fader.builtin}''); + resizer = helpers.mkRaw (if cfg.resizer.builtin == null then + cfg.resizer.custom + else + ''require("specs").${cfg.resizer.builtin}''); + }; + }; + in mkIf cfg.enable { + programs.nixvim = { + extraPlugins = [ pkgs.vimPlugins.specs-nvim ]; + + extraConfigLua = '' + require('specs').setup(${setup}) + ''; + }; + }; +}