diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:40:31 +0000 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:40:31 +0000 |
| commit | 339e2d15cc26fe86988ea06468d912a46c8d6f29 (patch) | |
| tree | a6167fc8fcfc6ae2dc102f57b2473858eac34063 /runtime/filetype.lua | |
| parent | 067dc73729267c0262438a6fdd66e586f8496946 (diff) | |
| parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
| download | rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.gz rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.bz2 rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.zip | |
Merge remote-tracking branch 'upstream/master' into fix_repeatcmdline
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 |