forked from nix-community/nixvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editorconfig.nix
75 lines (70 loc) · 1.89 KB
/
editorconfig.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
{ lib, config, ... }:
with lib;
{
imports = [
(lib.mkRenamedOptionModule
[
"plugins"
"editorconfig"
"enable"
]
[
"editorconfig"
"enable"
]
)
(lib.mkRemovedOptionModule [
"plugins"
"editorconfig"
"package"
] "editorconfig is now builtin, no plugin required")
];
options.editorconfig = {
enable = mkOption {
type = types.bool;
default = true;
description = "editorconfig plugin for neovim";
};
properties = mkOption {
type = types.attrsOf types.str;
default = { };
description = ''
The table key is a property name and the value is a callback function which accepts the
number of the buffer to be modified, the value of the property in the .editorconfig file,
and (optionally) a table containing all of the other properties and their values (useful
for properties which depend on other properties). The value is always a string and must be
coerced if necessary.
'';
example = {
foo = ''
function(bufnr, val, opts)
if opts.charset and opts.charset ~= "utf-8" then
error("foo can only be set when charset is utf-8", 0)
end
vim.b[bufnr].foo = val
end
'';
};
};
};
config =
let
cfg = config.editorconfig;
in
{
globals.editorconfig = mkIf (!cfg.enable) false;
extraConfigLua =
let
mkProperty = name: function: ''
__editorconfig.properties.${name} = ${function}
'';
propertiesString = lib.concatLines (lib.mapAttrsToList mkProperty cfg.properties);
in
mkIf (propertiesString != "" && cfg.enable) ''
do
local __editorconfig = require('editorconfig')
${propertiesString}
end
'';
};
}