mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-25 02:08:40 +02:00
editorconfig: Add editorconfig plugin (#265)
This is temporary, until neovim 0.9 when we will have builtin editorconfig
This commit is contained in:
parent
ac2d771f55
commit
d531c836d4
3 changed files with 78 additions and 0 deletions
|
@ -63,6 +63,7 @@
|
||||||
./utils/comment-nvim.nix
|
./utils/comment-nvim.nix
|
||||||
./utils/commentary.nix
|
./utils/commentary.nix
|
||||||
./utils/easyescape.nix
|
./utils/easyescape.nix
|
||||||
|
./utils/editorconfig.nix
|
||||||
./utils/endwise.nix
|
./utils/endwise.nix
|
||||||
./utils/floaterm.nix
|
./utils/floaterm.nix
|
||||||
./utils/goyo.nix
|
./utils/goyo.nix
|
||||||
|
|
59
plugins/utils/editorconfig.nix
Normal file
59
plugins/utils/editorconfig.nix
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
} @ args:
|
||||||
|
with lib; let
|
||||||
|
# TODO: Migrate to builtin editorconfig in neovim 0.9
|
||||||
|
helpers = import ../helpers.nix args;
|
||||||
|
in {
|
||||||
|
options.plugins.editorconfig = {
|
||||||
|
enable = mkEnableOption "editorconfig plugin for neovim";
|
||||||
|
|
||||||
|
package = helpers.mkPackageOption "editorconfig.nvim" pkgs.vimPlugins.editorconfig-nvim;
|
||||||
|
|
||||||
|
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.plugins.editorconfig;
|
||||||
|
in
|
||||||
|
mkIf cfg.enable {
|
||||||
|
extraPlugins = [cfg.package];
|
||||||
|
|
||||||
|
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
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
18
tests/test-sources/plugins/utils/editorconfig.nix
Normal file
18
tests/test-sources/plugins/utils/editorconfig.nix
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
# TODO: convert to disable test in neovim 0.9
|
||||||
|
empty = {
|
||||||
|
plugins.editorconfig.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
example = {
|
||||||
|
plugins.editorconfig.enable = true;
|
||||||
|
plugins.editorconfig.properties.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
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue