This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
neovim/lib.nix

45 lines
1003 B
Nix

rec {
#############################################################################
# Helpers
# Source: https://github.com/NixOS/nixpkgs/blob/d61bc96d16ca288c69b798b8e31eca64050098e3/lib/lists.nix
foldr = op: nul: list:
let
len = builtins.length list;
fold' = n:
if n == len
then nul
else op (builtins.elemAt list n) (fold' (n + 1));
in
fold' 0;
concatMap = op: list:
let
concat = (a: b: op a + b);
in
foldr concat "" list;
############################################################################
# Configs
optional = cond: val:
let
def =
if builtins.isList val then [ ]
else if builtins.isString val then ""
else null;
in
if cond then val else def;
#############################################################################
# Lua
mkLuaHeredoc = content: ''
lua << EOF
${content}
EOF
'';
mkLuaRc = contents: concatMap mkLuaHeredoc contents;
}