2024-05-05 19:39:35 +02:00
|
|
|
{ lib, config, ... }:
|
2023-04-15 15:21:25 +02:00
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(lib.mkRenamedOptionModule
|
|
|
|
[
|
|
|
|
"plugins"
|
|
|
|
"editorconfig"
|
|
|
|
"enable"
|
|
|
|
]
|
|
|
|
[
|
|
|
|
"editorconfig"
|
|
|
|
"enable"
|
2024-05-05 19:39:35 +02:00
|
|
|
]
|
2023-04-15 15:21:25 +02:00
|
|
|
)
|
|
|
|
(lib.mkRemovedOptionModule [
|
|
|
|
"plugins"
|
|
|
|
"editorconfig"
|
|
|
|
"package"
|
|
|
|
] "editorconfig is now builtin, no plugin required")
|
|
|
|
];
|
|
|
|
|
|
|
|
options.editorconfig = {
|
2024-08-30 14:37:41 -05:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2023-04-15 15:21:25 +02:00
|
|
|
default = true;
|
|
|
|
description = "editorconfig plugin for neovim";
|
|
|
|
};
|
|
|
|
|
2024-08-30 14:37:41 -05:00
|
|
|
properties = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
2023-04-15 15:21:25 +02:00
|
|
|
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
|
2024-05-05 19:39:35 +02:00
|
|
|
{
|
2024-08-30 14:37:41 -05:00
|
|
|
globals.editorconfig = lib.mkIf (!cfg.enable) false;
|
2023-04-15 15:21:25 +02:00
|
|
|
|
|
|
|
extraConfigLua =
|
2024-05-05 19:39:35 +02:00
|
|
|
let
|
2023-04-15 15:21:25 +02:00
|
|
|
mkProperty = name: function: ''
|
|
|
|
__editorconfig.properties.${name} = ${function}
|
2024-05-05 19:39:35 +02:00
|
|
|
'';
|
2023-04-15 15:21:25 +02:00
|
|
|
propertiesString = lib.concatLines (lib.mapAttrsToList mkProperty cfg.properties);
|
2024-05-05 19:39:35 +02:00
|
|
|
in
|
2024-08-30 14:37:41 -05:00
|
|
|
lib.mkIf (propertiesString != "" && cfg.enable) ''
|
2024-05-05 19:39:35 +02:00
|
|
|
do
|
2023-04-15 15:21:25 +02:00
|
|
|
local __editorconfig = require('editorconfig')
|
2024-05-05 19:39:35 +02:00
|
|
|
|
2023-04-15 15:21:25 +02:00
|
|
|
${propertiesString}
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|