From 06f7ca082ac3580e2c9242fccb4f80b3a74d4c6a Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Mon, 4 Mar 2024 14:37:11 -0500 Subject: [PATCH] WIP --- modules/programs/kakoune.nix | 85 ++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/modules/programs/kakoune.nix b/modules/programs/kakoune.nix index da0af0c0..c07bed54 100644 --- a/modules/programs/kakoune.nix +++ b/modules/programs/kakoune.nix @@ -93,34 +93,8 @@ let }; }; - keyMapping = types.submodule { + keysModule = types.submodule { 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 = ""; - description = '' - The key to be mapped. See - - for possible values. - ''; - }; - effect = mkOption { type = types.str; example = ":wq"; @@ -128,6 +102,13 @@ let 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; description = '' How many lines and columns to keep visible around the cursor. @@ -469,8 +452,18 @@ let }; keyMappings = mkOption { - type = types.listOf keyMapping; - default = [ ]; + type = types.attrsOf (types.attrsOf (types.oneOf types.string keysModule)); + default = {}; + example = { + normal = { + "=" = { + effect = ":echo Got count %val{count} and reg %val{register}"; + docstring = "TODO"; + }; + }; + + user."" = ":wq"; + }; description = '' User-defined key mappings. For documentation, see . @@ -559,15 +552,33 @@ let ]) "try %{declare-user-mode ${mode}}"; userModeStrings = map userModeString - (lists.unique (map (km: km.mode) cfg.config.keyMappings)); + (attrNames cfg.config.keyMappings); keyMappingString = km: - concatStringsSep " " [ - "map global" - "${km.mode} ${km.key} '${km.effect}'" - "${optionalString (km.docstring != null) - "-docstring '${km.docstring}'"}" - ]; + let + concatMap = f: lib.foldlAttrs + (acc: name: value: acc ++ f name value) + []; + 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: concatStringsSep " " [ @@ -611,7 +622,7 @@ let ++ optional (ui != null) "set-option global ui_options ${uiOptions}" ++ [ "# User modes" ] ++ userModeStrings ++ [ "# Key mappings" ] - ++ map keyMappingString keyMappings + ++ keyMappingString keyMappings ++ [ "# Hooks" ] ++ map hookString hooks); in pkgs.writeText "kakrc"