diff --git a/plugins/by-name/multicursors/default.nix b/plugins/by-name/multicursors/default.nix
index 8f74daa8..96dde916 100644
--- a/plugins/by-name/multicursors/default.nix
+++ b/plugins/by-name/multicursors/default.nix
@@ -1,249 +1,34 @@
{
lib,
- helpers,
- config,
- pkgs,
...
}:
-with lib;
-let
- cfg = config.plugins.multicursors;
+lib.nixvim.plugins.mkNeovimPlugin {
+ name = "multicursors";
+ package = "multicursors-nvim";
- keyOptionType =
- 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
- '';
- };
+ maintainers = [ lib.maintainers.khaneliman ];
- opts = mkOption {
- type = attrsOf str;
- default = { };
- description = "You can pass `:map-arguments` here.";
- example = {
- desc = "comment selections";
- };
+ settingsExample = {
+ DEBUG_MODE = true;
+ create_commands = false;
+ normal_keys = {
+ "," = {
+ method = lib.nixvim.mkRaw "require('multicursors.normal_mode').clear_others";
+ opts = {
+ desc = "Clear others";
};
};
- });
-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
- # assigning `false` to method removes the binding
- method = "require 'multicursors.normal_mode'.clear_others";
-
- # you can pass :map-arguments here
- opts = { desc = "Clear others"; };
- };
- "" = {
- 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.
- '';
- };
-
- generateHints =
- genAttrs
- [
- "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
- ''
- );
+ };
+ hint_config = {
+ type = "cmdline";
+ position = "top";
};
};
- config =
- let
- setupOptions =
- with cfg;
- let
- 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})
- '';
- };
+ # TODO: Deprecated 2025-10-04
+ inherit (import ./deprecations.nix lib)
+ imports
+ optionsRenamedToSettings
+ deprecateExtraOptions
+ ;
}
diff --git a/plugins/by-name/multicursors/deprecations.nix b/plugins/by-name/multicursors/deprecations.nix
new file mode 100644
index 00000000..59fdb8bf
--- /dev/null
+++ b/plugins/by-name/multicursors/deprecations.nix
@@ -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"
+ ]
+ ];
+}
diff --git a/tests/test-sources/plugins/by-name/multicursors/default.nix b/tests/test-sources/plugins/by-name/multicursors/default.nix
index d1e72ddd..5131ecc9 100644
--- a/tests/test-sources/plugins/by-name/multicursors/default.nix
+++ b/tests/test-sources/plugins/by-name/multicursors/default.nix
@@ -1,9 +1,44 @@
+{
+ lib,
+ ...
+}:
{
empty = {
- # ERROR: [Hydra.nvim] Option "hint.border" has been deprecated and will be removed on 2024-02-01 -- See hint.float_opts
- # Will be fixed by:
- # https://github.com/smoka7/multicursors.nvim/pull/91
- plugins.multicursors.enable = false;
+ plugins.multicursors.enable = true;
+ };
+
+ 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 = {
@@ -13,53 +48,55 @@
# https://github.com/smoka7/multicursors.nvim/pull/91
enable = false;
- debugMode = false;
- createCommands = true;
- updatetime = 50;
- nowait = true;
- normalKeys = {
- # to change default lhs of key mapping, change the key
- "," = {
- # assigning `null` to method exits from multi cursor mode
- # assigning `false` to method removes the binding
- method = "require 'multicursors.normal_mode'.clear_others";
+ settings = {
+ DEBUG_MODE = false;
+ create_commands = true;
+ updatetime = 50;
+ nowait = true;
+ normal_keys = {
+ # to change default lhs of key mapping, change the key
+ "," = {
+ # assigning `null` to method exits from multi cursor mode
+ # assigning `false` to method removes the binding
+ method = lib.nixvim.mkRaw "require('multicursors.normal_mode').clear_others";
- # you can pass :map-arguments here
- opts = {
- desc = "Clear others";
+ # you can pass :map-arguments here
+ opts = {
+ desc = "Clear others";
+ };
+ };
+ "" = {
+ method = lib.nixvim.mkRaw ''
+ 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";
+ };
};
};
- "" = {
- 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";
- };
+ insert_keys = null;
+ extend_keys = null;
+ hint_config = {
+ type = "window";
+ position = "bottom";
+ offset = 0;
+ border = "none";
+ show_name = true;
+ funcs = null;
+ };
+ generate_hints = {
+ normal = false;
+ insert = false;
+ extend = false;
};
- };
- insertKeys = null;
- extendKeys = null;
- hintConfig = {
- type = "window";
- position = "bottom";
- offset = 0;
- border = "none";
- showName = true;
- funcs = null;
- };
- generateHints = {
- normal = false;
- insert = false;
- extend = false;
};
};
};