diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:25 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:25 +0000 |
commit | 1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (patch) | |
tree | cd08258054db80bb9a11b1061bb091c70b76926a /runtime/filetype.lua | |
parent | eaa89c11d0f8aefbb512de769c6c82f61a8baca3 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.tar.gz rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.tar.bz2 rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.zip |
Merge remote-tracking branch 'upstream/master' into aucmd_textputpostaucmd_textputpost
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 |