plugins/autoclose: fixes

This commit is contained in:
Gaetan Lepage 2024-02-03 12:45:00 +01:00 committed by Gaétan Lepage
parent 06e4a4e0c8
commit 90fbde275c

View file

@ -8,65 +8,76 @@
with lib; let with lib; let
cfg = config.plugins.autoclose; cfg = config.plugins.autoclose;
in { in {
options.plugins.autoclose = { meta.maintainers = [maintainers.GaetanLepage];
enable = mkEnableOption "autoclose";
package = helpers.mkPackageOption "autoclose" pkgs.vimPlugins.autoclose-nvim;
keys = mkOption { options.plugins.autoclose = {
type = with types; nullOr (attrsOf anything); enable = mkEnableOption "autoclose.nvim";
default = null;
description = "Configures various options, such as shortcuts for pairs, what pair of characters to use in the shortcut, etc. See the plugin's [README](https://github.com/m4xshen/autoclose.nvim?tab=readme-ov-file#-configuration) for more info."; package = helpers.mkPackageOption "autoclose.nvim" pkgs.vimPlugins.autoclose-nvim;
example = ''
keys = { keys = helpers.mkNullOrOption (with types; attrsOf anything) ''
"(" = { escape = false, close = true, pair = "()" }, Configures various options, such as shortcuts for pairs, what pair of characters to use in the
"[" = { escape = false, close = true, pair = "[]" }, shortcut, etc.
"{" = { escape = false, close = true, pair = "{}" },
}; See the plugin's [README](https://github.com/m4xshen/autoclose.nvim?tab=readme-ov-file#-configuration) for more info.";
'';
}; Example:
```nix
{
"(" = { escape = false; close = true; pair = "()"; };
"[" = { escape = false; close = true; pair = "[]"; };
"{" = { escape = false; close = true; pair = "{}"; };
}
```
'';
options = { options = {
disabledFiletypes = helpers.defaultNullOpts.mkListOf types.str ''["text"]'' '' disabledFiletypes = helpers.defaultNullOpts.mkListOf types.str ''["text"]'' ''
The plugin will be disabled under the filetypes in this table. The plugin will be disabled under the filetypes in this table.
''; '';
disableWhenTouch = disableWhenTouch = helpers.defaultNullOpts.mkBool false ''
helpers.defaultNullOpts.mkBool false Set this to true will disable the auto-close function when the cursor touches character that
"Set this to true will disable the auto-close function when the cursor touches character that matches touch_regex."; matches touch_regex.
'';
touchRegex = touchRegex = helpers.defaultNullOpts.mkStr "[%w(%[{]" ''
helpers.defaultNullOpts.mkStr "[%w(%[{]" See [README](https://github.com/m4xshen/autoclose.nvim?tab=readme-ov-file#options).
"See [README](https://github.com/m4xshen/autoclose.nvim?tab=readme-ov-file#options)"; '';
pairSpaces = pairSpaces = helpers.defaultNullOpts.mkBool false ''
helpers.defaultNullOpts.mkBool false Pair the spaces when cursor is inside a pair of keys.
"Pair the spaces when cursor is inside a pair of keys. See [README](https://github.com/m4xshen/autoclose.nvim?tab=readme-ov-file#options)"; See [README](https://github.com/m4xshen/autoclose.nvim?tab=readme-ov-file#options)
'';
autoIndent = autoIndent = helpers.defaultNullOpts.mkBool true ''
helpers.defaultNullOpts.mkBool true "Enable auto-indent feature"; Enable auto-indent feature.
'';
disableCommandMode = disableCommandMode = helpers.defaultNullOpts.mkBool false ''
helpers.defaultNullOpts.mkBool false Disable autoclose for command mode globally.
"Disable autoclose for command mode globally"; '';
}; };
}; };
config = with cfg; let config = mkIf cfg.enable {
options' = {
inherit keys;
options = with options; {
disabled_filetypes = disabledFiletypes;
disable_when_touch = disableWhenTouch;
touch_regex = touchRegex;
pair_spaces = pairSpaces;
auto_indent = autoIndent;
disable_command_mode = disableCommandMode;
};
};
in {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
extraConfigLua = ''
require('autoclose').setup(${helpers.toLuaObject options'}) extraConfigLua = let
setupOptions = with cfg; {
inherit keys;
options = with options; {
disabled_filetypes = disabledFiletypes;
disable_when_touch = disableWhenTouch;
touch_regex = touchRegex;
pair_spaces = pairSpaces;
auto_indent = autoIndent;
disable_command_mode = disableCommandMode;
};
};
in ''
require('autoclose').setup(${helpers.toLuaObject setupOptions})
''; '';
}; };
} }