diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-23 11:46:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-23 11:46:23 +0800 |
commit | 2955c921ceaf5764e8d1592a78370d9ca3a268e2 (patch) | |
tree | e70e5a0652b0a035a11129901425a144c679b3a8 /runtime/filetype.lua | |
parent | a629888427d7dfd1b45d4cc456f9c6c7a7d5a854 (diff) | |
download | rneovim-2955c921ceaf5764e8d1592a78370d9ca3a268e2.tar.gz rneovim-2955c921ceaf5764e8d1592a78370d9ca3a268e2.tar.bz2 rneovim-2955c921ceaf5764e8d1592a78370d9ca3a268e2.zip |
fix(filetype): use unexpanded file name (#27931)
When the edited file is a symlink, the unexpanded file name is needed to
to achieve the same behavior as the autocommand pattern matching in Vim.
Neither args.file nor args.match are guaranteed to be unexpanded, so use
bufname() instead.
Diffstat (limited to 'runtime/filetype.lua')
-rw-r--r-- | runtime/filetype.lua | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/runtime/filetype.lua b/runtime/filetype.lua index 3f2a7c2960..4880ed55ef 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -11,7 +11,12 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { if not vim.api.nvim_buf_is_valid(args.buf) then return end - local ft, on_detect = vim.filetype.match({ filename = args.match, buf = args.buf }) + 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), + buf = args.buf, + }) if not ft then -- Generic configuration file used as fallback ft = require('vim.filetype.detect').conf(args.file, args.buf) |