From 927d4d2a15b8474cd6c605df65ef53873cf73131 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 3 Sep 2022 19:27:57 +0200 Subject: fix(filetype): run filetype.match on StdinReadPost (#20070) Problem: filetype detection does not run on piped input Solution: add `StdinReadPost` to main filetype.lua autocommand Rationale: legacy filetype detection checked contents by sourcing `scripts.vim` in separate autocommands, including on `StdinReadPost`. For Lua filetype detection, this was moved into the main autocommand, with bundled `scripts.vim` gated behind `g:do_legacy_filetype` (i.e., only user `scripts.vim` are sourced for compatibility by default). Adding `StdinReadPost` to the main autocommand again runs content checks on piped input without requiring code duplication and low-payoff refactoring. --- runtime/filetype.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/filetype.lua') diff --git a/runtime/filetype.lua b/runtime/filetype.lua index 9f5b5fd0dc..c50ba6453d 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -6,7 +6,7 @@ vim.g.did_load_filetypes = 1 vim.api.nvim_create_augroup('filetypedetect', { clear = false }) -vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, { +vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { group = 'filetypedetect', callback = function(args) local ft, on_detect = vim.filetype.match({ filename = args.match, buf = args.buf }) -- cgit From f8a1cadccff39923643fdea2e282be9fffa60e99 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 25 Sep 2022 22:29:25 +0800 Subject: fix(filetype): use :setf instead of nvim_buf_set_option (#20334) --- runtime/filetype.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'runtime/filetype.lua') diff --git a/runtime/filetype.lua b/runtime/filetype.lua index c50ba6453d..ee9d5a0a75 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -14,10 +14,14 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { -- Generic configuration file used as fallback ft = require('vim.filetype.detect').conf(args.file, args.buf) if ft then - vim.api.nvim_cmd({ cmd = 'setf', args = { 'FALLBACK', ft } }, {}) + vim.api.nvim_buf_call(args.buf, function() + vim.api.nvim_cmd({ cmd = 'setf', args = { 'FALLBACK', ft } }, {}) + end) end else - vim.api.nvim_buf_set_option(args.buf, 'filetype', ft) + vim.api.nvim_buf_call(args.buf, function() + vim.api.nvim_cmd({ cmd = 'setf', args = { ft } }, {}) + end) if on_detect then on_detect(args.buf) end -- cgit From 042eb74ff1ed63d79f8a642649cd6be6ec4b0eb9 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 17 Oct 2022 08:52:40 +0200 Subject: feat(runtime)!: remove filetype.vim (#20428) Made obsolete by now graduated `filetype.lua` (enabled by default). Note that changes or additions to the filetype detection still need to be made through a PR to vim/vim as we port the _logic_ as well as tests. --- 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 ee9d5a0a75..f772785d21 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -1,5 +1,4 @@ --- Skip if legacy filetype is enabled or filetype detection is disabled -if vim.g.do_legacy_filetype or vim.g.did_load_filetypes then +if vim.g.did_load_filetypes then return end vim.g.did_load_filetypes = 1 -- cgit