mirror of
https://github.com/neovim/neovim.git
synced 2026-05-05 05:25:10 +00:00
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.
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user