mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
fix(filetype): call on_detect before setting buffer filetype
The on_detect functions returned by filetype.lua set buffer local variables which are often used by filetype plugins. For example, the on_detect function for shell buffers sets variables such as b:is_bash or b:is_sh, which are used by the sh ftplugin. When called after setting the buffer's filetype, these variables cannot be used by the ftplugin (because they are not yet defined). Instead, call on_detect before setting the buffer filetype so that any buffer variables set by on_detect can be used in the ftplugin.
This commit is contained in:
@@ -18,12 +18,15 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, {
|
||||
end)
|
||||
end
|
||||
else
|
||||
vim.api.nvim_buf_call(args.buf, function()
|
||||
vim.api.nvim_cmd({ cmd = 'setf', args = { ft } }, {})
|
||||
end)
|
||||
-- on_detect is called before setting the filetype so that it can set any buffer local
|
||||
-- variables that may be used the filetype's ftplugin
|
||||
if on_detect then
|
||||
on_detect(args.buf)
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_call(args.buf, function()
|
||||
vim.api.nvim_cmd({ cmd = 'setf', args = { ft } }, {})
|
||||
end)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user