From dbb840da01c72d8a311e0c55d3248d78a64b63a4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Jul 2023 06:46:16 +0800 Subject: fix(runtime): respect 'rtp' order for all runtime files (#24335) --- runtime/filetype.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'runtime/filetype.lua') diff --git a/runtime/filetype.lua b/runtime/filetype.lua index f772785d21..cf5fe39656 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -32,8 +32,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 -- cgit From 020d1f626a3fbda84b84b2f57e8a85662a792a1a Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Thu, 24 Aug 2023 12:48:21 -0500 Subject: fix(filetype): call on_detect before setting buffer filetype The on_detect functions returned by filetype.lua set buffer local variables which are often used by filetype plugins. For example, the on_detect function for shell buffers sets variables such as b:is_bash or b:is_sh, which are used by the sh ftplugin. When called after setting the buffer's filetype, these variables cannot be used by the ftplugin (because they are not yet defined). Instead, call on_detect before setting the buffer filetype so that any buffer variables set by on_detect can be used in the ftplugin. --- runtime/filetype.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'runtime/filetype.lua') diff --git a/runtime/filetype.lua b/runtime/filetype.lua index cf5fe39656..4a4f37a1c4 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -18,12 +18,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, }) -- cgit From 670c7609c85547ef041af8cf17139a396d6af050 Mon Sep 17 00:00:00 2001 From: Hongbo Liu Date: Wed, 30 Aug 2023 11:14:58 -0400 Subject: fix(filetype): make sure buffer is valid before call nvim_buf_call (#24922) --- runtime/filetype.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'runtime/filetype.lua') diff --git a/runtime/filetype.lua b/runtime/filetype.lua index 4a4f37a1c4..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 -- cgit