fix(filetype): use :setf instead of nvim_buf_set_option (#20334)

This commit is contained in:
zeertzjq
2022-09-25 22:29:25 +08:00
committed by GitHub
parent 91e912f8d4
commit f8a1cadccf
2 changed files with 14 additions and 2 deletions

View File

@ -14,10 +14,14 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, {
-- Generic configuration file used as fallback
ft = require('vim.filetype.detect').conf(args.file, args.buf)
if ft then
vim.api.nvim_cmd({ cmd = 'setf', args = { 'FALLBACK', ft } }, {})
vim.api.nvim_buf_call(args.buf, function()
vim.api.nvim_cmd({ cmd = 'setf', args = { 'FALLBACK', ft } }, {})
end)
end
else
vim.api.nvim_buf_set_option(args.buf, 'filetype', ft)
vim.api.nvim_buf_call(args.buf, function()
vim.api.nvim_cmd({ cmd = 'setf', args = { ft } }, {})
end)
if on_detect then
on_detect(args.buf)
end