mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 19:35:37 +00:00
fix(filetype): use :setf instead of nvim_buf_set_option (#20334)
This commit is contained in:
@@ -14,10 +14,14 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, {
|
|||||||
-- Generic configuration file used as fallback
|
-- Generic configuration file used as fallback
|
||||||
ft = require('vim.filetype.detect').conf(args.file, args.buf)
|
ft = require('vim.filetype.detect').conf(args.file, args.buf)
|
||||||
if ft then
|
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
|
end
|
||||||
else
|
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
|
if on_detect then
|
||||||
on_detect(args.buf)
|
on_detect(args.buf)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
|
local meths = helpers.meths
|
||||||
local clear = helpers.clear
|
local clear = helpers.clear
|
||||||
local pathroot = helpers.pathroot
|
local pathroot = helpers.pathroot
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
@@ -94,3 +95,10 @@ describe('vim.filetype', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('filetype.lua', function()
|
||||||
|
it('does not override user autocommands that set filetype #20333', function()
|
||||||
|
clear({args={'--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md'}})
|
||||||
|
eq('notmarkdown', meths.buf_get_option(0, 'filetype'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user