mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
plugins/lz-n: add support for keymap(<plugin>).set API
Add a new `keymaps` option to the lz-n plugin that allows users to define keymaps that use lz.n's keymap(<plugin>).set functionality. This enables users to create keymaps that lazy-load plugins when specific keys are pressed, using the familiar vim.keymap.set() API style. The implementation: - Adds a new `keymaps` option using mkMapOptionSubmodule with a custom plugin property - Exposes a simple and consistent interface for configuring lazy-loaded keymaps - Processes these keymaps to generate corresponding Lua code with require('lz.n').keymap().set() - Cleanly separates plugin specs from keymap definitions while preserving their relationship
This commit is contained in:
parent
210af12eac
commit
03a0561a8f
1 changed files with 53 additions and 5 deletions
|
@ -7,16 +7,19 @@ let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
id
|
id
|
||||||
literalMD
|
literalMD
|
||||||
mkIf
|
mkMerge
|
||||||
mkOption
|
mkOption
|
||||||
|
optional
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
inherit (lib.nixvim)
|
inherit (lib.nixvim)
|
||||||
defaultNullOpts
|
defaultNullOpts
|
||||||
mkNullOrLuaFn
|
mkNullOrLuaFn
|
||||||
mkNullOrOption'
|
mkNullOrOption'
|
||||||
|
nestedLiteralLua
|
||||||
toLuaObject
|
toLuaObject
|
||||||
;
|
;
|
||||||
|
inherit (lib.nixvim.keymaps) mkMapOptionSubmodule;
|
||||||
in
|
in
|
||||||
lib.nixvim.plugins.mkNeovimPlugin {
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
name = "lz-n";
|
name = "lz-n";
|
||||||
|
@ -146,6 +149,40 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
keymaps = mkOption {
|
||||||
|
type = types.listOf (mkMapOptionSubmodule {
|
||||||
|
extraOptions.plugin = mkOption {
|
||||||
|
type = with types; either str lzPluginType;
|
||||||
|
example = "telescope.nvim";
|
||||||
|
description = ''
|
||||||
|
The plugin (name or spec) to lazy-load when the keymap is triggered.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This must match the name used in the `plugins` list or be a valid plugin that can be loaded.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = [ ];
|
||||||
|
example = [
|
||||||
|
{
|
||||||
|
plugin = "telescope.nvim";
|
||||||
|
key = "<leader>ff";
|
||||||
|
action = nestedLiteralLua "function() require('telescope.builtin').find_files() end";
|
||||||
|
options.desc = "Find files";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
plugin = "neo-tree.nvim";
|
||||||
|
key = "<leader>ft";
|
||||||
|
action = "<CMD>Neotree toggle<CR>";
|
||||||
|
options.desc = "NeoTree toggle";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
description = ''
|
||||||
|
Define keymaps that will use lz.n's `keymap(<plugin>).set` functionality.
|
||||||
|
This provides a more intuitive way to define lazy-loaded keymaps with the familiar `keymaps` option API style.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
plugins = mkOption {
|
plugins = mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
List of plugin specs provided to the `require('lz.n').load` function.
|
List of plugin specs provided to the `require('lz.n').load` function.
|
||||||
|
@ -158,7 +195,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
__unkeyed-1 = "neo-tree.nvim";
|
__unkeyed-1 = "neo-tree.nvim";
|
||||||
enabled = ''
|
enabled = ''
|
||||||
function()
|
function()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
keys = [
|
keys = [
|
||||||
|
@ -208,8 +245,19 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
|
|
||||||
extraConfig = cfg: {
|
extraConfig = cfg: {
|
||||||
globals.lz_n = lib.modules.mkAliasAndWrapDefsWithPriority id options.plugins.lz-n.settings;
|
globals.lz_n = lib.modules.mkAliasAndWrapDefsWithPriority id options.plugins.lz-n.settings;
|
||||||
plugins.lz-n.luaConfig.content = mkIf (cfg.plugins != [ ]) ''
|
plugins.lz-n.luaConfig.content = mkMerge (
|
||||||
require('lz.n').load( ${toLuaObject cfg.plugins})
|
optional (cfg.plugins != [ ]) "require('lz.n').load(${toLuaObject cfg.plugins})"
|
||||||
'';
|
++ map (
|
||||||
|
{
|
||||||
|
plugin,
|
||||||
|
mode,
|
||||||
|
key,
|
||||||
|
action,
|
||||||
|
options,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
"require('lz.n').keymap(${toLuaObject plugin}).set(${toLuaObject mode}, ${toLuaObject key}, ${toLuaObject action}, ${toLuaObject options})"
|
||||||
|
) cfg.keymaps
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue