plugins/vim-slime: switch to using mkPlugin

This commit is contained in:
Gaetan Lepage 2024-01-07 11:40:22 +01:00 committed by Gaétan Lepage
parent c498d0b9c9
commit a82b8188fd

View file

@ -1,21 +1,18 @@
{ {
lib, lib,
helpers,
config,
pkgs, pkgs,
... ...
}: let } @ args:
cfg = config.plugins.vim-slime; with lib;
in with import ../helpers.nix {inherit lib;};
with lib; { mkPlugin args {
options.plugins.vim-slime = { name = "vim-slime";
enable = mkEnableOption "vim-slime"; package = pkgs.vimPlugins.vim-slime;
globalPrefix = "slime_";
package = helpers.mkPackageOption "vim-slime" pkgs.vimPlugins.vim-slime; options = {
target = mkDefaultOpt {
target = type = types.enum [
helpers.defaultNullOpts.mkEnum
[
"dtach" "dtach"
"kitty" "kitty"
"neovim" "neovim"
@ -26,31 +23,61 @@ in
"whimrepl" "whimrepl"
"x11" "x11"
"zellij" "zellij"
] ];
"screen" description = ''
"Which backend vim-slime should use."; Which backend vim-slime should use.
vimterminalCmd = helpers.mkNullOrOption types.str "The vim terminal command to execute."; Default: "screen"
'';
example = "dtach";
};
noMappings = helpers.defaultNullOpts.mkBool false "Whether to disable the default mappings."; vimterminalCmd = mkDefaultOpt {
global = "vimterminal_cmd";
type = types.str;
description = "The vim terminal command to execute.";
};
pasteFile = helpers.defaultNullOpts.mkStr "$HOME/.slime_paste" '' noMappings = mkDefaultOpt {
global = "no_mappings";
type = types.bool;
description = ''
Whether to disable the default mappings.
Default: `false`
'';
};
pasteFile = mkDefaultOpt {
global = "paste_file";
type = types.str;
description = ''
Required to transfer data from vim to GNU screen or tmux. Required to transfer data from vim to GNU screen or tmux.
Setting this explicitly can work around some occasional portability issues. Setting this explicitly can work around some occasional portability issues.
whimrepl does not require or support this setting. whimrepl does not require or support this setting.
'';
preserveCurpos = helpers.defaultNullOpts.mkBool true '' Default: "$HOME/.slime_paste"
'';
};
preserveCurpos = mkDefaultOpt {
global = "preserve_curpos";
type = types.bool;
description = ''
Whether to preserve cursor position when sending a line or paragraph. Whether to preserve cursor position when sending a line or paragraph.
'';
defaultConfig = Default: `true`
helpers.defaultNullOpts.mkNullable '';
(with types; attrsOf (either str helpers.nixvimTypes.rawLua)) };
"null"
'' defaultConfig = mkDefaultOpt {
global = "default_config";
type = with nixvimTypes; attrsOf (either str rawLua);
description = ''
Pre-filled prompt answer. Pre-filled prompt answer.
Default: `null`
Examples: Examples:
- `tmux`: - `tmux`:
```nix ```nix
@ -67,50 +94,30 @@ in
} }
``` ```
''; '';
};
dontAskDefault = helpers.defaultNullOpts.mkBool false '' dontAskDefault = mkDefaultOpt {
global = "dont_ask_default";
type = types.bool;
description = ''
Whether to bypass the prompt and use the specified default configuration options. Whether to bypass the prompt and use the specified default configuration options.
'';
bracketedPaste = helpers.defaultNullOpts.mkBool false '' Default: `false`
'';
};
bracketedPaste = mkDefaultOpt {
global = "bracketed_paste";
type = with types; nullOr bool;
description = ''
Sometimes REPL are too smart for their own good, e.g. autocompleting a bracket that should Sometimes REPL are too smart for their own good, e.g. autocompleting a bracket that should
not be autocompleted when pasting code from a file. not be autocompleted when pasting code from a file.
In this case it can be useful to rely on bracketed-paste In this case it can be useful to rely on bracketed-paste
(https://cirw.in/blog/bracketed-paste). (https://cirw.in/blog/bracketed-paste).
Luckily, tmux knows how to handle that. See tmux's manual. Luckily, tmux knows how to handle that. See tmux's manual.
'';
extraConfig = mkOption { Default: `false`
type = types.attrs;
default = {};
description = ''
The configuration options for vim-slime without the 'slime_' prefix.
Example: To set 'slime_foobar' to 1, write
extraConfig = {
foobar = true;
};
''; '';
}; };
}; };
config = mkIf cfg.enable {
extraPlugins = [cfg.package];
globals =
mapAttrs'
(name: nameValuePair ("slime_" + name))
(
{
inherit (cfg) target;
vimterminal_cmd = cfg.vimterminalCmd;
no_mappings = cfg.noMappings;
paste_file = cfg.pasteFile;
preserve_curpos = cfg.preserveCurpos;
default_config = cfg.defaultConfig;
dont_ask_default = cfg.dontAskDefault;
bracketed_paste = cfg.bracketedPaste;
}
// cfg.extraConfig
);
};
} }