From 1b1743dc5a0c76675764705fdb505c28de8fa67b Mon Sep 17 00:00:00 2001 From: n3oney Date: Sat, 22 Apr 2023 15:48:10 +0200 Subject: [PATCH] feat: create utility functions to make adding bindings even easier --- lib/stdlib-extended.nix | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/stdlib-extended.nix b/lib/stdlib-extended.nix index 92945a5..0455983 100644 --- a/lib/stdlib-extended.nix +++ b/lib/stdlib-extended.nix @@ -4,7 +4,7 @@ nixpkgsLib: let mkNvimLib = import ./.; in - nixpkgsLib.extend (self: super: { + nixpkgsLib.extend (self: super: rec { nvim = mkNvimLib {lib = self;}; mkLuaBinding = key: action: desc: @@ -40,6 +40,24 @@ in 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. literalExpression = super.literalExpression or super.literalExample; literalDocBook = super.literalDocBook or super.literalExample;