From 1077843b9bee550fe2ae1e3e700a9c135005d593 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 6 Dec 2024 20:57:21 +0800 Subject: [PATCH] fix(filetype): make filetype detection work with :doautocmd (#31470) --- runtime/filetype.lua | 4 ++-- test/functional/lua/filetype_spec.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/filetype.lua b/runtime/filetype.lua index 797033da06..730991a00c 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -13,8 +13,8 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { end local ft, on_detect = vim.filetype.match({ -- The unexpanded file name is needed here. #27914 - -- Neither args.file nor args.match are guaranteed to be unexpanded. - filename = vim.fn.bufname(args.buf), + -- However, bufname() can't be used, as it doesn't work with :doautocmd. #31306 + filename = args.file, buf = args.buf, }) if not ft then diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua index 6a4f8d70f3..b75ff75b05 100644 --- a/test/functional/lua/filetype_spec.lua +++ b/test/functional/lua/filetype_spec.lua @@ -208,7 +208,7 @@ describe('filetype.lua', function() eq('gitconfig', api.nvim_get_option_value('filetype', {})) end) - pending('works with :doautocmd BufRead #31306', function() + it('works with :doautocmd BufRead #31306', function() clear({ args = { '--clean' } }) eq('', api.nvim_get_option_value('filetype', {})) command('doautocmd BufRead README.md')