mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
lib: cleanup with lib
This commit is contained in:
parent
c76e5070b9
commit
35788bbc5a
9 changed files with 179 additions and 160 deletions
|
@ -3,14 +3,13 @@
|
|||
helpers,
|
||||
_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);
|
||||
concatNonEmptyLines = lines: lib.concatLines (builtins.filter hasContent lines);
|
||||
|
||||
listToUnkeyedAttrs =
|
||||
list:
|
||||
|
@ -38,7 +37,7 @@ rec {
|
|||
toRawKeys :: AttrSet -> AttrSet
|
||||
```
|
||||
*/
|
||||
toRawKeys = mapAttrs' (n: v: nameValuePair "__rawKey__${n}" v);
|
||||
toRawKeys = lib.mapAttrs' (n: v: lib.nameValuePair "__rawKey__${n}" v);
|
||||
|
||||
/**
|
||||
Create a 1-element attrs with a raw lua key.
|
||||
|
@ -70,13 +69,13 @@ rec {
|
|||
toSnakeCase =
|
||||
let
|
||||
splitByWords = builtins.split "([A-Z])";
|
||||
processWord = s: if isString s then s else "_" + toLower (elemAt s 0);
|
||||
processWord = s: if lib.isString s then s else "_" + lib.toLower (lib.elemAt s 0);
|
||||
in
|
||||
string:
|
||||
let
|
||||
words = splitByWords string;
|
||||
in
|
||||
concatStrings (map processWord words);
|
||||
lib.concatStrings (map processWord words);
|
||||
|
||||
/**
|
||||
Capitalize a string by making the first character uppercase.
|
||||
|
@ -97,13 +96,13 @@ rec {
|
|||
upperFirstChar =
|
||||
s:
|
||||
let
|
||||
first = substring 0 1 s;
|
||||
rest = substring 1 (stringLength s) s;
|
||||
result = (toUpper first) + rest;
|
||||
first = lib.substring 0 1 s;
|
||||
rest = lib.substring 1 (lib.stringLength s) s;
|
||||
result = (lib.toUpper first) + rest;
|
||||
in
|
||||
optionalString (s != "") result;
|
||||
lib.optionalString (s != "") result;
|
||||
|
||||
mkIfNonNull' = x: y: (mkIf (x != null) y);
|
||||
mkIfNonNull' = x: y: (lib.mkIf (x != null) y);
|
||||
|
||||
mkIfNonNull = x: (mkIfNonNull' x x);
|
||||
|
||||
|
@ -113,12 +112,12 @@ rec {
|
|||
r:
|
||||
if r == null || r == "" then
|
||||
null
|
||||
else if isString r then
|
||||
else if lib.isString r then
|
||||
{ __raw = r; }
|
||||
else if types.isRawType r then
|
||||
else if lib.types.isRawType r then
|
||||
r
|
||||
else
|
||||
throw "mkRaw: invalid input: ${generators.toPretty { multiline = false; } r}";
|
||||
throw "mkRaw: invalid input: ${lib.generators.toPretty { multiline = false; } r}";
|
||||
|
||||
wrapDo = string: ''
|
||||
do
|
||||
|
@ -131,7 +130,7 @@ rec {
|
|||
# TODO: account for a possible ']]' in the string
|
||||
wrapVimscriptForLua =
|
||||
string:
|
||||
optionalString (hasContent string) ''
|
||||
lib.optionalString (hasContent string) ''
|
||||
vim.cmd([[
|
||||
${string}
|
||||
]])
|
||||
|
@ -142,7 +141,7 @@ rec {
|
|||
# TODO: account for a possible 'EOF' if the string
|
||||
wrapLuaForVimscript =
|
||||
string:
|
||||
optionalString (hasContent string) ''
|
||||
lib.optionalString (hasContent string) ''
|
||||
lua << EOF
|
||||
${string}
|
||||
EOF
|
||||
|
@ -151,16 +150,16 @@ rec {
|
|||
# Split a list into a several sub-list, each with a max-size of `size`
|
||||
groupListBySize =
|
||||
size: list:
|
||||
reverseList (
|
||||
foldl' (
|
||||
lib.reverseList (
|
||||
lib.foldl' (
|
||||
lists: item:
|
||||
let
|
||||
first = head lists;
|
||||
rest = drop 1 lists;
|
||||
first = lib.head lists;
|
||||
rest = lib.drop 1 lists;
|
||||
in
|
||||
if lists == [ ] then
|
||||
[ [ item ] ]
|
||||
else if length first < size then
|
||||
else if lib.length first < size then
|
||||
[ (first ++ [ item ]) ] ++ rest
|
||||
else
|
||||
[ [ item ] ] ++ lists
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue