Skip to content

Commit

Permalink
Use a timer to defer configuration
Browse files Browse the repository at this point in the history
There is no way to establish precedence or priority of autocommands in
Neovim, yet we want to ensure that the editorconfig options are applied
last, after any file type settings or settings from other plugins, to
ensure they have the highest priority. Using a timer with value 0 causes
the function to be deferred until after all other autocommands have run.
  • Loading branch information
gpanders committed Jul 31, 2021
1 parent 5cae6a9 commit 2e44b10
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions after/plugin/editorconfig.vim → plugin/editorconfig.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ if exists('g:loaded_editorconfig') || !has('nvim')
endif
let g:loaded_editorconfig = 1

" The autocmds must be set in the after/ directory to ensure they will run
" last
function! s:load(...)
lua require('editorconfig').config()
endfunction

augroup editorconfig
autocmd! BufNewFile,BufRead,BufFilePost * lua require('editorconfig').config()
" Use a timer with value 0 to defer executing the autocommand until after
" all other autocommands have run. This will ensure that settings applied
" by editorconfig take highest precedence.
autocmd! BufNewFile,BufRead,BufFilePost * call timer_start(0, function('s:load'))
augroup END

0 comments on commit 2e44b10

Please sign in to comment.