plugins/better-escape: switch to mkNeovimPlugin + update

This commit is contained in:
Gaetan Lepage 2024-07-23 00:01:09 +02:00 committed by Gaétan Lepage
parent 95dade6292
commit 3b6d403f39
2 changed files with 111 additions and 48 deletions

View file

@ -6,59 +6,94 @@
... ...
}: }:
with lib; with lib;
let helpers.neovim-plugin.mkNeovimPlugin config {
cfg = config.plugins.better-escape; name = "better-escape";
in originalName = "better-escape.nvim";
{ luaName = "better_escape";
options.plugins.better-escape = helpers.neovim-plugin.extraOptionsOptions // { defaultPackage = pkgs.vimPlugins.better-escape-nvim;
enable = mkEnableOption "better-escape.nvim";
package = helpers.mkPluginPackageOption "better-escape.nvim" pkgs.vimPlugins.better-escape-nvim; maintainers = [ maintainers.GaetanLepage ];
mapping = helpers.mkNullOrOption (with types; listOf str) '' # TODO: introduced 2024-07-23. Remove after 24.11 release.
List of mappings to use to enter escape mode. deprecateExtraOptions = true;
''; optionsRenamedToSettings = [ "timeout" ];
imports =
let
basePluginPath = [
"plugins"
"better-escape"
];
in
[
(mkRemovedOptionModule (basePluginPath ++ [ "clearEmptyLines" ]) ''
This option has been removed upstream.
See the [upstream README](https://github.com/max397574/better-escape.nvim?tab=readme-ov-file#rewrite) for additional information.
'')
(mkRemovedOptionModule (basePluginPath ++ [ "keys" ]) ''
This option has been removed upstream.
See the [upstream README](https://github.com/max397574/better-escape.nvim?tab=readme-ov-file#rewrite) for additional information.
'')
(mkRemovedOptionModule (basePluginPath ++ [ "mapping" ]) ''
This option has been removed in favor of `plugins.better-escape.settings.mapping`.
See the [upstream README](https://github.com/max397574/better-escape.nvim?tab=readme-ov-file#rewrite) for additional information.
'')
];
settingsOptions = {
timeout = helpers.defaultNullOpts.mkStrLuaOr types.ints.unsigned "vim.o.timeoutlen" '' timeout = helpers.defaultNullOpts.mkStrLuaOr types.ints.unsigned "vim.o.timeoutlen" ''
The time in which the keys must be hit in ms. The time in which the keys must be hit in ms.
Uses the value of `vim.o.timeoutlen` (`options.timeoutlen` in nixvim) by default. Uses the value of `vim.o.timeoutlen` (`options.timeoutlen` in nixvim) by default.
''; '';
clearEmptyLines = helpers.defaultNullOpts.mkBool false '' default_mappings = helpers.defaultNullOpts.mkBool true ''
Clear line after escaping if there is only whitespace. Whether to enable default key mappings.
''; '';
keys = mappings = helpers.defaultNullOpts.mkAttrsOf' {
helpers.defaultNullOpts.mkNullable (with types; either str helpers.nixvimTypes.rawLua) "<ESC>" type = types.anything;
'' pluginDefault = {
Keys used for escaping, if it is a function will use the result everytime. i.j = {
k = "<Esc>";
Example (recommended): j = "<Esc>";
};
keys.__raw = \'\' c.j = {
function() k = "<Esc>";
return vim.api.nvim_win_get_cursor(0)[2] > 1 and '<esc>l' or '<esc>' j = "<Esc>";
end };
\'\'; t.j = {
''; k = "<Esc>";
j = "<Esc>";
};
v.j.k = "<Esc>";
s.j.k = "<Esc>";
};
example.i." "."<tab>".__raw = ''
function()
-- Defer execution to avoid side-effects
vim.defer_fn(function()
-- set undo point
vim.o.ul = vim.o.ul
require("luasnip").expand_or_jump()
end, 1)
end
'';
description = "Define mappings for each mode.";
};
}; };
config = settingsExample = {
let timeout = "vim.o.timeoutlen";
setupOptions = mapping = {
with cfg; i." "."<tab>".__raw = ''
{ function()
inherit mapping timeout; -- Defer execution to avoid side-effects
clear_empty_lines = clearEmptyLines; vim.defer_fn(function()
inherit keys; -- set undo point
} vim.o.ul = vim.o.ul
// cfg.extraOptions; require("luasnip").expand_or_jump()
in end, 1)
mkIf cfg.enable { end
extraPlugins = [ cfg.package ];
extraConfigLua = ''
require('better_escape').setup(${helpers.toLuaObject setupOptions})
''; '';
}; };
};
} }

View file

@ -3,17 +3,45 @@
plugins.better-escape.enable = true; plugins.better-escape.enable = true;
}; };
defaults = {
plugins.better-escape = {
enable = true;
settings = {
timeout = "vim.o.timeoutlen";
default_mappings = true;
mappings = {
i.j = {
k = "<Esc>";
j = "<Esc>";
};
c.j = {
k = "<Esc>";
j = "<Esc>";
};
t.j = {
k = "<Esc>";
j = "<Esc>";
};
v.j.k = "<Esc>";
s.j.k = "<Esc>";
};
};
};
};
example = { example = {
plugins.better-escape = { plugins.better-escape = {
enable = true; enable = true;
mapping = [ settings = {
"jj" mappings.i.j = {
"jk" k = "<Esc>";
]; j = "<Esc>";
timeout = 150; };
clearEmptyLines = false; timeout = 150;
keys = "<ESC>"; };
}; };
}; };
} }