2023-10-13 22:47:44 +01:00
|
|
|
{
|
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
|
|
|
config,
|
|
|
|
pkgs,
|
2023-10-13 22:47:44 +01:00
|
|
|
...
|
|
|
|
}:
|
2024-05-05 19:39:35 +02:00
|
|
|
with lib;
|
|
|
|
let
|
2023-10-13 22:47:44 +01:00
|
|
|
cfg = config.plugins.better-escape;
|
2024-05-05 19:39:35 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.plugins.better-escape = helpers.neovim-plugin.extraOptionsOptions // {
|
|
|
|
enable = mkEnableOption "better-escape.nvim";
|
2023-10-13 22:47:44 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
package = helpers.mkPackageOption "better-escape.nvim" pkgs.vimPlugins.better-escape-nvim;
|
2023-10-13 22:47:44 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
mapping = helpers.mkNullOrOption (with types; listOf str) ''
|
|
|
|
List of mappings to use to enter escape mode.
|
|
|
|
'';
|
2023-10-13 22:47:44 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
timeout = helpers.defaultNullOpts.mkStrLuaOr types.ints.unsigned "vim.o.timeoutlen" ''
|
|
|
|
The time in which the keys must be hit in ms.
|
|
|
|
Uses the value of `vim.o.timeoutlen` (`options.timeoutlen` in nixvim) by default.
|
|
|
|
'';
|
2023-10-13 22:47:44 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
clearEmptyLines = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Clear line after escaping if there is only whitespace.
|
|
|
|
'';
|
2023-10-13 22:47:44 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
keys =
|
|
|
|
helpers.defaultNullOpts.mkNullable (with types; either str helpers.nixvimTypes.rawLua) "<ESC>"
|
2023-10-13 22:47:44 +01:00
|
|
|
''
|
|
|
|
Keys used for escaping, if it is a function will use the result everytime.
|
|
|
|
|
|
|
|
Example (recommended):
|
|
|
|
|
|
|
|
keys.__raw = \'\'
|
|
|
|
function()
|
|
|
|
return vim.api.nvim_win_get_cursor(0)[2] > 1 and '<esc>l' or '<esc>'
|
|
|
|
end
|
|
|
|
\'\';
|
|
|
|
'';
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2023-10-13 22:47:44 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
setupOptions =
|
|
|
|
with cfg;
|
|
|
|
{
|
|
|
|
inherit mapping timeout;
|
|
|
|
clear_empty_lines = clearEmptyLines;
|
|
|
|
inherit keys;
|
|
|
|
}
|
|
|
|
// cfg.extraOptions;
|
|
|
|
in
|
2023-10-13 22:47:44 +01:00
|
|
|
mkIf cfg.enable {
|
2024-05-05 19:39:35 +02:00
|
|
|
extraPlugins = [ cfg.package ];
|
2023-10-13 22:47:44 +01:00
|
|
|
|
|
|
|
extraConfigLua = ''
|
|
|
|
require('better_escape').setup(${helpers.toLuaObject setupOptions})
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|