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 {
Required to transfer data from vim to GNU screen or tmux. global = "no_mappings";
Setting this explicitly can work around some occasional portability issues. type = types.bool;
whimrepl does not require or support this setting. description = ''
''; Whether to disable the default mappings.
preserveCurpos = helpers.defaultNullOpts.mkBool true '' Default: `false`
Whether to preserve cursor position when sending a line or paragraph. '';
''; };
defaultConfig = pasteFile = mkDefaultOpt {
helpers.defaultNullOpts.mkNullable global = "paste_file";
(with types; attrsOf (either str helpers.nixvimTypes.rawLua)) type = types.str;
"null" description = ''
'' Required to transfer data from vim to GNU screen or tmux.
Setting this explicitly can work around some occasional portability issues.
whimrepl does not require or support this setting.
Default: "$HOME/.slime_paste"
'';
};
preserveCurpos = mkDefaultOpt {
global = "preserve_curpos";
type = types.bool;
description = ''
Whether to preserve cursor position when sending a line or paragraph.
Default: `true`
'';
};
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 {
Whether to bypass the prompt and use the specified default configuration options. global = "dont_ask_default";
''; type = types.bool;
bracketedPaste = helpers.defaultNullOpts.mkBool false ''
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.
In this case it can be useful to rely on bracketed-paste
(https://cirw.in/blog/bracketed-paste).
Luckily, tmux knows how to handle that. See tmux's manual.
'';
extraConfig = mkOption {
type = types.attrs;
default = {};
description = '' description = ''
The configuration options for vim-slime without the 'slime_' prefix. Whether to bypass the prompt and use the specified default configuration options.
Example: To set 'slime_foobar' to 1, write
extraConfig = { Default: `false`
foobar = true; '';
}; };
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
not be autocompleted when pasting code from a file.
In this case it can be useful to rely on bracketed-paste
(https://cirw.in/blog/bracketed-paste).
Luckily, tmux knows how to handle that. See tmux's manual.
Default: `false`
''; '';
}; };
}; };
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
);
};
} }