mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-23 17:28:39 +02:00
helpers: add rawKeysAttrs
This commit is contained in:
parent
03c5f5eb74
commit
0ba2ea5416
2 changed files with 56 additions and 0 deletions
|
@ -40,3 +40,18 @@ A certain number of helpers are defined that can be useful:
|
||||||
|
|
||||||
- `helpers.enableExceptInTests`: Evaluates to `true`, except in `mkTestDerivationFromNixvimModule`
|
- `helpers.enableExceptInTests`: Evaluates to `true`, except in `mkTestDerivationFromNixvimModule`
|
||||||
where it evaluates to `false`. This allows to skip instantiating plugins that can't be run in tests.
|
where it evaluates to `false`. This allows to skip instantiating plugins that can't be run in tests.
|
||||||
|
|
||||||
|
- `helpers.toRawKeys attrs`: Convert the keys of the given `attrs` to raw lua.
|
||||||
|
```nix
|
||||||
|
toRawKeys {foo = 1; bar = "hi";}
|
||||||
|
```
|
||||||
|
will translate in lua to:
|
||||||
|
```lua
|
||||||
|
{[foo] = 1, [bar] = 2,}
|
||||||
|
```
|
||||||
|
Otherwise, the keys of a regular `attrs` will be interpreted as lua string:
|
||||||
|
```lua
|
||||||
|
{['foo'] = 1, ['bar'] = 2,}
|
||||||
|
-- which is the same as
|
||||||
|
{foo = 1, bar = 2,}
|
||||||
|
```
|
||||||
|
|
|
@ -11,6 +11,47 @@ with lib;
|
||||||
"__empty" = null;
|
"__empty" = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Turn all the keys of an attrs into raw lua.
|
||||||
|
|
||||||
|
# Example
|
||||||
|
|
||||||
|
```nix
|
||||||
|
toRawKeys { foo = 1; bar = 2; }
|
||||||
|
=> { __rawKey__foo = 1; __rawKey__bar = 2; }
|
||||||
|
```
|
||||||
|
|
||||||
|
# Type
|
||||||
|
|
||||||
|
```
|
||||||
|
toRawKeys :: AttrSet -> AttrSet
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
toRawKeys = mapAttrs' (n: v: nameValuePair "__rawKey__${n}" v);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a 1-element attrs with a raw lua key.
|
||||||
|
|
||||||
|
# Example
|
||||||
|
|
||||||
|
```nix
|
||||||
|
mkRawKey "foo" 1
|
||||||
|
=> { __rawKey__foo = 1; }
|
||||||
|
```
|
||||||
|
|
||||||
|
# Type
|
||||||
|
|
||||||
|
```
|
||||||
|
mkRawKey :: String -> String -> AttrSet
|
||||||
|
```
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
|
||||||
|
- [n] The attribute name (raw lua)
|
||||||
|
- [v] The attribute value
|
||||||
|
*/
|
||||||
|
mkRawKey = n: v: toRawKeys { "${n}" = v; };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert a string from camelCase to snake_case
|
Convert a string from camelCase to snake_case
|
||||||
Type: string -> string
|
Type: string -> string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue