diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
commit | 931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch) | |
tree | d8c1843a95da5ea0bb4acc09f7e37843d9995c86 /runtime/filetype.lua | |
parent | 142d9041391780ac15b89886a54015fdc5c73995 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-userreg.tar.gz rneovim-userreg.tar.bz2 rneovim-userreg.zip |
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'runtime/filetype.lua')
-rw-r--r-- | runtime/filetype.lua | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/runtime/filetype.lua b/runtime/filetype.lua index f772785d21..3f2a7c2960 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -8,6 +8,9 @@ vim.api.nvim_create_augroup('filetypedetect', { clear = false }) vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { group = 'filetypedetect', callback = function(args) + 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 }) if not ft then -- Generic configuration file used as fallback @@ -18,12 +21,15 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { end) end else - vim.api.nvim_buf_call(args.buf, function() - vim.api.nvim_cmd({ cmd = 'setf', args = { ft } }, {}) - end) + -- 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 on_detect(args.buf) end + + vim.api.nvim_buf_call(args.buf, function() + vim.api.nvim_cmd({ cmd = 'setf', args = { ft } }, {}) + end) end end, }) @@ -32,8 +38,7 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { if not vim.g.did_load_ftdetect then vim.cmd([[ augroup filetypedetect - runtime! ftdetect/*.vim - runtime! ftdetect/*.lua + runtime! ftdetect/*.{vim,lua} augroup END ]]) end |