mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-08 19:46:06 +01:00
plugins/multicursors: migrate to mkNeovimPlugin
This commit is contained in:
parent
ce149cac11
commit
2f8fbcdfd0
3 changed files with 213 additions and 284 deletions
|
|
@ -1,249 +1,34 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
let
|
name = "multicursors";
|
||||||
cfg = config.plugins.multicursors;
|
package = "multicursors-nvim";
|
||||||
|
|
||||||
keyOptionType =
|
maintainers = [ lib.maintainers.khaneliman ];
|
||||||
with types;
|
|
||||||
attrsOf (submodule {
|
|
||||||
options = {
|
|
||||||
method = mkOption {
|
|
||||||
type = either str (enum [ false ]);
|
|
||||||
description = ''
|
|
||||||
Assigning `"nil"` exits from multi cursor mode.
|
|
||||||
Assigning `false` removes the binding
|
|
||||||
'';
|
|
||||||
example = ''
|
|
||||||
function()
|
|
||||||
require('multicursors.utils').call_on_selections(
|
|
||||||
function(selection)
|
|
||||||
vim.api.nvim_win_set_cursor(0, { selection.row + 1, selection.col + 1 })
|
|
||||||
local line_count = selection.end_row - selection.row + 1
|
|
||||||
vim.cmd('normal ' .. line_count .. 'gcc')
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
opts = mkOption {
|
settingsExample = {
|
||||||
type = attrsOf str;
|
DEBUG_MODE = true;
|
||||||
default = { };
|
create_commands = false;
|
||||||
description = "You can pass `:map-arguments` here.";
|
normal_keys = {
|
||||||
example = {
|
|
||||||
desc = "comment selections";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
plugins.multicursors = lib.nixvim.plugins.neovim.extraOptionsOptions // {
|
|
||||||
enable = mkEnableOption "multicursors.nvim";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "multicursors.nvim" {
|
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
|
||||||
"multicursors-nvim"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
debugMode = helpers.defaultNullOpts.mkBool false "Enable debug mode.";
|
|
||||||
|
|
||||||
createCommands = helpers.defaultNullOpts.mkBool true "Create Multicursor user commands.";
|
|
||||||
|
|
||||||
updatetime = helpers.defaultNullOpts.mkUnsignedInt 50 ''
|
|
||||||
Selections get updated if this many milliseconds nothing is typed in the insert mode see
|
|
||||||
`:help updatetime`.
|
|
||||||
'';
|
|
||||||
|
|
||||||
nowait = helpers.defaultNullOpts.mkBool true "see `:help :map-nowait`.";
|
|
||||||
|
|
||||||
normalKeys = helpers.mkNullOrOption keyOptionType ''
|
|
||||||
Normal mode key mappings.
|
|
||||||
|
|
||||||
Default: see the [README.md](https://github.com/smoka7/multicursors.nvim)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
```nix
|
|
||||||
{
|
|
||||||
# to change default lhs of key mapping, change the key
|
|
||||||
"," = {
|
"," = {
|
||||||
# assigning `null` to method exits from multi cursor mode
|
method = lib.nixvim.mkRaw "require('multicursors.normal_mode').clear_others";
|
||||||
# assigning `false` to method removes the binding
|
opts = {
|
||||||
method = "require 'multicursors.normal_mode'.clear_others";
|
desc = "Clear others";
|
||||||
|
|
||||||
# you can pass :map-arguments here
|
|
||||||
opts = { desc = "Clear others"; };
|
|
||||||
};
|
};
|
||||||
"<C-/>" = {
|
|
||||||
method = \'\'
|
|
||||||
function()
|
|
||||||
require('multicursors.utils').call_on_selections(
|
|
||||||
function(selection)
|
|
||||||
vim.api.nvim_win_set_cursor(0, { selection.row + 1, selection.col + 1 })
|
|
||||||
local line_count = selection.end_row - selection.row + 1
|
|
||||||
vim.cmd('normal ' .. line_count .. 'gcc')
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
\'\';
|
|
||||||
opts = { desc = "comment selections"; };
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
```
|
|
||||||
'';
|
|
||||||
|
|
||||||
insertKeys = helpers.mkNullOrOption keyOptionType ''
|
|
||||||
Insert mode key mappings.
|
|
||||||
|
|
||||||
Default: see the [README.md](https://github.com/smoka7/multicursors.nvim)
|
|
||||||
'';
|
|
||||||
|
|
||||||
extendKeys = helpers.mkNullOrOption keyOptionType ''
|
|
||||||
Insert mode key mappings.
|
|
||||||
|
|
||||||
Default: see the [README.md](https://github.com/smoka7/multicursors.nvim)
|
|
||||||
'';
|
|
||||||
|
|
||||||
hintConfig = {
|
|
||||||
type =
|
|
||||||
helpers.mkNullOrOption
|
|
||||||
(types.enum [
|
|
||||||
"window"
|
|
||||||
"cmdline"
|
|
||||||
"statusline"
|
|
||||||
])
|
|
||||||
''
|
|
||||||
- "window": show hint in a floating window;
|
|
||||||
- "cmdline": show hint in a echo area;
|
|
||||||
- "statusline": show auto-generated hint in the statusline.
|
|
||||||
'';
|
|
||||||
|
|
||||||
position = helpers.defaultNullOpts.mkEnum [
|
|
||||||
"top-left"
|
|
||||||
"top"
|
|
||||||
"top-right"
|
|
||||||
"middle-left"
|
|
||||||
"middle"
|
|
||||||
"middle-right"
|
|
||||||
"bottom-left"
|
|
||||||
"bottom"
|
|
||||||
"bottom-right"
|
|
||||||
] "bottom" "Set the position of the hint.";
|
|
||||||
|
|
||||||
offset = helpers.mkNullOrOption types.int ''
|
|
||||||
The offset from the nearest editor border.
|
|
||||||
(valid when `type` if `"window"`).
|
|
||||||
'';
|
|
||||||
|
|
||||||
border = helpers.defaultNullOpts.mkBorder "none" "the hint window" "";
|
|
||||||
|
|
||||||
showName = helpers.mkNullOrOption types.bool ''
|
|
||||||
Show hydras name or `HYDRA:` label at the beginning of an auto-generated hint.
|
|
||||||
'';
|
|
||||||
|
|
||||||
funcs = helpers.mkNullOrOption (with types; attrsOf str) ''
|
|
||||||
Attrs where keys are function names and values are functions themselves.
|
|
||||||
Each function should return string.
|
|
||||||
This functions can be required from hint with `%{func_name}` syntaxis.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
hint_config = {
|
||||||
generateHints =
|
type = "cmdline";
|
||||||
genAttrs
|
position = "top";
|
||||||
[
|
|
||||||
"normal"
|
|
||||||
"insert"
|
|
||||||
"extend"
|
|
||||||
]
|
|
||||||
(
|
|
||||||
mode:
|
|
||||||
helpers.defaultNullOpts.mkNullable (with types; either bool str) false ''
|
|
||||||
Hints for ${mode} mode.
|
|
||||||
|
|
||||||
Accepted values:
|
|
||||||
- `true`: generate hints
|
|
||||||
- `false`: don't generate hints
|
|
||||||
- str: provide your own hints
|
|
||||||
''
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
# TODO: Deprecated 2025-10-04
|
||||||
let
|
inherit (import ./deprecations.nix lib)
|
||||||
setupOptions =
|
imports
|
||||||
with cfg;
|
optionsRenamedToSettings
|
||||||
let
|
deprecateExtraOptions
|
||||||
mkMaps =
|
|
||||||
value:
|
|
||||||
helpers.ifNonNull' value (
|
|
||||||
mapAttrs (
|
|
||||||
key: mapping: with mapping; {
|
|
||||||
method =
|
|
||||||
# `false`
|
|
||||||
if isBool method then method else helpers.mkRaw method;
|
|
||||||
inherit opts;
|
|
||||||
}
|
|
||||||
) value
|
|
||||||
);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
DEBUG_MODE = debugMode;
|
|
||||||
create_commands = createCommands;
|
|
||||||
inherit updatetime nowait;
|
|
||||||
normal_keys = mkMaps normalKeys;
|
|
||||||
insert_keys = mkMaps insertKeys;
|
|
||||||
extend_keys = mkMaps extendKeys;
|
|
||||||
hint_config = with hintConfig; {
|
|
||||||
inherit
|
|
||||||
type
|
|
||||||
position
|
|
||||||
offset
|
|
||||||
border
|
|
||||||
;
|
;
|
||||||
show_name = showName;
|
|
||||||
funcs = helpers.ifNonNull' funcs (mapAttrs (name: helpers.mkRaw) funcs);
|
|
||||||
};
|
|
||||||
generate_hints =
|
|
||||||
genAttrs
|
|
||||||
[
|
|
||||||
"normal"
|
|
||||||
"insert"
|
|
||||||
"extend"
|
|
||||||
]
|
|
||||||
(
|
|
||||||
mode:
|
|
||||||
let
|
|
||||||
value = generateHints.${mode};
|
|
||||||
in
|
|
||||||
helpers.ifNonNull' value (
|
|
||||||
if isBool value then
|
|
||||||
value
|
|
||||||
else
|
|
||||||
helpers.mkRaw ''
|
|
||||||
[[
|
|
||||||
${value}
|
|
||||||
]]
|
|
||||||
''
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// extraOptions;
|
|
||||||
in
|
|
||||||
mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
extraConfigLua = ''
|
|
||||||
require("multicursors").setup(${lib.nixvim.toLuaObject setupOptions})
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
107
plugins/by-name/multicursors/deprecations.nix
Normal file
107
plugins/by-name/multicursors/deprecations.nix
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
lib:
|
||||||
|
let
|
||||||
|
# Helper function to transform key mappings with mkRaw wrapping
|
||||||
|
mkMaps =
|
||||||
|
value:
|
||||||
|
lib.nixvim.ifNonNull' value (
|
||||||
|
lib.mapAttrs (
|
||||||
|
_key: mapping: with mapping; {
|
||||||
|
method = if lib.isBool method then method else lib.nixvim.mkRaw method;
|
||||||
|
inherit opts;
|
||||||
|
}
|
||||||
|
) value
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
# TODO: added 2025-10-04
|
||||||
|
deprecateExtraOptions = true;
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
# Custom transformations for normalKeys, insertKeys, extendKeys
|
||||||
|
(lib.mkChangedOptionModule
|
||||||
|
[
|
||||||
|
"plugins"
|
||||||
|
"multicursors"
|
||||||
|
"normalKeys"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"plugins"
|
||||||
|
"multicursors"
|
||||||
|
"settings"
|
||||||
|
"normal_keys"
|
||||||
|
]
|
||||||
|
(config: mkMaps (lib.getAttrFromPath [ "plugins" "multicursors" "normalKeys" ] config))
|
||||||
|
)
|
||||||
|
(lib.mkChangedOptionModule
|
||||||
|
[
|
||||||
|
"plugins"
|
||||||
|
"multicursors"
|
||||||
|
"insertKeys"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"plugins"
|
||||||
|
"multicursors"
|
||||||
|
"settings"
|
||||||
|
"insert_keys"
|
||||||
|
]
|
||||||
|
(config: mkMaps (lib.getAttrFromPath [ "plugins" "multicursors" "insertKeys" ] config))
|
||||||
|
)
|
||||||
|
(lib.mkChangedOptionModule
|
||||||
|
[
|
||||||
|
"plugins"
|
||||||
|
"multicursors"
|
||||||
|
"extendKeys"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"plugins"
|
||||||
|
"multicursors"
|
||||||
|
"settings"
|
||||||
|
"extend_keys"
|
||||||
|
]
|
||||||
|
(config: mkMaps (lib.getAttrFromPath [ "plugins" "multicursors" "extendKeys" ] config))
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
"debugMode"
|
||||||
|
"createCommands"
|
||||||
|
"updatetime"
|
||||||
|
"nowait"
|
||||||
|
[
|
||||||
|
"hintConfig"
|
||||||
|
"type"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"hintConfig"
|
||||||
|
"position"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"hintConfig"
|
||||||
|
"offset"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"hintConfig"
|
||||||
|
"border"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"hintConfig"
|
||||||
|
"showName"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"hintConfig"
|
||||||
|
"funcs"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"generateHints"
|
||||||
|
"normal"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"generateHints"
|
||||||
|
"insert"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"generateHints"
|
||||||
|
"extend"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,44 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
{
|
{
|
||||||
empty = {
|
empty = {
|
||||||
# ERROR: [Hydra.nvim] Option "hint.border" has been deprecated and will be removed on 2024-02-01 -- See hint.float_opts
|
plugins.multicursors.enable = true;
|
||||||
# Will be fixed by:
|
};
|
||||||
# https://github.com/smoka7/multicursors.nvim/pull/91
|
|
||||||
plugins.multicursors.enable = false;
|
defaults = {
|
||||||
|
plugins.multicursors = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
DEBUG_MODE = false;
|
||||||
|
create_commands = true;
|
||||||
|
updatetime = 50;
|
||||||
|
nowait = true;
|
||||||
|
mode_keys = {
|
||||||
|
append = "a";
|
||||||
|
change = "c";
|
||||||
|
extend = "e";
|
||||||
|
insert = "i";
|
||||||
|
};
|
||||||
|
hint_config = {
|
||||||
|
float_opts = {
|
||||||
|
border = "none";
|
||||||
|
};
|
||||||
|
position = "bottom";
|
||||||
|
};
|
||||||
|
generate_hints = {
|
||||||
|
normal = true;
|
||||||
|
insert = true;
|
||||||
|
extend = true;
|
||||||
|
config = {
|
||||||
|
column_count = null;
|
||||||
|
max_hint_length = 25;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
example = {
|
example = {
|
||||||
|
|
@ -13,16 +48,17 @@
|
||||||
# https://github.com/smoka7/multicursors.nvim/pull/91
|
# https://github.com/smoka7/multicursors.nvim/pull/91
|
||||||
enable = false;
|
enable = false;
|
||||||
|
|
||||||
debugMode = false;
|
settings = {
|
||||||
createCommands = true;
|
DEBUG_MODE = false;
|
||||||
|
create_commands = true;
|
||||||
updatetime = 50;
|
updatetime = 50;
|
||||||
nowait = true;
|
nowait = true;
|
||||||
normalKeys = {
|
normal_keys = {
|
||||||
# to change default lhs of key mapping, change the key
|
# to change default lhs of key mapping, change the key
|
||||||
"," = {
|
"," = {
|
||||||
# assigning `null` to method exits from multi cursor mode
|
# assigning `null` to method exits from multi cursor mode
|
||||||
# assigning `false` to method removes the binding
|
# assigning `false` to method removes the binding
|
||||||
method = "require 'multicursors.normal_mode'.clear_others";
|
method = lib.nixvim.mkRaw "require('multicursors.normal_mode').clear_others";
|
||||||
|
|
||||||
# you can pass :map-arguments here
|
# you can pass :map-arguments here
|
||||||
opts = {
|
opts = {
|
||||||
|
|
@ -30,7 +66,7 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
"<C-/>" = {
|
"<C-/>" = {
|
||||||
method = ''
|
method = lib.nixvim.mkRaw ''
|
||||||
function()
|
function()
|
||||||
require('multicursors.utils').call_on_selections(
|
require('multicursors.utils').call_on_selections(
|
||||||
function(selection)
|
function(selection)
|
||||||
|
|
@ -46,21 +82,22 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
insertKeys = null;
|
insert_keys = null;
|
||||||
extendKeys = null;
|
extend_keys = null;
|
||||||
hintConfig = {
|
hint_config = {
|
||||||
type = "window";
|
type = "window";
|
||||||
position = "bottom";
|
position = "bottom";
|
||||||
offset = 0;
|
offset = 0;
|
||||||
border = "none";
|
border = "none";
|
||||||
showName = true;
|
show_name = true;
|
||||||
funcs = null;
|
funcs = null;
|
||||||
};
|
};
|
||||||
generateHints = {
|
generate_hints = {
|
||||||
normal = false;
|
normal = false;
|
||||||
insert = false;
|
insert = false;
|
||||||
extend = false;
|
extend = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue