2024-02-26 04:28:07 +00:00
|
|
|
{lib}: let
|
|
|
|
inherit (lib.options) mkOption;
|
2024-03-12 00:48:53 +00:00
|
|
|
inherit (lib.modules) mkIf mkDefault;
|
2024-02-26 04:28:07 +00:00
|
|
|
inherit (lib.types) nullOr str;
|
|
|
|
inherit (lib.attrsets) isAttrs mapAttrs;
|
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
mkLuaBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
2024-08-12 00:07:45 +00:00
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
mkExprBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
|
|
|
expr = true;
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
2024-08-12 00:07:45 +00:00
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
mkBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
silent = true;
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
2024-08-12 00:07:45 +00:00
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
mkMappingOption = description: default:
|
|
|
|
mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
inherit default description;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
# Utility function that takes two attrsets:
|
|
|
|
# { someKey = "some_value" } and
|
|
|
|
# { someKey = { description = "Some Description"; }; }
|
|
|
|
# and merges them into
|
|
|
|
# { someKey = { value = "some_value"; description = "Some Description"; }; }
|
|
|
|
addDescriptionsToMappings = actualMappings: mappingDefinitions:
|
|
|
|
mapAttrs (name: value: let
|
|
|
|
isNested = isAttrs value;
|
|
|
|
returnedValue =
|
|
|
|
if isNested
|
|
|
|
then addDescriptionsToMappings actualMappings.${name} mappingDefinitions.${name}
|
|
|
|
else {
|
|
|
|
inherit value;
|
|
|
|
inherit (mappingDefinitions.${name}) description;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
returnedValue)
|
|
|
|
actualMappings;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
mkSetBinding = mode: binding: action:
|
|
|
|
mkBinding mode binding.value action binding.description;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
mkSetExprBinding = mode: binding: action:
|
|
|
|
mkExprBinding mode binding.value action binding.description;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
mkSetLuaBinding = mode: binding: action:
|
|
|
|
mkLuaBinding mode binding.value action binding.description;
|
2024-03-12 00:48:53 +00:00
|
|
|
|
2024-08-03 16:41:41 +00:00
|
|
|
# Utility function that takes two attrsets:
|
|
|
|
# { someKey = "some_value" } and
|
|
|
|
# { someKey = { description = "Some Description"; }; }
|
|
|
|
# and merges them into
|
|
|
|
# { someKey = { value = "some_value"; description = "Some Description"; }; }
|
|
|
|
addDescriptionsToMappings = actualMappings: mappingDefinitions:
|
|
|
|
mapAttrs (name: value: let
|
|
|
|
isNested = isAttrs value;
|
|
|
|
returnedValue =
|
|
|
|
if isNested
|
|
|
|
then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}"
|
|
|
|
else {
|
|
|
|
inherit value;
|
|
|
|
inherit (mappingDefinitions."${name}") description;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
returnedValue)
|
|
|
|
actualMappings;
|
|
|
|
|
|
|
|
mkSetBinding = binding: action:
|
|
|
|
mkBinding binding.value action binding.description;
|
|
|
|
|
|
|
|
mkSetExprBinding = binding: action:
|
|
|
|
mkExprBinding binding.value action binding.description;
|
|
|
|
|
|
|
|
mkSetLuaBinding = binding: action:
|
|
|
|
mkLuaBinding binding.value action binding.description;
|
|
|
|
|
|
|
|
pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
|
|
|
|
|
|
|
|
mkLznBinding = mode: lhs: rhs: desc: {
|
|
|
|
inherit mode lhs rhs desc;
|
|
|
|
};
|
2024-08-03 17:18:25 +00:00
|
|
|
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# ```
|
|
|
|
# vim.lazy.plugins = {
|
|
|
|
# telescope = {
|
|
|
|
# # ...
|
|
|
|
# keys = builtins.filter ({lhs, ...}: lhs != null) [
|
|
|
|
# mkSetLznBinding mapping ":Telescope<CR>"
|
|
|
|
# ];
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# ```
|
|
|
|
mkSetLznBinding = binding: action: {
|
|
|
|
lhs = binding.value;
|
|
|
|
rhs = action;
|
|
|
|
desc = binding.description;
|
|
|
|
};
|
2024-08-03 16:41:41 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
binds
|