Compare commits

..

40 commits

Author SHA1 Message Date
Ching Pei Yang
2f1ce86ba4
Merge 61dc2e74d9 into e40cce5653 2024-08-23 12:26:52 +00:00
Ching Pei Yang
61dc2e74d9 flake: update lzn-auto-require 2024-08-23 14:26:44 +02:00
Ching Pei Yang
5bd9a3870d lz.n: add missing PluginSpec options 2024-08-23 14:26:44 +02:00
Ching Pei Yang
cac156bad9 add TODO 2024-08-23 14:26:44 +02:00
Ching Pei Yang
8011b8a675 lib: allow luaInline in lz.n map action 2024-08-23 14:26:44 +02:00
Ching Pei Yang
22f9ca1f6d flake: update lzn-auto-require 2024-08-23 14:26:44 +02:00
Ching Pei Yang
83432a1fb5 fixup! wrapper: use lzn-auto-require loader 2024-08-23 14:26:44 +02:00
Ching Pei Yang
5bf238006e lib: add mkSetLuaBinding 2024-08-23 14:26:44 +02:00
Ching Pei Yang
a5207983e1 wrapper: use lzn-auto-require loader 2024-08-23 14:26:44 +02:00
Ching Pei Yang
b6439bc889 flake: add plugin lzn-auto-require 2024-08-23 14:26:44 +02:00
Ching Pei Yang
0f77675e84 lz.n: generate less code 2024-08-23 14:26:44 +02:00
Ching Pei Yang
369d5a3169 lz.n: wrap lua code in function 2024-08-23 14:26:44 +02:00
Ching Pei Yang
3064acad93 lib: add mkLznBinding 2024-08-23 14:26:44 +02:00
Ching Pei Yang
2d696c99d6 nvim-tree: load nvim-tree if openOnSetup 2024-08-23 14:26:44 +02:00
Ching Pei Yang
14733b8890 nvim-tree: move to lz.n keymaps 2024-08-23 14:26:44 +02:00
Ching Pei Yang
f1676e6936 lib: add mkLznBinding 2024-08-23 14:26:44 +02:00
Ching Pei Yang
9825c65f6c lib: change lz.n spec "inlineLua" types to str 2024-08-23 14:26:44 +02:00
Ching Pei Yang
547f323ab6 lz.n: missing type check 2024-08-23 14:26:44 +02:00
Ching Pei Yang
3b6df3941d lib: add lznKeySpec example 2024-08-23 14:26:44 +02:00
Ching Pei Yang
1928851e7e lz.n: process key maps 2024-08-23 14:26:44 +02:00
Ching Pei Yang
05e18c6631 remove unused 2024-08-23 14:26:44 +02:00
Pei Yang Ching
aba0e3ec9c lib: fix lz.n map type 2024-08-23 14:26:44 +02:00
Ching Pei Yang
65f4fa41f1 lib: add lz.n KeySpec 2024-08-23 14:26:44 +02:00
Pei Yang Ching
3bf022d591 nvim-tree: use lazy 2024-08-23 14:26:44 +02:00
Pei Yang Ching
86e56965c8 lazy: add setupOpts support 2024-08-23 14:26:44 +02:00
Pei Yang Ching
5e7c92d298 fix: broken optPlugins 2024-08-23 14:26:44 +02:00
Pei Yang Ching
4402102657 switch to other hacky array-table syntax 2024-08-23 14:26:44 +02:00
Pei Yang Ching
2ff606a743 wrap lazy init code in function 2024-08-23 14:26:44 +02:00
Ching Pei Yang
6465ee7b41 flake: update lz.n 2024-08-23 14:26:44 +02:00
Ching Pei Yang
c70e9e5eb5 lib: add lznPluginTableType 2024-08-23 14:26:44 +02:00
Ching Pei Yang
67e9f8b8bc lib: export lznPluginType 2024-08-23 14:26:44 +02:00
Ching Pei Yang
cf8ef6afe7 lz.n: load lz.n 2024-08-23 14:26:44 +02:00
Ching Pei Yang
fade02f9c9 lz.n: add basic lazy.plugins option 2024-08-23 14:26:44 +02:00
Pei Yang Ching
e3e0bd0b9b lib: add basic lz.n plugin spec type 2024-08-23 14:26:44 +02:00
Pei Yang Ching
6c7cfca128 add lazy module skeleton 2024-08-23 14:26:44 +02:00
Pei Yang Ching
8f10767543 flake: add lz.n plugin 2024-08-23 14:26:44 +02:00
Pei Yang Ching
f37f90d824 maps: fix missing description 2024-08-23 14:26:44 +02:00
Ching Pei Yang
b268b5c082 remove unused 2024-08-23 14:26:44 +02:00
Pei Yang Ching
71727e5378 keymaps: update example 2024-08-23 14:26:32 +02:00
Pei Yang Ching
34b462a744 keymaps: use listOf mapOption instead 2024-08-23 14:17:24 +02:00
3 changed files with 66 additions and 37 deletions

