refactor(nvim): condense functions

This commit is contained in:
Moritz Böhme 2023-08-11 19:00:11 +02:00
parent 0c591c0435
commit 1566dc84f4
Signed by: moritz
GPG key ID: 970C6E89EB0547A9

View file

@ -24,38 +24,28 @@ let
then func
else abort "Either cmd or function must be set"
);
descString = optionalString (desc != null) "desc = ${quote desc},";
in
''{ ${quote key}, ${cmdString}, mode = ${quote mode}, ${optionalString (desc != null) "desc = ${quote desc},"} }'';
''{ ${quote key}, ${cmdString}, mode = ${quote mode}, ${descString} }'';
lazySpecFromPlugin =
{ plugin
, dependencies
, init
, conf
, lazy
, event
, enabled
, cmd
, ft
, priority
, keys
}:
listToStringMultiLine id
{ plugin, dependencies, init, conf, lazy, event, enabled, cmd, ft, priority, keys }:
listToStringMultiLine'
([
"dir = ${quote plugin}"
"name = ${quote (getName plugin)}"
]
++ (optional (lazy != null) "lazy = ${boolToString lazy}")
++ (optional (!enabled) "enabled = ${boolToString enabled}")
++ (optional (dependencies != [ ]) "dependencies = ${listToStringMultiLine id (map lazySpecFromPlugin dependencies)}")
++ (optional (dependencies != [ ]) "dependencies = ${listToStringMultiLine' (map lazySpecFromPlugin dependencies)}")
++ (optional (init != null) "init = function(plugin)\n${toString init}\nend")
++ (optional (conf != null) "config = function(plugin, opts)\n${toString conf}\nend")
++ (optional (keys != [ ]) "keys = ${listToStringMultiLine id (map keybinding keys)}")
++ (optional (keys != [ ]) "keys = ${listToStringMultiLine' (map keybinding keys)}")
++ (optional (event != [ ]) "event = ${listToStringOneLine quote event}")
++ (optional (cmd != [ ]) "cmd = ${listToStringOneLine quote cmd}")
++ (optional (ft != [ ]) "ft = ${listToStringOneLine quote ft}")
++ (optional (priority != null) "priority = ${toString priority}")
);
lazySpecs = listToStringMultiLine id (map lazySpecFromPlugin cfg.plugins);
lazySpecs = listToStringMultiLine' (map lazySpecFromPlugin cfg.plugins);
lazy = /* lua */ ''
require("lazy").setup(${lazySpecs})
'';