nixeovim/lib/mod.nix

82 lines
1.7 KiB
Nix

{ lib }:
let
inherit (builtins) listToAttrs;
inherit (lib) nameValuePair removePrefix removeSuffix;
wrap = val: "<${val}>";
unwrap = val: removePrefix "<" (removeSuffix ">" val);
char = num: wrap "Char-${num}"; # map a character by its decimal, octal or hexadecimal number
shift = key: wrap "S-${unwrap key}"; # shift-key *shift* *<S-*
ctrl = key: wrap "C-${unwrap key}"; # control-key *control* *ctrl* *<C-*
meta = key: wrap "M-${unwrap key}"; # alt-key or meta-key *META* *ALT* *<M-*
super = key: wrap "D-${unwrap key}"; # command-key or "super" key *<D-*
keys = listToAttrs (map (v: nameValuePair v (wrap v)) (
[
"Leader"
"LocalLeader"
"Cmd"
"Plug"
"MouseMove"
"Nul"
"Bs"
"Tab"
"Nl"
"Cr"
"Esc"
"Space"
"Lt"
"Bslash"
"Bar"
"Del"
"Csi"
"Eol"
"Ignore"
"Nop"
"Up"
"Down"
"Left"
"Right"
"Help"
"Undo"
"Insert"
"Home"
"End"
"PageUp"
"PageDown"
"kUp"
"kDown"
"kLeft"
"kRight"
"kHome"
"kEnd"
"kOrigin"
"kPageUp"
"kPageDown"
"kDel"
"kPlus"
"kMinus"
"kMultiply"
"kDivide"
"kPoint"
"kComma"
"kEqual"
"kEnter"
]
++ map (n: "F${toString n}") (lib.range 1 12)
++ map (n: "k${toString n}") (lib.range 0 9)
)
);
in
{ inherit char shift ctrl meta super; } // keys // {
return = keys.cr;
enter = keys.cr;
backslash = keys.bslash;
cmd = expr: keys.Cmd + expr + keys.Cr;
leader = expr: keys.Leader + expr;
localLeader = expr: keys.LocalLeader + expr;
}