mirror of
https://github.com/nix-community/nixvim.git
synced 2025-12-07 01:21:05 +01:00
modules/output: refactor config generation
The motivation for this change was to avoid generating empty
config sections like
vim.cmd([[
]])
To make a config generation cleaner several helper functions introduced:
* `hasContent` have been moved to helpers
* `concatNonEmptyLines` joins strings (which has content) separated with
newlines
* `wrapVimscriptForLua` wraps a lua string for using in Vimscript, but
only if the string has content, otherwise empty string is returned
* `wrapLuaForVimscript` wraps Vimscript for using in lua, but only if
the string has content, otherwise empty string is returned
Added tests:
* testing that all possible config sections are present in the final
generated config
* testing that the config files generated by empty `files` definitions
don't have any content in it
This commit is contained in:
parent
6dc0bda459
commit
299d0406bb
4 changed files with 149 additions and 37 deletions
|
|
@ -4,7 +4,14 @@
|
|||
_nixvimTests,
|
||||
}:
|
||||
with lib;
|
||||
{
|
||||
rec {
|
||||
# Whether a string contains something other than whitespaces
|
||||
hasContent = str: builtins.match "[[:space:]]*" str == null;
|
||||
|
||||
# Concatenate a list of strings, adding a newline at the end of each one,
|
||||
# but skipping strings containing only whitespace characters
|
||||
concatNonEmptyLines = lines: concatLines (builtins.filter hasContent lines);
|
||||
|
||||
listToUnkeyedAttrs =
|
||||
list:
|
||||
builtins.listToAttrs (lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list);
|
||||
|
|
@ -118,4 +125,26 @@ with lib;
|
|||
${string}
|
||||
end
|
||||
'';
|
||||
|
||||
# Wrap Vimscript for using in lua,
|
||||
# but only if the string contains something other than whitespaces
|
||||
# TODO: account for a possible ']]' in the string
|
||||
wrapVimscriptForLua =
|
||||
string:
|
||||
optionalString (hasContent string) ''
|
||||
vim.cmd([[
|
||||
${string}
|
||||
]])
|
||||
'';
|
||||
|
||||
# Wrap lua script for using in Vimscript,
|
||||
# but only if the string contains something other than whitespaces
|
||||
# TODO: account for a possible 'EOF' if the string
|
||||
wrapLuaForVimscript =
|
||||
string:
|
||||
optionalString (hasContent string) ''
|
||||
lua << EOF
|
||||
${string}
|
||||
EOF
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue