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 # Keymaps
(lib.flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars: (lib.flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
let let
buf = lib.optionalString (vars.buffer != null) vars.buffer;
m = if builtins.isList mode then lib.head mode else mode; m = if builtins.isList mode then lib.head mode else mode;
in 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." else abort "This case should never happen."
)) ))
])); ]));

View File

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

View File

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