mirror of
https://github.com/nix-community/nixvim.git
synced 2025-12-17 06:21:13 +01:00
plugins/leap: migrate to mkNeovimPlugin
This commit is contained in:
parent
a33eee710f
commit
35b7251d83
3 changed files with 88 additions and 260 deletions
|
|
@ -1,191 +1,42 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
cfg = config.plugins.leap;
|
inherit (lib) types;
|
||||||
in
|
in
|
||||||
{
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
options.plugins.leap = lib.nixvim.plugins.neovim.extraOptionsOptions // {
|
name = "leap";
|
||||||
enable = mkEnableOption "leap.nvim";
|
package = "leap-nvim";
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "leap.nvim" {
|
maintainers = [ lib.maintainers.khaneliman ];
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
|
||||||
"leap-nvim"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
addDefaultMappings = mkOption {
|
extraOptions = {
|
||||||
|
addDefaultMappings = lib.mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = "Whether to enable the default mappings.";
|
description = "Whether to enable the default mappings.";
|
||||||
};
|
};
|
||||||
|
|
||||||
maxPhaseOneTargets = helpers.mkNullOrOption types.int ''
|
|
||||||
By default, the plugin shows labels and/or highlights matches right after the first input
|
|
||||||
character.
|
|
||||||
This option disables ahead-of-time displaying of target beacons beyond a certain number of
|
|
||||||
phase one targets (to mitigate visual noise in extreme cases).
|
|
||||||
Setting it to 0 disables two-phase processing altogether.
|
|
||||||
'';
|
|
||||||
|
|
||||||
highlightUnlabeledPhaseOneTargets = helpers.defaultNullOpts.mkBool false ''
|
|
||||||
Whether to highlight unlabeled (i.e., directly reachable) matches after the first input
|
|
||||||
character.
|
|
||||||
'';
|
|
||||||
|
|
||||||
maxHighlightedTraversalTargets = helpers.defaultNullOpts.mkInt 10 ''
|
|
||||||
Number of targets to be highlighted after the cursor in `|leap-traversal|` mode (when there
|
|
||||||
are no labels at all).
|
|
||||||
'';
|
|
||||||
|
|
||||||
caseSensitive = helpers.defaultNullOpts.mkBool false ''
|
|
||||||
Whether to consider case in search patterns.
|
|
||||||
'';
|
|
||||||
|
|
||||||
equivalenceClasses = helpers.defaultNullOpts.mkListOf' {
|
|
||||||
type = with types; either str (listOf str);
|
|
||||||
description = ''
|
|
||||||
A character will match any other in its equivalence class. The sets can
|
|
||||||
either be defined as strings or tables.
|
|
||||||
|
|
||||||
Note: Make sure to have a set containing `\n` if you want to be able to
|
|
||||||
target characters at the end of the line.
|
|
||||||
|
|
||||||
Note: Non-mutual aliases are not possible in Leap, for the same reason
|
|
||||||
that supporting |smartcase| is not possible: we would need to show two
|
|
||||||
different labels, corresponding to two different futures, at the same
|
|
||||||
time.
|
|
||||||
'';
|
|
||||||
pluginDefault = [ " \t\r\n" ];
|
|
||||||
example = [
|
|
||||||
"\r\n"
|
|
||||||
")]}>"
|
|
||||||
"([{<"
|
|
||||||
[
|
|
||||||
"\""
|
|
||||||
"'"
|
|
||||||
"`"
|
|
||||||
]
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
substituteChars = helpers.defaultNullOpts.mkAttrsOf' {
|
callSetup = false;
|
||||||
type = types.str;
|
extraConfig = cfg: {
|
||||||
description = ''
|
plugins.leap.luaConfig.content =
|
||||||
The keys in this attrs will be substituted in labels and highlighted matches by the given
|
lib.optionalString cfg.addDefaultMappings ''
|
||||||
characters.
|
|
||||||
This way special (e.g. whitespace) characters can be made visible in matches, or even be
|
|
||||||
used as labels.
|
|
||||||
'';
|
|
||||||
pluginDefault = { };
|
|
||||||
example = {
|
|
||||||
"\r" = "¬";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
safeLabels =
|
|
||||||
helpers.defaultNullOpts.mkNullable (with lib.types; maybeRaw (listOf str))
|
|
||||||
(stringToCharacters "sfnut/SFNLHMUGT?Z")
|
|
||||||
''
|
|
||||||
When the number of matches does not exceed the number of these "safe" labels plus one, the
|
|
||||||
plugin jumps to the first match automatically after entering the pattern.
|
|
||||||
Obviously, for this purpose you should choose keys that are unlikely to be used right
|
|
||||||
after a jump!
|
|
||||||
|
|
||||||
Setting the list to `[]` effectively disables the autojump feature.
|
|
||||||
|
|
||||||
Note: Operator-pending mode ignores this, since we need to be able to select the actual
|
|
||||||
target before executing the operation.
|
|
||||||
'';
|
|
||||||
|
|
||||||
labels =
|
|
||||||
helpers.defaultNullOpts.mkListOf types.str
|
|
||||||
(stringToCharacters "sfnjklhodwembuyvrgtcx/zSFNJKLHODWEMBUYVRGTCX?Z")
|
|
||||||
''
|
|
||||||
Target labels to be used when there are more matches than labels in
|
|
||||||
`|leap.opts.safe_labels|` plus one.
|
|
||||||
|
|
||||||
Setting the list to `[]` forces autojump to always be on (except for Operator-pending
|
|
||||||
mode, where it makes no sense).
|
|
||||||
In this case, do not forget to set `special_keys.next_group` to something "safe" too.
|
|
||||||
'';
|
|
||||||
|
|
||||||
specialKeys = {
|
|
||||||
nextTarget = helpers.defaultNullOpts.mkStr "<enter>" ''
|
|
||||||
Key captured by the plugin at runtime to jump to the next match in traversal mode
|
|
||||||
(`|leap-traversal|`)
|
|
||||||
'';
|
|
||||||
|
|
||||||
prevTarget = helpers.defaultNullOpts.mkStr "<tab>" ''
|
|
||||||
Key captured by the plugin at runtime to jump to the previous match in traversal mode
|
|
||||||
(`|leap-traversal|`)
|
|
||||||
'';
|
|
||||||
|
|
||||||
nextGroup = helpers.defaultNullOpts.mkStr "<space>" ''
|
|
||||||
Key captured by the plugin at runtime to switch to the next group of matches, when there
|
|
||||||
are more matches than available labels.
|
|
||||||
'';
|
|
||||||
|
|
||||||
prevGroup = helpers.defaultNullOpts.mkStr "<tab>" ''
|
|
||||||
Key captured by the plugin at runtime to switch to the previous group of matches, when
|
|
||||||
there are more matches than available labels.
|
|
||||||
'';
|
|
||||||
|
|
||||||
multiAccept = helpers.defaultNullOpts.mkStr "<enter>" ''
|
|
||||||
Key captured by the plugin at runtime to accept the selection in `|leap-multiselect|`
|
|
||||||
mode.
|
|
||||||
'';
|
|
||||||
|
|
||||||
multiRevert = helpers.defaultNullOpts.mkStr "<backspace>" ''
|
|
||||||
Key captured by the plugin at runtime to deselect the last selected target in
|
|
||||||
`|leap-multiselect|` mode.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config =
|
|
||||||
let
|
|
||||||
options =
|
|
||||||
with cfg;
|
|
||||||
{
|
|
||||||
max_phase_one_targets = maxPhaseOneTargets;
|
|
||||||
highlight_unlabeled_phase_one_targets = highlightUnlabeledPhaseOneTargets;
|
|
||||||
max_highlighted_traversal_targets = maxHighlightedTraversalTargets;
|
|
||||||
case_sensitive = caseSensitive;
|
|
||||||
equivalence_classes = equivalenceClasses;
|
|
||||||
substitute_chars = substituteChars;
|
|
||||||
safe_labels = safeLabels;
|
|
||||||
inherit labels;
|
|
||||||
special_keys = with specialKeys; {
|
|
||||||
next_target = nextTarget;
|
|
||||||
prev_target = prevTarget;
|
|
||||||
next_group = nextGroup;
|
|
||||||
prev_group = prevGroup;
|
|
||||||
multi_accept = multiAccept;
|
|
||||||
multi_revert = multiRevert;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// cfg.extraOptions;
|
|
||||||
in
|
|
||||||
mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
extraConfigLua =
|
|
||||||
(optionalString cfg.addDefaultMappings ''
|
|
||||||
require('leap').add_default_mappings()
|
require('leap').add_default_mappings()
|
||||||
'')
|
''
|
||||||
+ (optionalString (options != { }) ''
|
+ lib.optionalString (cfg.settings != { }) ''
|
||||||
require('leap').opts = vim.tbl_deep_extend(
|
require('leap').opts = vim.tbl_deep_extend(
|
||||||
"keep",
|
"keep",
|
||||||
${lib.nixvim.toLuaObject options},
|
${lib.nixvim.toLuaObject cfg.settings},
|
||||||
require('leap').opts
|
require('leap').opts
|
||||||
)
|
)
|
||||||
'');
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# TODO: Deprecated 2025-10-04
|
||||||
|
inherit (import ./deprecations.nix)
|
||||||
|
optionsRenamedToSettings
|
||||||
|
deprecateExtraOptions
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
38
plugins/by-name/leap/deprecations.nix
Normal file
38
plugins/by-name/leap/deprecations.nix
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
# TODO: added 2025-10-04
|
||||||
|
deprecateExtraOptions = true;
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
"maxPhaseOneTargets"
|
||||||
|
"highlightUnlabeledPhaseOneTargets"
|
||||||
|
"maxHighlightedTraversalTargets"
|
||||||
|
"caseSensitive"
|
||||||
|
"equivalenceClasses"
|
||||||
|
"substituteChars"
|
||||||
|
"safeLabels"
|
||||||
|
"labels"
|
||||||
|
[
|
||||||
|
"specialKeys"
|
||||||
|
"nextTarget"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"specialKeys"
|
||||||
|
"prevTarget"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"specialKeys"
|
||||||
|
"nextGroup"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"specialKeys"
|
||||||
|
"prevGroup"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"specialKeys"
|
||||||
|
"multiAccept"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"specialKeys"
|
||||||
|
"multiRevert"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
{
|
{
|
||||||
empty = {
|
empty = {
|
||||||
plugins.leap.enable = true;
|
plugins.leap.enable = true;
|
||||||
|
|
@ -7,98 +11,33 @@
|
||||||
autojump-disabled = {
|
autojump-disabled = {
|
||||||
plugins.leap = {
|
plugins.leap = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
settings.safe_labels.__empty = null;
|
||||||
safeLabels.__empty = null;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
example = {
|
example = {
|
||||||
plugins.leap = {
|
plugins.leap = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
addDefaultMappings = true;
|
addDefaultMappings = true;
|
||||||
maxPhaseOneTargets = 10;
|
settings = {
|
||||||
highlightUnlabeledPhaseOneTargets = false;
|
max_phase_one_targets = 10;
|
||||||
maxHighlightedTraversalTargets = 10;
|
highlight_unlabeled_phase_one_targets = false;
|
||||||
caseSensitive = false;
|
max_highlighted_traversal_targets = 10;
|
||||||
equivalenceClasses = [ " \t\r\n" ];
|
case_sensitive = false;
|
||||||
substituteChars = {
|
equivalence_classes = [ " \t\r\n" ];
|
||||||
|
substitute_chars = {
|
||||||
"\r" = "¬";
|
"\r" = "¬";
|
||||||
};
|
};
|
||||||
safeLabels = [
|
safe_labels = lib.stringToCharacters "sfnut/SFNLHMUGT?Z";
|
||||||
"s"
|
labels = lib.stringToCharacters "sfnjklhodwembuyvrgtcx/zSFNJKLHODWEMBUYVRGTCX?Z";
|
||||||
"f"
|
special_keys = {
|
||||||
"n"
|
next_target = "<enter>";
|
||||||
"u"
|
prev_target = "<tab>";
|
||||||
"t"
|
next_group = "<space>";
|
||||||
"/"
|
prev_group = "<tab>";
|
||||||
"S"
|
multi_accept = "<enter>";
|
||||||
"F"
|
multi_revert = "<backspace>";
|
||||||
"N"
|
};
|
||||||
"L"
|
|
||||||
"H"
|
|
||||||
"M"
|
|
||||||
"U"
|
|
||||||
"G"
|
|
||||||
"T"
|
|
||||||
"?"
|
|
||||||
"Z"
|
|
||||||
];
|
|
||||||
labels = [
|
|
||||||
"s"
|
|
||||||
"f"
|
|
||||||
"n"
|
|
||||||
"j"
|
|
||||||
"k"
|
|
||||||
"l"
|
|
||||||
"h"
|
|
||||||
"o"
|
|
||||||
"d"
|
|
||||||
"w"
|
|
||||||
"e"
|
|
||||||
"m"
|
|
||||||
"b"
|
|
||||||
"u"
|
|
||||||
"y"
|
|
||||||
"v"
|
|
||||||
"r"
|
|
||||||
"g"
|
|
||||||
"t"
|
|
||||||
"c"
|
|
||||||
"x"
|
|
||||||
"/"
|
|
||||||
"z"
|
|
||||||
"S"
|
|
||||||
"F"
|
|
||||||
"N"
|
|
||||||
"J"
|
|
||||||
"K"
|
|
||||||
"L"
|
|
||||||
"H"
|
|
||||||
"O"
|
|
||||||
"D"
|
|
||||||
"W"
|
|
||||||
"E"
|
|
||||||
"M"
|
|
||||||
"B"
|
|
||||||
"U"
|
|
||||||
"Y"
|
|
||||||
"V"
|
|
||||||
"R"
|
|
||||||
"G"
|
|
||||||
"T"
|
|
||||||
"C"
|
|
||||||
"X"
|
|
||||||
"?"
|
|
||||||
"Z"
|
|
||||||
];
|
|
||||||
specialKeys = {
|
|
||||||
nextTarget = "<enter>";
|
|
||||||
prevTarget = "<tab>";
|
|
||||||
nextGroup = "<space>";
|
|
||||||
prevGroup = "<tab>";
|
|
||||||
multiAccept = "<enter>";
|
|
||||||
multiRevert = "<backspace>";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue