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

View file

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

View file

@ -1,4 +1,4 @@
{ lib }: { lib, nix2lua }:
let let
modeEnum = lib.types.enum [ "" "n" "!" "i" "c" "v" "x" "s" "o" "t" "l" ]; modeEnum = lib.types.enum [ "" "n" "!" "i" "c" "v" "x" "s" "o" "t" "l" ];
@ -126,6 +126,21 @@ let
Human-readable description. 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 in

View file

@ -46,8 +46,7 @@ in
buf = lib.optionalString (vars.buffer != null) vars.buffer; 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 if config.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then vars.genConfig
call "vim.keymap.set" [ mode lhs rhs (removeAttrs vars [ "mode" "lhs" "rhs" ]) ]
else abort "This case should never happen." else abort "This case should never happen."
)) ))
])); ]));