Compare commits

...

3 commits

Author SHA1 Message Date
Ching Pei Yang
c7df5c97f3 lz.n: generate less code 2024-08-03 19:48:13 +02:00
Ching Pei Yang
e086dc02fe lz.n: wrap lua code in function 2024-08-03 19:46:52 +02:00
Ching Pei Yang
fc58c85524 lib: add mkLznBinding 2024-08-03 19:18:25 +02:00
2 changed files with 42 additions and 9 deletions

View file

@ -71,6 +71,24 @@
mkLznBinding = mode: lhs: rhs: desc: { mkLznBinding = mode: lhs: rhs: desc: {
inherit mode lhs rhs desc; inherit mode lhs rhs desc;
}; };
# 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;
};
}; };
in in
binds binds

View file

@ -31,15 +31,30 @@
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"]) (removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
// { // {
"@1" = name; "@1" = name;
after = mkLuaInline '' before =
function() if spec.before != null
${ then
optionalString (spec.setupModule != null) mkLuaInline ''
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})" function()
} ${spec.before}
${optionalString (spec.after != null) spec.after} end
end ''
''; else null;
after =
if spec.setupModule == null && spec.after == null
then null
else
mkLuaInline ''
function()
${
optionalString (spec.setupModule != null)
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"
}
${optionalString (spec.after != null) spec.after}
end
'';
keys = keys =
if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set" if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set"
then map toLuzLznKeySpec spec.keys then map toLuzLznKeySpec spec.keys