View file

@ -4,55 +4,74 @@
...
}: let
inherit (lib.modules) mkIf mkMerge;
inherit (builtins) mapAttrs;
inherit (lib.trivial) pipe;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.lists) flatten;
processLegacyMap = modes: legacyMap: [(legacyMap // {mode = modes;})];
legacyMapModes = {
normal = ["n"];
insert = ["i"];
select = ["s"];
visual = ["v"];
terminal = ["t"];
normalVisualOp = ["n" "v" "o"];
visualOnly = ["n" "x"];
operator = ["o"];
insertCommand = ["i" "c"];
lang = ["l"];
command = ["c"];
};
cfg = config.vim;
in {
config = {
vim.keymaps = mkMerge [
(mkIf cfg.disableArrows {
"<up>" = [
(
mkIf cfg.disableArrows [
{
key = "<up>";
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
];
"<down>" = [
{
key = "<down>";
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
];
"<left>" = [
{
key = "<left>";
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
];
"<right>" = [
{
key = "<right>";
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
];
})
(mapAttrs (_key: processLegacyMap ["n"]) cfg.maps.normal)
(mapAttrs (_key: processLegacyMap ["i"]) cfg.maps.insert)
(mapAttrs (_key: processLegacyMap ["s"]) cfg.maps.select)
(mapAttrs (_key: processLegacyMap ["v"]) cfg.maps.visual)
(mapAttrs (_key: processLegacyMap ["t"]) cfg.maps.terminal)
(mapAttrs (_key: processLegacyMap ["n" "v" "o"]) cfg.maps.normalVisualOp)
(mapAttrs (_key: processLegacyMap ["n" "x"]) cfg.maps.visualOnly)
(mapAttrs (_key: processLegacyMap ["o"]) cfg.maps.operator)
(mapAttrs (_key: processLegacyMap ["i" "c"]) cfg.maps.insertCommand)
(mapAttrs (_key: processLegacyMap ["l"]) cfg.maps.lang)
(mapAttrs (_key: processLegacyMap ["c"]) cfg.maps.command)
]
)
(
pipe cfg.maps
[
(mapAttrsToList (
oldMode: keybinds:
mapAttrsToList (
key: bind:
bind
// {
inherit key;
mode = legacyMapModes.${oldMode};
}
)
keybinds
))
flatten
]
)
];
};
}

View file

@ -31,6 +31,12 @@
options =
mapConfigOptions
// {
key = mkOption {
type = str;
description = ''
Key that triggers this keybind.
'';
};
mode = mkOption {
type = either str (listOf str);
description = ''
@ -44,31 +50,36 @@
};
# legacy stuff
mapOption = submodule {
legacyMapOption = submodule {
options = mapConfigOptions;
};
mapOptions = mode:
mkOption {
description = "Mappings for ${mode} mode";
type = attrsOf mapOption;
type = attrsOf legacyMapOption;
default = {};
};
in {
options.vim = {
keymaps = mkOption {
type = submodule {
freeformType = attrsOf (listOf mapType);
};
type = listOf mapType;
description = "Custom keybindings.";
example = ''
maps = {
"<leader>m" = {
vim.keymaps = [
{
key = "<leader>m";
mode = "n";
silent = true;
action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
};
action = ":make<CR>";
}
{
key = "<leader>l";
mode = ["n" "x"];
silent = true;
action = "<cmd>cnext<CR>";
}
];
'';
default = {};
};

View file

@ -40,15 +40,14 @@ in {
inherit (keymap) desc silent nowait script expr unique noremap;
};
toLuaKeymap = key: bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
toLuaKeymap = bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject bind.key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
maps =
pipe
# attrsOf (listOf mapOption)
# listOf mapOption
cfg.keymaps
[
(mapAttrsToList (key: binds:
concatLines (map (toLuaKeymap key) binds)))
(map toLuaKeymap)
concatLines
];