forked from nix-community/nixvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.nix
85 lines (79 loc) · 1.87 KB
/
opts.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
lib,
helpers,
config,
...
}:
with lib;
let
optionsAttrs = {
opts = {
prettyName = "options";
luaVariableName = "options";
luaApi = "opt";
description = "The configuration options, e.g. line numbers (`vim.opt.*`)";
};
globalOpts = {
prettyName = "global options";
luaVariableName = "global_options";
luaApi = "opt_global";
description = "The configuration global options (`vim.opt_global.*`)";
};
localOpts = {
prettyName = "local options";
luaVariableName = "local_options";
luaApi = "opt_local";
description = "The configuration local options (`vim.opt_local.*`)";
};
globals = {
prettyName = "globals";
luaVariableName = "globals";
luaApi = "g";
description = "Global variables (`vim.g.*`)";
};
};
in
{
options = mapAttrs (
_:
{ description, ... }:
mkOption {
type = with types; attrsOf anything;
default = { };
inherit description;
}
) optionsAttrs;
# Added 2024-03-29 (do not remove)
imports = mapAttrsToList (old: new: mkRenamedOptionModule [ old ] [ new ]) {
options = "opts";
globalOptions = "globalOpts";
localOptions = "localOpts";
};
config = {
extraConfigLuaPre = concatLines (
mapAttrsToList (
optionName:
{
prettyName,
luaVariableName,
luaApi,
...
}:
let
varName = "nixvim_${luaVariableName}";
optionDefinitions = config.${optionName};
in
optionalString (optionDefinitions != { }) ''
-- Set up ${prettyName} {{{
do
local ${varName} = ${helpers.toLuaObject optionDefinitions}
for k,v in pairs(${varName}) do
vim.${luaApi}[k] = v
end
end
-- }}}
''
) optionsAttrs
);
};
}