mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #18353 from jamessan/ft-match-fix
This commit is contained in:
commit
a1542b091d
@ -1482,8 +1482,18 @@ end
|
|||||||
local pattern_sorted = sort_by_priority(pattern)
|
local pattern_sorted = sort_by_priority(pattern)
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
local function normalize_path(path)
|
local function normalize_path(path, as_pattern)
|
||||||
return (path:gsub("\\", "/"):gsub("^~", vim.env.HOME))
|
local normal = path:gsub("\\", '/')
|
||||||
|
if normal:find('^~') then
|
||||||
|
if as_pattern then
|
||||||
|
-- Escape Lua's metacharacters when $HOME is used in a pattern.
|
||||||
|
-- The rest of path should already be properly escaped.
|
||||||
|
normal = vim.env.HOME:gsub('[-^$()%%.%[%]+?]', '%%%0') .. normal:sub(2)
|
||||||
|
else
|
||||||
|
normal = vim.env.HOME .. normal:sub(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return normal
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Add new filetype mappings.
|
--- Add new filetype mappings.
|
||||||
@ -1552,7 +1562,7 @@ function M.add(filetypes)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for k, v in pairs(filetypes.pattern or {}) do
|
for k, v in pairs(filetypes.pattern or {}) do
|
||||||
pattern[normalize_path(k)] = v
|
pattern[normalize_path(k, true)] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
if filetypes.pattern then
|
if filetypes.pattern then
|
||||||
|
@ -70,6 +70,7 @@ describe('vim.filetype', function()
|
|||||||
it('works with patterns', function()
|
it('works with patterns', function()
|
||||||
eq('markdown', exec_lua([[
|
eq('markdown', exec_lua([[
|
||||||
local root = ...
|
local root = ...
|
||||||
|
vim.env.HOME = '/a-funky+home%dir'
|
||||||
vim.filetype.add({
|
vim.filetype.add({
|
||||||
pattern = {
|
pattern = {
|
||||||
['~/blog/.*%.txt'] = 'markdown',
|
['~/blog/.*%.txt'] = 'markdown',
|
||||||
|
Loading…
Reference in New Issue
Block a user