plugins/hardtime: migrate to mkNeovimPlugin

Co-authored-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
refaelsh 2024-09-08 00:01:06 +03:00 committed by Matt Sturgeon
parent 810eacf516
commit 2de406d972
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 658 additions and 662 deletions

View file

@ -1,244 +1,228 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.hardtime;
inherit (lib.nixvim) defaultNullOpts;
inherit (lib) types;
in
{
options = {
plugins.hardtime = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "hardtime";
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "hardtime";
originalName = "hardtime.nvim";
package = "hardtime-nvim";
package = lib.mkPackageOption pkgs "hardtime" {
default = [
"vimPlugins"
"hardtime-nvim"
];
};
maintainers = [ lib.maintainers.refaelsh ];
maxTime = helpers.defaultNullOpts.mkUnsignedInt 1000 ''
Maximum time (in milliseconds) to consider key presses as repeated.
'';
# TODO: Added 2024-09-07; remove after 24.11
deprecateExtraOptions = true;
optionsRenamedToSettings = [
"hint"
"notification"
"hints"
"maxTime"
"maxCount"
"disableMouse"
"allowDifferentKey"
"resettingKeys"
"restrictedKeys"
"restrictionMode"
"disabledKeys"
"disabledFiletypes"
];
maxCount = helpers.defaultNullOpts.mkUnsignedInt 2 ''
Maximum count of repeated key presses allowed within the `max_time` period.
'';
settingsOptions = {
max_time = defaultNullOpts.mkUnsignedInt 1000 ''
Maximum time (in milliseconds) to consider key presses as repeated.
'';
disableMouse = helpers.defaultNullOpts.mkBool true ''
Disable mouse support.
'';
max_count = defaultNullOpts.mkUnsignedInt 2 ''
Maximum count of repeated key presses allowed within the `max_time` period.
'';
hint = helpers.defaultNullOpts.mkBool true ''
Enable hint messages for better commands.
'';
disable_mouse = defaultNullOpts.mkBool true ''
Disable mouse support.
'';
notification = helpers.defaultNullOpts.mkBool true ''
Enable notification messages for restricted and disabled keys.
'';
hint = defaultNullOpts.mkBool true ''
Enable hint messages for better commands.
'';
allowDifferentKey = helpers.defaultNullOpts.mkBool false ''
Allow different keys to reset the count.
'';
notification = defaultNullOpts.mkBool true ''
Enable notification messages for restricted and disabled keys.
'';
enabled = helpers.defaultNullOpts.mkBool true ''
Whether the plugin in enabled by default or not.
'';
allow_different_key = defaultNullOpts.mkBool false ''
Allow different keys to reset the count.
'';
resettingKeys = helpers.defaultNullOpts.mkAttrsOf (with types; listOf str) {
"1" = [
"n"
"x"
];
"2" = [
"n"
"x"
];
"3" = [
"n"
"x"
];
"4" = [
"n"
"x"
];
"5" = [
"n"
"x"
];
"6" = [
"n"
"x"
];
"7" = [
"n"
"x"
];
"8" = [
"n"
"x"
];
"9" = [
"n"
"x"
];
"c" = [ "n" ];
"C" = [ "n" ];
"d" = [ "n" ];
"x" = [ "n" ];
"X" = [ "n" ];
"y" = [ "n" ];
"Y" = [ "n" ];
"p" = [ "n" ];
"P" = [ "n" ];
} "Keys in what modes that reset the count.";
enabled = defaultNullOpts.mkBool true ''
Whether the plugin in enabled by default or not.
'';
restrictedKeys = helpers.defaultNullOpts.mkAttrsOf (with types; listOf str) {
"h" = [
"n"
"x"
];
"j" = [
"n"
"x"
];
"k" = [
"n"
"x"
];
"l" = [
"n"
"x"
];
"-" = [
"n"
"x"
];
"+" = [
"n"
"x"
];
"gj" = [
"n"
"x"
];
"gk" = [
"n"
"x"
];
"<CR>" = [
"n"
"x"
];
"<C-M>" = [
"n"
"x"
];
"<C-N>" = [
"n"
"x"
];
"<C-P>" = [
"n"
"x"
];
} "Keys in what modes triggering the count mechanism.";
resetting_keys = defaultNullOpts.mkAttrsOf (with types; listOf str) {
"1" = [
"n"
"x"
];
"2" = [
"n"
"x"
];
"3" = [
"n"
"x"
];
"4" = [
"n"
"x"
];
"5" = [
"n"
"x"
];
"6" = [
"n"
"x"
];
"7" = [
"n"
"x"
];
"8" = [
"n"
"x"
];
"9" = [
"n"
"x"
];
"c" = [ "n" ];
"C" = [ "n" ];
"d" = [ "n" ];
"x" = [ "n" ];
"X" = [ "n" ];
"y" = [ "n" ];
"Y" = [ "n" ];
"p" = [ "n" ];
"P" = [ "n" ];
} "Keys in what modes that reset the count.";
restrictionMode =
helpers.defaultNullOpts.mkEnumFirstDefault
[
"block"
"hint"
]
''
The behavior when `restricted_keys` trigger count mechanism.
'';
restricted_keys = defaultNullOpts.mkAttrsOf (with types; listOf str) {
"h" = [
"n"
"x"
];
"j" = [
"n"
"x"
];
"k" = [
"n"
"x"
];
"l" = [
"n"
"x"
];
"-" = [
"n"
"x"
];
"+" = [
"n"
"x"
];
"gj" = [
"n"
"x"
];
"gk" = [
"n"
"x"
];
"<CR>" = [
"n"
"x"
];
"<C-M>" = [
"n"
"x"
];
"<C-N>" = [
"n"
"x"
];
"<C-P>" = [
"n"
"x"
];
} "Keys in what modes triggering the count mechanism.";
disabledKeys = helpers.defaultNullOpts.mkAttrsOf (with types; listOf str) {
"<Up>" = [
""
"i"
];
"<Down>" = [
""
"i"
];
"<Left>" = [
""
"i"
];
"<Right>" = [
""
"i"
];
} "Keys in what modes are disabled.";
restriction_mode =
defaultNullOpts.mkEnumFirstDefault
[
"block"
"hint"
]
''
The behavior when `restricted_keys` trigger count mechanism.
'';
disabledFiletypes = helpers.defaultNullOpts.mkListOf types.str [
"qf"
"netrw"
"NvimTree"
"lazy"
"mason"
] "`hardtime.nvim` is disabled under these filetypes.";
disabled_keys = defaultNullOpts.mkAttrsOf (with types; listOf str) {
"<Up>" = [
""
"i"
];
"<Down>" = [
""
"i"
];
"<Left>" = [
""
"i"
];
"<Right>" = [
""
"i"
];
} "Keys in what modes are disabled.";
hints =
helpers.mkNullOrOption
(
with types;
attrsOf (submodule {
options = {
message = lib.mkOption {
description = "Hint message to be displayed.";
type = helpers.nixvimTypes.rawLua;
};
disabled_filetypes = defaultNullOpts.mkListOf types.str [
"qf"
"netrw"
"NvimTree"
"lazy"
"mason"
] "`hardtime.nvim` is disabled under these filetypes.";
length = lib.mkOption {
description = "The length of actual key strokes that matches this pattern.";
type = types.ints.unsigned;
};
hints =
lib.nixvim.mkNullOrOption
(
with types;
attrsOf (submodule {
options = {
message = lib.mkOption {
description = "Hint message to be displayed.";
type = types.rawLua;
};
})
)
''
`key` is a string pattern you want to match, `value` is a table
of hint massage and pattern length.
'';
};
length = lib.mkOption {
description = "The length of actual key strokes that matches this pattern.";
type = types.ints.unsigned;
};
};
})
)
''
`key` is a string pattern you want to match, `value` is a table
of hint massage and pattern length.
'';
};
config =
let
setupOptions =
with cfg;
{
inherit
hint
notification
enabled
hints
;
max_time = maxTime;
max_count = maxCount;
disable_mouse = disableMouse;
allow_different_key = allowDifferentKey;
resetting_keys = resettingKeys;
restricted_keys = restrictedKeys;
restriction_mode = restrictionMode;
disabled_keys = disabledKeys;
disabled_filetypes = disabledFiletypes;
}
// extraOptions;
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraConfigLua = ''
require("hardtime").setup(${helpers.toLuaObject setupOptions})
'';
settingsExample = {
max_time = 1500;
settings = {
showmode = false;
};
};
}

View file

@ -7,471 +7,483 @@
plugins.hardtime = {
enable = true;
maxTime = 1000;
maxCount = 2;
disableMouse = true;
hint = true;
notification = true;
allowDifferentKey = false;
enabled = true;
restrictionMode = "block";
settings = {
max_time = 1000;
max_count = 2;
disable_mouse = true;
hint = true;
notification = true;
allow_different_key = false;
enabled = true;
restriction_mode = "block";
resettingKeys = {
"1" = [
"n"
"x"
];
"2" = [
"n"
"x"
];
"3" = [
"n"
"x"
];
"4" = [
"n"
"x"
];
"5" = [
"n"
"x"
];
"6" = [
"n"
"x"
];
"7" = [
"n"
"x"
];
"8" = [
"n"
"x"
];
"9" = [
"n"
"x"
];
"c" = [ "n" ];
"C" = [ "n" ];
"d" = [ "n" ];
"x" = [ "n" ];
"X" = [ "n" ];
"y" = [ "n" ];
"Y" = [ "n" ];
"p" = [ "n" ];
"P" = [ "n" ];
};
restrictedKeys = {
"h" = [
"n"
"x"
];
"j" = [
"n"
"x"
];
"k" = [
"n"
"x"
];
"l" = [
"n"
"x"
];
"-" = [
"n"
"x"
];
"+" = [
"n"
"x"
];
"gj" = [
"n"
"x"
];
"gk" = [
"n"
"x"
];
"<CR>" = [
"n"
"x"
];
"<C-M>" = [
"n"
"x"
];
"<C-N>" = [
"n"
"x"
];
"<C-P>" = [
"n"
"x"
];
};
disabledKeys = {
"<Up>" = [
""
"i"
];
"<Down>" = [
""
"i"
];
"<Left>" = [
""
"i"
];
"<Right>" = [
""
"i"
];
};
disabledFiletypes = [
"qf"
"netrw"
"NvimTree"
"lazy"
"mason"
];
hints = {
"[kj]%^" = {
message.__raw = ''
function(key)
return "Use "
.. (key == "k^" and "-" or "<CR> or +")
.. " instead of "
.. key
end
'';
length = 2;
resetting_keys = {
"1" = [
"n"
"x"
];
"2" = [
"n"
"x"
];
"3" = [
"n"
"x"
];
"4" = [
"n"
"x"
];
"5" = [
"n"
"x"
];
"6" = [
"n"
"x"
];
"7" = [
"n"
"x"
];
"8" = [
"n"
"x"
];
"9" = [
"n"
"x"
];
"c" = [ "n" ];
"C" = [ "n" ];
"d" = [ "n" ];
"x" = [ "n" ];
"X" = [ "n" ];
"y" = [ "n" ];
"Y" = [ "n" ];
"p" = [ "n" ];
"P" = [ "n" ];
};
"%$a" = {
message.__raw = ''
function()
return "Use A instead of $a"
end
'';
length = 2;
restricted_keys = {
"h" = [
"n"
"x"
];
"j" = [
"n"
"x"
];
"k" = [
"n"
"x"
];
"l" = [
"n"
"x"
];
"-" = [
"n"
"x"
];
"+" = [
"n"
"x"
];
"gj" = [
"n"
"x"
];
"gk" = [
"n"
"x"
];
"<CR>" = [
"n"
"x"
];
"<C-M>" = [
"n"
"x"
];
"<C-N>" = [
"n"
"x"
];
"<C-P>" = [
"n"
"x"
];
};
"%^i" = {
message.__raw = ''
function()
return "Use I instead of ^i"
end
'';
length = 2;
disabled_keys = {
"<Up>" = [
""
"i"
];
"<Down>" = [
""
"i"
];
"<Left>" = [
""
"i"
];
"<Right>" = [
""
"i"
];
};
"%D[k-]o" = {
message.__raw = ''
function(keys)
return "Use O instead of " .. keys:sub(2)
end
'';
length = 3;
};
disabled_file_types = [
"qf"
"netrw"
"NvimTree"
"lazy"
"mason"
];
"%D[j+]O" = {
message.__raw = ''
function(keys)
return "Use o instead of " .. keys:sub(2)
end
'';
length = 3;
};
"[^fFtT]li" = {
message.__raw = ''
function()
return "Use a instead of li"
end
'';
length = 3;
};
"2([dcy=<>])%1" = {
message.__raw = ''
function(key)
return "Use " .. key:sub(3) .. "j instead of " .. key
end
'';
length = 3;
};
"[^dcy=]f.h" = {
message.__raw = ''
function(keys)
return "Use t" .. keys:sub(3, 3) .. " instead of " .. keys:sub(2)
end
'';
length = 4;
};
"[^dcy=]F.l" = {
message.__raw = ''
function(keys)
return "Use T" .. keys:sub(3, 3) .. " instead of " .. keys:sub(2)
end
'';
length = 4;
};
"[^dcy=]T.h" = {
message.__raw = ''
function(keys)
return "Use F" .. keys:sub(3, 3) .. " instead of " .. keys:sub(2)
end
'';
length = 4;
};
"[^dcy=]t.l" = {
message.__raw = ''
function(keys)
return "Use f" .. keys:sub(3, 3) .. " instead of " .. keys:sub(2)
end
'';
length = 4;
};
"d[bBwWeE%^%$]i" = {
message.__raw = ''
function(keys)
return "Use " .. "c" .. keys:sub(2, 2) .. " instead of " .. keys
end
'';
length = 3;
};
"dg[eE]i" = {
message.__raw = ''
function(keys)
return "Use " .. "c" .. keys:sub(2, 3) .. " instead of " .. keys
end
'';
length = 4;
};
"d[tTfF].i" = {
message.__raw = ''
function(keys)
return "Use " .. "c" .. keys:sub(2, 3) .. " instead of " .. keys
end
'';
length = 4;
};
"d[ia][\"'`{}%[%]()<>bBwWspt]i" = {
message.__raw = ''
function(keys)
return "Use " .. "c" .. keys:sub(2, 3) .. " instead of " .. keys
end
'';
length = 4;
};
"Vgg[dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use " .. keys:sub(4, 4) .. "gg instead of " .. keys
end
'';
length = 4;
};
"Vgg\".[dy]" = {
message.__raw = ''
function(keys)
return "Use " .. keys:sub(4, 6) .. "gg instead of " .. keys
end
'';
length = 6;
};
"VG[dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use " .. keys:sub(3, 3) .. "G instead of " .. keys
end
'';
length = 3;
};
"VG\".[dy]" = {
message.__raw = ''
function(keys)
return "Use " .. keys:sub(3, 5) .. "G instead of " .. keys
end
'';
length = 5;
};
"V%d[kj][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 4)
.. keys:sub(2, 3)
hints = {
"[kj]%^" = {
message.__raw = ''
function(key)
return "Use "
.. (key == "k^" and "-" or "<CR> or +")
.. " instead of "
.. keys
end
'';
length = 4;
};
.. key
end
'';
length = 2;
};
"V%d[kj]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 6)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 6;
};
"%$a" = {
message.__raw = ''
function()
return "Use A instead of $a"
end
'';
length = 2;
};
"V%d%d[kj][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(5, 5)
.. keys:sub(2, 4)
.. " instead of "
.. keys
end
'';
length = 5;
};
"%^i" = {
message.__raw = ''
function()
return "Use I instead of ^i"
end
'';
length = 2;
};
"V%d%d[kj]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(5, 7)
.. keys:sub(2, 4)
.. " instead of "
.. keys
end
'';
length = 7;
};
"%D[k-]o" = {
message.__raw = ''
function(keys)
return "Use O instead of " .. keys:sub(2)
end
'';
length = 3;
};
"[vV][bBwWeE%^%$][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(3, 3)
.. keys:sub(2, 2)
.. " instead of "
.. keys
end
'';
length = 3;
};
"%D[j+]O" = {
message.__raw = ''
function(keys)
return "Use o instead of " .. keys:sub(2)
end
'';
length = 3;
};
"[vV][bBwWeE%^%$]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(3, 5)
.. keys:sub(2, 2)
.. " instead of "
.. keys
end
'';
length = 5;
};
"[^fFtT]li" = {
message.__raw = ''
function()
return "Use a instead of li"
end
'';
length = 3;
};
"[vV]g[eE][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 4)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 4;
};
"2([dcy=<>])%1" = {
message.__raw = ''
function(key)
return "Use " .. key:sub(3) .. "j instead of " .. key
end
'';
length = 3;
};
"[vV]g[eE]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 6)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 6;
};
"[^dcy=]f.h" = {
message.__raw = ''
function(keys)
return "Use t" .. keys:sub(3, 3) .. " instead of " .. keys:sub(2)
end
'';
length = 4;
};
"[vV][tTfF].[dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 4)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 4;
};
"[^dcy=]F.l" = {
message.__raw = ''
function(keys)
return "Use T" .. keys:sub(3, 3) .. " instead of " .. keys:sub(2)
end
'';
length = 4;
};
"[vV][tTfF].\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 6)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 6;
};
"[vV][ia][\"'`{}%[%]()<>bBwWspt][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 4)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 4;
};
"[^dcy=]T.h" = {
message.__raw = ''
function(keys)
return "Use F" .. keys:sub(3, 3) .. " instead of " .. keys:sub(2)
end
'';
length = 4;
};
"[vV][ia][\"'`{}%[%]()<>bBwWspt]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 6)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 6;
"[^dcy=]t.l" = {
message.__raw = ''
function(keys)
return "Use f" .. keys:sub(3, 3) .. " instead of " .. keys:sub(2)
end
'';
length = 4;
};
"d[bBwWeE%^%$]i" = {
message.__raw = ''
function(keys)
return "Use " .. "c" .. keys:sub(2, 2) .. " instead of " .. keys
end
'';
length = 3;
};
"dg[eE]i" = {
message.__raw = ''
function(keys)
return "Use " .. "c" .. keys:sub(2, 3) .. " instead of " .. keys
end
'';
length = 4;
};
"d[tTfF].i" = {
message.__raw = ''
function(keys)
return "Use " .. "c" .. keys:sub(2, 3) .. " instead of " .. keys
end
'';
length = 4;
};
"d[ia][\"'`{}%[%]()<>bBwWspt]i" = {
message.__raw = ''
function(keys)
return "Use " .. "c" .. keys:sub(2, 3) .. " instead of " .. keys
end
'';
length = 4;
};
"Vgg[dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use " .. keys:sub(4, 4) .. "gg instead of " .. keys
end
'';
length = 4;
};
"Vgg\".[dy]" = {
message.__raw = ''
function(keys)
return "Use " .. keys:sub(4, 6) .. "gg instead of " .. keys
end
'';
length = 6;
};
"VG[dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use " .. keys:sub(3, 3) .. "G instead of " .. keys
end
'';
length = 3;
};
"VG\".[dy]" = {
message.__raw = ''
function(keys)
return "Use " .. keys:sub(3, 5) .. "G instead of " .. keys
end
'';
length = 5;
};
"V%d[kj][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 4)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 4;
};
"V%d[kj]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 6)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 6;
};
"V%d%d[kj][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(5, 5)
.. keys:sub(2, 4)
.. " instead of "
.. keys
end
'';
length = 5;
};
"V%d%d[kj]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(5, 7)
.. keys:sub(2, 4)
.. " instead of "
.. keys
end
'';
length = 7;
};
"[vV][bBwWeE%^%$][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(3, 3)
.. keys:sub(2, 2)
.. " instead of "
.. keys
end
'';
length = 3;
};
"[vV][bBwWeE%^%$]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(3, 5)
.. keys:sub(2, 2)
.. " instead of "
.. keys
end
'';
length = 5;
};
"[vV]g[eE][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 4)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 4;
};
"[vV]g[eE]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 6)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 6;
};
"[vV][tTfF].[dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 4)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 4;
};
"[vV][tTfF].\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 6)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 6;
};
"[vV][ia][\"'`{}%[%]()<>bBwWspt][dcy=<>]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 4)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 4;
};
"[vV][ia][\"'`{}%[%]()<>bBwWspt]\".[dy]" = {
message.__raw = ''
function(keys)
return "Use "
.. keys:sub(4, 6)
.. keys:sub(2, 3)
.. " instead of "
.. keys
end
'';
length = 6;
};
};
};
};
};
example = {
plugins.hardtime = {
enable = true;
settings = {
showmode = false;
};
};
};
}