lib/types: gen lua config in the keymap submodule

This commit is contained in:
Dmitriy Pleshevskiy 2024-04-30 00:46:43 +03:00
parent 5e12b830c8
commit d82800af41
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
4 changed files with 28 additions and 11 deletions

View file

@ -3,20 +3,23 @@
, nix2lua ? import <nix2lua>
}:
let nix2lua' = nix2lua; in
let
inherit (pkgs.lib) evalModules filter concatMapStringsSep showWarnings;
extendedLib = import ./lib { inherit (pkgs) lib; };
nix2lua = nix2lua'.lib;
lib = import ./lib {
inherit (pkgs) lib;
inherit nix2lua;
};
allModules = import ./module-list.nix { inherit pkgs; };
rawModule = evalModules {
modules = [ config ] ++ allModules;
specialArgs = {
inherit pkgs;
lib = extendedLib;
nix2lua = nix2lua.lib;
};
specialArgs = { inherit pkgs lib nix2lua; };
};
failedAssertions = map (x: x.message) (filter (x: !x.assertion) rawModule.config.assertions);

View file

@ -1,7 +1,7 @@
{ lib }:
{ lib, nix2lua }:
let
types = import ./types.nix { inherit lib; };
types = import ./types.nix { inherit lib nix2lua; };
in
lib // {
types = lib.types // types;

View file

@ -1,4 +1,4 @@
{ lib }:
{ lib, nix2lua }:
let
modeEnum = lib.types.enum [ "" "n" "!" "i" "c" "v" "x" "s" "o" "t" "l" ];
@ -126,6 +126,21 @@ let
Human-readable description.
'';
};
genConfig = mkOption {
type = types.attrs;
readOnly = true;
internal = true;
};
};
config = {
genConfig = with nix2lua; call "vim.keymap.set" [
config.mode
config.lhs
config.rhs
{ inherit (config) buffer nowait silent script expr unique remap desc; }
];
};
});
in

View file

@ -46,8 +46,7 @@ in
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" ]) ]
if config.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then vars.genConfig
else abort "This case should never happen."
))
]));