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 22:27:05 +00:00
|
|
|
binds = rec {
|
|
|
|
mkLuaBinding = key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
"${key}" = {
|
|
|
|
inherit action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkExprBinding = key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
"${key}" = {
|
|
|
|
inherit action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
|
|
|
expr = true;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkBinding = key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
"${key}" = {
|
|
|
|
inherit action desc;
|
|
|
|
silent = true;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkMappingOption = description: default:
|
|
|
|
mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
inherit default description;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 22:27:05 +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 22:27:05 +00:00
|
|
|
mkSetBinding = binding: action:
|
|
|
|
mkBinding binding.value action binding.description;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkSetExprBinding = binding: action:
|
|
|
|
mkExprBinding binding.value action binding.description;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkSetLuaBinding = binding: action:
|
|
|
|
mkLuaBinding binding.value action binding.description;
|
2024-03-12 00:48:53 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
|
2024-08-03 16:41:41 +00:00
|
|
|
|
|
|
|
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-12 22:27:05 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
binds
|