diff options
author | Gregory Anders <greg@gpanders.com> | 2023-01-04 14:36:18 -0700 |
---|---|---|
committer | Gregory Anders <greg@gpanders.com> | 2023-01-07 08:19:12 -0700 |
commit | 34d1eaa792fa332cea190568967a489e324fca6f (patch) | |
tree | ccc218ca7e709141c455b5ffe76aaf9cb9604023 /runtime/plugin/editorconfig.lua | |
parent | 42afa0369a3c01dddd1efef1397bbf46011f391b (diff) | |
download | rneovim-34d1eaa792fa332cea190568967a489e324fca6f.tar.gz rneovim-34d1eaa792fa332cea190568967a489e324fca6f.tar.bz2 rneovim-34d1eaa792fa332cea190568967a489e324fca6f.zip |
feat(editorconfig): allow editorconfig to be toggled dynamically
Rather than only check `editorconfig_enable` when the plugin is loaded,
check it each time the autocommand fires, so that users may enable or
disable it dynamically.
Also check for a buffer local version of the variable, so that
editorconfig can be enabled or disabled per-buffer.
Diffstat (limited to 'runtime/plugin/editorconfig.lua')
-rw-r--r-- | runtime/plugin/editorconfig.lua | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/runtime/plugin/editorconfig.lua b/runtime/plugin/editorconfig.lua index 60eb861aaa..c715279fd5 100644 --- a/runtime/plugin/editorconfig.lua +++ b/runtime/plugin/editorconfig.lua @@ -1,11 +1,14 @@ -if vim.g.editorconfig_enable == false or vim.g.editorconfig_enable == 0 then - return -end - local group = vim.api.nvim_create_augroup('editorconfig', {}) vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead', 'BufFilePost' }, { group = group, callback = function(args) + -- Buffer-local enable has higher priority + local enable = + vim.F.if_nil(vim.b.editorconfig_enable, vim.F.if_nil(vim.g.editorconfig_enable, true)) + if not enable then + return + end + require('editorconfig').config(args.buf) end, }) |