aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/vim/filetype.lua18
1 files changed, 12 insertions, 6 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index c310eb3e42..193c9b0199 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -2061,7 +2061,8 @@ end
--- pattern, if any) and should return a string that will be used as the
--- buffer's filetype. Optionally, the function can return a second function
--- value which, when called, modifies the state of the buffer. This can be used
---- to, for example, set filetype-specific buffer variables.
+--- to, for example, set filetype-specific buffer variables. This function will
+--- be called by Nvim before setting the buffer's filetype.
---
--- Filename patterns can specify an optional priority to resolve cases when a
--- file path matches multiple patterns. Higher priorities are matched first.
@@ -2376,11 +2377,16 @@ function M.match(args)
-- If the function tries to use the filename that is nil then it will fail,
-- but this enables checks which do not need a filename to still work.
local ok
- ok, ft = pcall(require('vim.filetype.detect').match_contents, contents, name, function(ext)
- return dispatch(extension[ext], name, bufnr)
- end)
- if ok and ft then
- return ft
+ ok, ft, on_detect = pcall(
+ require('vim.filetype.detect').match_contents,
+ contents,
+ name,
+ function(ext)
+ return dispatch(extension[ext], name, bufnr)
+ end
+ )
+ if ok then
+ return ft, on_detect
end
end
end