feat: create utility functions to make adding bindings even easier

This commit is contained in:
n3oney 2023-04-22 15:48:10 +02:00
parent 586a7f5b41
commit 1b1743dc5a
No known key found for this signature in database
GPG key ID: C786693DE727850E

View file

@ -4,7 +4,7 @@
nixpkgsLib: let nixpkgsLib: let
mkNvimLib = import ./.; mkNvimLib = import ./.;
in in
nixpkgsLib.extend (self: super: { nixpkgsLib.extend (self: super: rec {
nvim = mkNvimLib {lib = self;}; nvim = mkNvimLib {lib = self;};
mkLuaBinding = key: action: desc: mkLuaBinding = key: action: desc:
@ -40,6 +40,24 @@ in
inherit default description; inherit default description;
}; };
# 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:
self.attrsets.mapAttrs (name: value: {
value = value;
description = mappingDefinitions."${name}".description;
})
actualMappings;
mkSetBinding = binding: action:
mkBinding binding.value action binding.description;
mkSetLuaBinding = binding: action:
mkLuaBinding binding.value action binding.description;
# For forward compatibility. # For forward compatibility.
literalExpression = super.literalExpression or super.literalExample; literalExpression = super.literalExpression or super.literalExample;
literalDocBook = super.literalDocBook or super.literalExample; literalDocBook = super.literalDocBook or super.literalExample;