mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
Merge 20b8124527
into a0d8c2b86e
This commit is contained in:
commit
f4003f6832
@ -2791,6 +2791,7 @@ vim.filetype.match({args}) *vim.filetype.match()*
|
||||
(`function?`) A function that modifies buffer state when called (for
|
||||
example, to set some filetype specific buffer variables). The function
|
||||
accepts a buffer number as its only argument.
|
||||
(`boolean?`) True if a match was found via fallback
|
||||
|
||||
|
||||
==============================================================================
|
||||
|
@ -11,21 +11,13 @@ 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({
|
||||
local ft, on_detect, is_fallback = 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)
|
||||
if ft then
|
||||
vim._with({ buf = args.buf }, function()
|
||||
vim.api.nvim_cmd({ cmd = 'setf', args = { 'FALLBACK', ft } }, {})
|
||||
end)
|
||||
end
|
||||
else
|
||||
if ft then
|
||||
-- on_detect is called before setting the filetype so that it can set any buffer local
|
||||
-- variables that may be used the filetype's ftplugin
|
||||
if on_detect then
|
||||
@ -33,7 +25,10 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, {
|
||||
end
|
||||
|
||||
vim._with({ buf = args.buf }, function()
|
||||
vim.api.nvim_cmd({ cmd = 'setf', args = { ft } }, {})
|
||||
vim.api.nvim_cmd({
|
||||
cmd = 'setf',
|
||||
args = (is_fallback and { 'FALLBACK', ft } or { ft }),
|
||||
}, {})
|
||||
end)
|
||||
end
|
||||
end,
|
||||
|
@ -2706,6 +2706,7 @@ end
|
||||
---@return function|nil # A function that modifies buffer state when called (for example, to set some
|
||||
--- filetype specific buffer variables). The function accepts a buffer number as
|
||||
--- its only argument.
|
||||
---@return boolean|nil # True if a match was found via fallback
|
||||
function M.match(args)
|
||||
vim.validate({
|
||||
arg = { args, 't' },
|
||||
@ -2796,11 +2797,19 @@ function M.match(args)
|
||||
return dispatch(extension[ext], name, bufnr)
|
||||
end
|
||||
)
|
||||
if ok then
|
||||
if ok and ft then
|
||||
return ft, on_detect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Generic configuration file used as fallback
|
||||
if name and bufnr then
|
||||
ft = detect.conf(name, bufnr)
|
||||
if ft then
|
||||
return ft, nil, true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Get the default option value for a {filetype}.
|
||||
|
Loading…
Reference in New Issue
Block a user