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

View file

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