Compare commits

..

42 commits

Author SHA1 Message Date
Ching Pei Yang
51035c5468
Merge 477f2fb8c7 into e40cce5653 2024-08-23 12:34:43 +00:00
Ching Pei Yang
477f2fb8c7 flake: update lzn-auto-require 2024-08-23 14:34:25 +02:00
Ching Pei Yang
7bace58ab4 lz.n: add missing PluginSpec options 2024-08-23 14:34:25 +02:00
Ching Pei Yang
ca86aaa3af add TODO 2024-08-23 14:34:25 +02:00
Ching Pei Yang
c991b2adea lib: allow luaInline in lz.n map action 2024-08-23 14:34:25 +02:00
Ching Pei Yang
6d42de8aba flake: update lzn-auto-require 2024-08-23 14:34:25 +02:00
Ching Pei Yang
39ebfbcd98 fixup! wrapper: use lzn-auto-require loader 2024-08-23 14:34:25 +02:00
Ching Pei Yang
0daad3e51a lib: add mkSetLuaBinding 2024-08-23 14:34:25 +02:00
Ching Pei Yang
7075872810 wrapper: use lzn-auto-require loader 2024-08-23 14:34:25 +02:00
Ching Pei Yang
4e13acfac3 flake: add plugin lzn-auto-require 2024-08-23 14:33:39 +02:00
Ching Pei Yang
3a88caeda6 lz.n: generate less code 2024-08-23 14:33:39 +02:00
Ching Pei Yang
4c230a0460 lz.n: wrap lua code in function 2024-08-23 14:33:39 +02:00
Ching Pei Yang
cfaa2e3e77 lib: add mkLznBinding 2024-08-23 14:33:39 +02:00
Ching Pei Yang
217079b546 nvim-tree: load nvim-tree if openOnSetup 2024-08-23 14:33:39 +02:00
Ching Pei Yang
6fe0103209 nvim-tree: move to lz.n keymaps 2024-08-23 14:33:39 +02:00
Ching Pei Yang
6d2d9cd60e lib: add mkLznBinding 2024-08-23 14:33:39 +02:00
Ching Pei Yang
b1cc8bb27b lib: change lz.n spec "inlineLua" types to str 2024-08-23 14:33:39 +02:00
Ching Pei Yang
90dd876c53 lz.n: missing type check 2024-08-23 14:33:39 +02:00
Ching Pei Yang
146fcf25e6 lib: add lznKeySpec example 2024-08-23 14:33:39 +02:00
Ching Pei Yang
5eadc2937d lz.n: process key maps 2024-08-23 14:33:39 +02:00
Ching Pei Yang
f683cd36e0 remove unused 2024-08-23 14:33:39 +02:00
Pei Yang Ching
bd6c228e5c lib: fix lz.n map type 2024-08-23 14:33:39 +02:00
Ching Pei Yang
d660aae9be lib: add lz.n KeySpec 2024-08-23 14:33:39 +02:00
Pei Yang Ching
4014ab0a01 nvim-tree: use lazy 2024-08-23 14:33:39 +02:00
Pei Yang Ching
659c4b5ca2 lazy: add setupOpts support 2024-08-23 14:33:39 +02:00
Pei Yang Ching
23c6f319cd fix: broken optPlugins 2024-08-23 14:33:39 +02:00
Pei Yang Ching
57828912bb switch to other hacky array-table syntax 2024-08-23 14:33:39 +02:00
Pei Yang Ching
56a3d45ac7 wrap lazy init code in function 2024-08-23 14:33:39 +02:00
Ching Pei Yang
5745fd8103 flake: update lz.n 2024-08-23 14:33:39 +02:00
Ching Pei Yang
5a045d2ea0 lib: add lznPluginTableType 2024-08-23 14:33:39 +02:00
Ching Pei Yang
7648cb8c7e lib: export lznPluginType 2024-08-23 14:33:39 +02:00
Ching Pei Yang
6e3292f2c4 lz.n: load lz.n 2024-08-23 14:33:39 +02:00
Ching Pei Yang
7abd0f8626 lz.n: add basic lazy.plugins option 2024-08-23 14:33:39 +02:00
Pei Yang Ching
3800a1c016 lib: add basic lz.n plugin spec type 2024-08-23 14:33:39 +02:00
Pei Yang Ching
6cd3363942 add lazy module skeleton 2024-08-23 14:33:39 +02:00
Pei Yang Ching
6d7d5ee190 flake: add lz.n plugin 2024-08-23 14:33:39 +02:00
Pei Yang Ching
b6c1a7145e maps: fix missing description 2024-08-23 14:33:39 +02:00
Ching Pei Yang
b2eae85e79 remove unused 2024-08-23 14:33:39 +02:00
Pei Yang Ching
feccaf477a cleanup unused import 2024-08-23 14:33:32 +02:00
Pei Yang Ching
aa040ab538 remove unneeded pipe 2024-08-23 14:33:16 +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 44 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

@ -6,7 +6,7 @@
inherit (builtins) map mapAttrs filter;
inherit (lib.attrsets) mapAttrsToList filterAttrs;
inherit (lib.strings) concatLines concatMapStringsSep optionalString;
inherit (lib.trivial) showWarnings pipe;
inherit (lib.trivial) showWarnings;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
@ -40,17 +40,9 @@ 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)
cfg.keymaps
[
(mapAttrsToList (key: binds:
concatLines (map (toLuaKeymap key) binds)))
concatLines
];
maps = concatLines (map toLuaKeymap cfg.keymaps);
keymaps = maps;
in {