build/neovim: add keymap validation to build process

This commit is contained in:
Dmitriy Pleshevskiy 2024-04-29 15:47:56 +03:00
parent e98bb24f6d
commit 4c73e0220e
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
2 changed files with 11 additions and 5 deletions

View file

@ -42,7 +42,13 @@ in
(lib.optional (config.vim.cmd != "") (call "vim.cmd" config.vim.cmd))
# Keymaps
(lib.flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
call "vim.keymap.set" [ mode lhs rhs (removeAttrs vars [ "mode" "lhs" "rhs" ]) ]
let
buf = lib.optionalString (vars.buffer != null) vars.buffer;
m = if builtins.isList mode then lib.head mode else mode;
in
if config.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then
call "vim.keymap.set" [ mode lhs rhs (removeAttrs vars [ "mode" "lhs" "rhs" ]) ]
else abort "This case should never happen."
))
]));

View file

@ -23,10 +23,10 @@ let cfg = config.vim.keymap; in
let
sourceModes = if builtins.isList mode then mode else [ mode ];
unwrappedModes = lib.flatten (lib.flip map sourceModes (m:
if m == "" then [ "n" "x" "s" "o" ]
else if m == "!" then [ "i" "c" ]
else if m == "v" then [ "x" "s" ]
else if m == "l" then [ "i" "c" "l" ]
if m == "" then [ m "n" "x" "s" "o" ]
else if m == "!" then [ m "i" "c" ]
else if m == "v" then [ m "x" "s" ]
else if m == "l" then [ m "i" "c" "l" ]
else m
));