diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-26 13:31:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-26 13:31:37 +0800 |
commit | d6f406db4527deb693f0aef90316c25d846f5195 (patch) | |
tree | c70e3eef1aa8bc0347e6cb6bba4c83edda61ab7e | |
parent | 00e71d3da3464df2b4c4f33bfd5fac6d88e7c867 (diff) | |
download | rneovim-d6f406db4527deb693f0aef90316c25d846f5195.tar.gz rneovim-d6f406db4527deb693f0aef90316c25d846f5195.tar.bz2 rneovim-d6f406db4527deb693f0aef90316c25d846f5195.zip |
fix(filetype): don't use fnamemodify() with :e for extension (#27976)
Use pattern matching instead, as fnamemodify() with :e produces an empty
string when the file name only has an extension, leading to differences
in behavior from Vim.
Related #16955 #27972
-rw-r--r-- | runtime/lua/vim/filetype.lua | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index af5636a32d..a69391be18 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -1472,7 +1472,6 @@ local filename = { ['bash.bashrc'] = detect.bash, bashrc = detect.bash, ['.bashrc'] = detect.bash, - ['.env'] = detect.sh, ['.kshrc'] = detect.ksh, ['.profile'] = detect.sh, ['/etc/profile'] = detect.sh, @@ -2387,7 +2386,9 @@ function M.match(args) end -- Next, check file extension - local ext = fn.fnamemodify(name, ':e') + -- Don't use fnamemodify() with :e modifier here, + -- as that's empty when there is only an extension. + local ext = name:match('%.([^.]-)$') or '' ft, on_detect = dispatch(extension[ext], path, bufnr) if ft then return ft, on_detect |