modules/keymap: don't validate by buffer

This commit is contained in:
Dmitriy Pleshevskiy 2024-05-01 14:56:36 +03:00
parent 688e8e2ece
commit bc38ab74de
Signed by: pleshevskiy
GPG Key ID: 17041163DA10A9A2
3 changed files with 5 additions and 10 deletions

View File

@ -43,10 +43,9 @@ in
# Keymaps
(lib.flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
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 vars.genConfig
if config.vim.keymap._validate."${m}"."${lhs}" == rhs then vars.genConfig
else abort "This case should never happen."
))
]));

View File

@ -1,7 +1,6 @@
{ lib, ... }:
let
fnOpts = { name, config, ... }: {
options = with lib; {
args = mkOption {
@ -43,10 +42,9 @@ let
(lib.flip map innerCfg.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
let
buf = lib.optionalString (vars.buffer != null) vars.buffer.raw;
m = if builtins.isList mode then lib.head mode else mode;
in
if innerCfg.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then vars.genConfig
if innerCfg.vim.keymap._validate."${m}"."${lhs}" == rhs then vars.genConfig
else abort "This case should never happen."
))
]);

View File

@ -4,8 +4,8 @@ let cfg = config.vim.keymap; in
{
options.vim.keymap = with lib; {
_validate = mkOption {
# buffer mode lhs rhs
type = with types; attrsOf (attrsOf (attrsOf (either str attrs)));
# mode lhs rhs
type = with types; attrsOf (attrsOf (either str attrs));
visible = false;
internal = true;
readOnly = true;
@ -29,12 +29,10 @@ let cfg = config.vim.keymap; in
else if m == "l" then [ m "i" "c" "l" ]
else m
)));
buf = lib.optionalString (buffer != null) buffer.raw;
in
lib.foldl lib.recursiveUpdate { }
(lib.flip map unwrappedModes (m: {
"${buf}"."${m}"."${lhs}" = rhs;
"${m}"."${lhs}" = rhs;
}))
)
cfg.set);