nixeovim/lib/types.nix

149 lines
4.8 KiB
Nix

{ lib, nix2lua }:
let
modeEnum = lib.types.enum [ "" "n" "!" "i" "c" "v" "x" "s" "o" "t" "l" ];
mode = with lib.types; either modeEnum (uniq (listOf modeEnum));
# TODO: maybe add more options and add descriptions from
# :help vim.keymap.set
# :help nvim_set_keymap
keymap = lib.types.submodule ({ config, ... }: {
options = with lib; {
lhs = mkOption {
type = types.str;
description = ''
Left-hand side |{lhs}| of the mapping.
'';
};
rhs = mkOption {
type = with types; oneOf [ str attrs ];
description = ''
Right-hand side |{rhs}| of the mapping, can be a Lua function.
'';
};
mode = mkOption {
type = mode;
default = "";
description = ''
Mode | Norm | Ins | Cmd | Vis | Sel | Opr | Term | Lang |
Command +------+-----+-----+-----+-----+-----+------+------+
"" | yes | - | - | yes | yes | yes | - | - |
"n" | yes | - | - | - | - | - | - | - |
"!" | - | yes | yes | - | - | - | - | - |
"i" | - | yes | - | - | - | - | - | - |
"c" | - | - | yes | - | - | - | - | - |
"v" | - | - | - | yes | yes | - | - | - |
"x" | - | - | - | yes | - | - | - | - |
"s" | - | - | - | - | yes | - | - | - |
"o" | - | - | - | - | - | yes | - | - |
"t" | - | - | - | - | - | - | yes | - |
"l" | - | yes | yes | - | - | - | - | yes |
`:help map-overview`
'';
};
buffer = mkOption {
type = with types; nullOr attrs;
default = null;
description = ''
The mapping will be effective in the current buffer only.
`:help :map-buffer`
'';
};
nowait = mkOption {
type = types.bool;
default = false;
description = ''
When defining a buffer-local mapping for "," there may be a global mapping
that starts with ",". Then you need to type another character for Vim to know
whether to use the "," mapping or the longer one. To avoid this add the
<nowait> argument. Then the mapping will be used when it matches, Vim does
not wait for more characters to be typed.
`:help :map-nowait`
'';
};
silent = mkOption {
type = types.bool;
default = false;
description = ''
To define a mapping which will not be echoed on the command line.
`:help :map-silent`
'';
};
script = mkOption {
type = types.bool;
default = false;
description = ''
If the first argument to one of these commands is "<script>" and it is used to
define a new mapping or abbreviation, the mapping will only remap characters
in the {rhs} using mappings that were defined local to a script, starting with
"<SID>". This can be used to avoid that mappings from outside a script
interfere (e.g., when CTRL-V is remapped in mswin.vim), but do use other
mappings defined in the script.
`:help :map-script`
'';
};
expr = mkOption {
type = types.bool;
default = false;
description = ''
If the first argument to one of these commands is "<expr>" and it is used to
define a new mapping or abbreviation, the argument is an expression. The
expression is evaluated to obtain the {rhs} that is used.
`:help :map-expression`
'';
};
unique = mkOption {
type = types.bool;
default = false;
description = ''
It is used to define a new mapping or abbreviation, the command will fail if
the mapping or abbreviation already exists.
When defining a local mapping, there will also be a check if a global map
already exists which is equal.
`:help :map-unique`
'';
};
remap = mkOption {
type = types.bool;
default = false;
description = ''
Make the mapping recursive.
'';
};
desc = mkOption {
type = with types; nullOr str;
default = null;
description = ''
Human-readable description.
'';
};
genConfig = mkOption {
type = types.attrs;
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
{
inherit mode keymap;
}