diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2022-06-09 13:12:36 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 13:12:36 -0600 |
commit | 58323b1fe2e494cf6a75f108780e21c08996c08e (patch) | |
tree | a301a6d047003efa3835460a793a87d4f205f785 /runtime/filetype.lua | |
parent | 28e43881b74b800fa37957e77b5e56994e1120cd (diff) | |
download | rneovim-58323b1fe2e494cf6a75f108780e21c08996c08e.tar.gz rneovim-58323b1fe2e494cf6a75f108780e21c08996c08e.tar.bz2 rneovim-58323b1fe2e494cf6a75f108780e21c08996c08e.zip |
feat(filetype): remove side effects from vim.filetype.match (#18894)
Many filetypes from filetype.vim set buffer-local variables, meaning
vim.filetype.match cannot be used without side effects. Instead of
setting these buffer-local variables in the filetype detection functions
themselves, have vim.filetype.match return an optional function value
that, when called, sets these variables. This allows vim.filetype.match
to work without side effects.
Diffstat (limited to 'runtime/filetype.lua')
-rw-r--r-- | runtime/filetype.lua | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/runtime/filetype.lua b/runtime/filetype.lua index d2510c5494..b002b8971b 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -11,8 +11,14 @@ vim.api.nvim_create_augroup('filetypedetect', { clear = false }) vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, { group = 'filetypedetect', - callback = function() - vim.filetype.match(vim.fn.expand('<afile>')) + callback = function(args) + local ft, on_detect = vim.filetype.match(args.file, args.buf) + if ft then + vim.api.nvim_buf_set_option(args.buf, 'filetype', ft) + if on_detect then + on_detect(args.buf) + end + end end, }) |