fix(filetype): match on <afile> rather than <abuf> (#16943)

Filetype detection runs on BufRead and BufNewFile autocommands, both of
which can fire without an underlying buffer, so it's incorrect to use
<abuf> to determine the file path. Instead, match on <afile> and assume
that the buffer we're operating on is the current buffer. This is the
same assumption that filetype.vim makes, so it should be safe.
This commit is contained in:
Gregory Anders
2022-01-05 09:50:54 -07:00
committed by GitHub
parent 55a59e56ed
commit f40ce34563
3 changed files with 16 additions and 17 deletions

View File

@@ -9,7 +9,7 @@ end
vim.cmd [[
augroup filetypedetect
au BufRead,BufNewFile * call v:lua.vim.filetype.match(str2nr(expand('<abuf>')))
au BufRead,BufNewFile * call v:lua.vim.filetype.match(expand('<afile>'))
" These *must* be sourced after the autocommand above is created
runtime! ftdetect/*.vim