This commit is contained in:
Rosario Pulella 2024-03-04 14:37:11 -05:00
parent d579633ff9
commit 06f7ca082a

View file

@ -93,34 +93,8 @@ let
}; };
}; };
keyMapping = types.submodule { keysModule = types.submodule {
options = { options = {
mode = mkOption {
type = types.str;
example = "user";
description = ''
The mode in which the mapping takes effect.
'';
};
docstring = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Optional documentation text to display in info boxes.
'';
};
key = mkOption {
type = types.str;
example = "<a-x>";
description = ''
The key to be mapped. See
<https://github.com/mawww/kakoune/blob/master/doc/pages/mapping.asciidoc#mappable-keys>
for possible values.
'';
};
effect = mkOption { effect = mkOption {
type = types.str; type = types.str;
example = ":wq<ret>"; example = ":wq<ret>";
@ -128,6 +102,13 @@ let
The sequence of keys to be mapped. The sequence of keys to be mapped.
''; '';
}; };
docstring = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Optional documentation text to display in info boxes.
'';
};
}; };
}; };
@ -226,6 +207,8 @@ let
}; };
}; };
}); });
docstring = lib.mkOption {
};
default = null; default = null;
description = '' description = ''
How many lines and columns to keep visible around the cursor. How many lines and columns to keep visible around the cursor.
@ -469,8 +452,18 @@ let
}; };
keyMappings = mkOption { keyMappings = mkOption {
type = types.listOf keyMapping; type = types.attrsOf (types.attrsOf (types.oneOf types.string keysModule));
default = [ ]; default = {};
example = {
normal = {
"=" = {
effect = ":echo Got count %val{count} and reg %val{register}<ret>";
docstring = "TODO";
};
};
user."<a-x>" = ":wq<ret>";
};
description = '' description = ''
User-defined key mappings. For documentation, see User-defined key mappings. For documentation, see
<https://github.com/mawww/kakoune/blob/master/doc/pages/mapping.asciidoc>. <https://github.com/mawww/kakoune/blob/master/doc/pages/mapping.asciidoc>.
@ -559,15 +552,33 @@ let
]) "try %{declare-user-mode ${mode}}"; ]) "try %{declare-user-mode ${mode}}";
userModeStrings = map userModeString userModeStrings = map userModeString
(lists.unique (map (km: km.mode) cfg.config.keyMappings)); (attrNames cfg.config.keyMappings);
keyMappingString = km: keyMappingString = km:
concatStringsSep " " [ let
"map global" concatMap = f: lib.foldlAttrs
"${km.mode} ${km.key} '${km.effect}'" (acc: name: value: acc ++ f name value)
"${optionalString (km.docstring != null) [];
"-docstring '${km.docstring}'"}" buildMapString = mode: key: value:
]; let
effect = if lib.isString value then "'${value}'"
else if lib.isAttrs value then
(assert (lib.isString value.effect); "'${value.effect}'")
else abort "WOPS";
docstring = optionalString
(lib.isAttrs value && lib.isString value.docstring)
"-docstring '${value.docstring}'";
in
concatStringSep " " [
"map global"
"${mode}"
"${key}"
effect
docstring
];
in
concatMap (mode: concatMap (key: value: [buildMapString mode key value]));
hookString = h: hookString = h:
concatStringsSep " " [ concatStringsSep " " [
@ -611,7 +622,7 @@ let
++ optional (ui != null) "set-option global ui_options ${uiOptions}" ++ optional (ui != null) "set-option global ui_options ${uiOptions}"
++ [ "# User modes" ] ++ userModeStrings ++ [ "# Key mappings" ] ++ [ "# User modes" ] ++ userModeStrings ++ [ "# Key mappings" ]
++ map keyMappingString keyMappings ++ keyMappingString keyMappings
++ [ "# Hooks" ] ++ map hookString hooks); ++ [ "# Hooks" ] ++ map hookString hooks);
in pkgs.writeText "kakrc" in pkgs.writeText "kakrc"