2024-04-30 16:54:48 +03:00
|
|
|
{ lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
fnOpts = { name, config, ... }: {
|
|
|
|
options = with lib; {
|
|
|
|
args = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
content = mkOption {
|
|
|
|
type = types.functionTo (lib.types.submoduleWith {
|
|
|
|
modules = [
|
2024-05-01 02:01:47 +03:00
|
|
|
{
|
|
|
|
options.extra = with lib; mkOption {
|
|
|
|
type = with types; nullOr attrs;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
}
|
2024-04-30 16:54:48 +03:00
|
|
|
./vim/keymap.nix
|
|
|
|
# ./vim/opts.nix
|
|
|
|
];
|
|
|
|
specialArgs = { inherit lib; };
|
|
|
|
});
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
lambda = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
readOnly = true;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
lambda = with lib.nix2lua;
|
|
|
|
let
|
|
|
|
fnArgs = builtins.listToAttrs (map (v: { name = v; value = raw v; }) config.args);
|
2024-05-01 02:01:47 +03:00
|
|
|
innerCfg = config.content fnArgs;
|
2024-04-30 16:54:48 +03:00
|
|
|
in
|
|
|
|
lambda config.args (lib.flatten [
|
2024-05-01 02:01:47 +03:00
|
|
|
innerCfg.extra
|
2024-04-30 16:54:48 +03:00
|
|
|
|
|
|
|
(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
|
|
|
|
else abort "This case should never happen."
|
|
|
|
))
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.fn = with lib; mkOption {
|
|
|
|
type = with types; attrsOf (submodule fnOpts);
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
}
|