From 34d1eaa792fa332cea190568967a489e324fca6f Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 4 Jan 2023 14:36:18 -0700 Subject: 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. --- runtime/plugin/editorconfig.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'runtime') 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, }) -- cgit From 6ffa434f0b1c6e82fb6c1445d5d7382e0ef22e07 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 4 Jan 2023 15:10:19 -0700 Subject: refactor(editorconfig)!: change editorconfig_enable to editorconfig --- runtime/doc/editorconfig.txt | 14 ++++++++------ runtime/doc/news.txt | 2 +- runtime/plugin/editorconfig.lua | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/editorconfig.txt b/runtime/doc/editorconfig.txt index e93713e5ff..04a057e5ff 100644 --- a/runtime/doc/editorconfig.txt +++ b/runtime/doc/editorconfig.txt @@ -13,16 +13,18 @@ the opened file are applied. For more information on EditorConfig, see https://editorconfig.org/. - *g:editorconfig_enable* -EditorConfig integration can be disabled by adding >lua + *g:editorconfig* *b:editorconfig* +EditorConfig integration can be disabled globally by adding >lua - vim.g.editorconfig_enable = false + vim.g.editorconfig = false < -to the user's |init.lua| file (or the Vimscript equivalent to |init.vim|). +to the user's |init.lua| file (or the Vimscript equivalent to |init.vim|). It +can also be disabled per-buffer by setting the |b:editorconfig| buffer-local +variable to `false`. - *b:editorconfig* When Nvim finds a valid .editorconfig file it will store the applied -properties in the buffer variable |b:editorconfig|. +properties in the buffer variable |b:editorconfig| if it was not already set to +`false` by the user. *editorconfig-properties* The following properties are supported by default: diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 3e291e59c9..33ac9ddd20 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -53,7 +53,7 @@ The following new APIs or features were added. • EditorConfig support is now builtin. This is enabled by default and happens automatically. To disable it, users should add >lua - vim.g.editorconfig_enable = false + vim.g.editorconfig = false < (or the Vimscript equivalent) to their |config| file. diff --git a/runtime/plugin/editorconfig.lua b/runtime/plugin/editorconfig.lua index c715279fd5..54cd0e828e 100644 --- a/runtime/plugin/editorconfig.lua +++ b/runtime/plugin/editorconfig.lua @@ -3,8 +3,7 @@ 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)) + local enable = vim.F.if_nil(vim.b.editorconfig, vim.F.if_nil(vim.g.editorconfig, true)) if not enable then return end -- cgit