aboutsummaryrefslogtreecommitdiff
path: root/runtime/filetype.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2022-03-13 15:52:41 -0600
committerGitHub <noreply@github.com>2022-03-13 15:52:41 -0600
commitf9f843e02e5a0a036caa35efa686897f0e04ee3c (patch)
tree09b0e9e7dbe4ac5b0685b38a151b72386fb160a3 /runtime/filetype.lua
parentce537bb2320325d73b79fd46ab09d51ed1cb7fc2 (diff)
downloadrneovim-f9f843e02e5a0a036caa35efa686897f0e04ee3c.tar.gz
rneovim-f9f843e02e5a0a036caa35efa686897f0e04ee3c.tar.bz2
rneovim-f9f843e02e5a0a036caa35efa686897f0e04ee3c.zip
refactor: use Lua autocommands in filetype.lua (#17711)
Diffstat (limited to 'runtime/filetype.lua')
-rw-r--r--runtime/filetype.lua38
1 files changed, 24 insertions, 14 deletions
diff --git a/runtime/filetype.lua b/runtime/filetype.lua
index 74e427c358..8224b79534 100644
--- a/runtime/filetype.lua
+++ b/runtime/filetype.lua
@@ -7,26 +7,36 @@ if vim.g.do_filetype_lua ~= 1 then
return
end
--- TODO: Remove vim.cmd once Lua autocommands land
-vim.cmd [[
-augroup filetypedetect
-au BufRead,BufNewFile * call v:lua.vim.filetype.match(expand('<afile>'))
+vim.api.nvim_create_augroup("filetypedetect", {clear = false})
+
+vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
+ group = "filetypedetect",
+ callback = function()
+ vim.filetype.match(vim.fn.expand("<afile>"))
+ end,
+})
-" These *must* be sourced after the autocommand above is created
+-- These *must* be sourced after the autocommand above is created
+vim.cmd [[
runtime! ftdetect/*.vim
runtime! ftdetect/*.lua
+]]
-" Set a marker so that the ftdetect scripts are not sourced a second time by filetype.vim
-let g:did_load_ftdetect = 1
+-- Set a marker so that the ftdetect scripts are not sourced a second time by filetype.vim
+vim.g.did_load_ftdetect = 1
-" If filetype.vim is disabled, set up the autocmd to use scripts.vim
-if exists('did_load_filetypes')
- au BufRead,BufNewFile * if !did_filetype() && expand('<amatch>') !~ g:ft_ignore_pat | runtime! scripts.vim | endif
- au StdinReadPost * if !did_filetype() | runtime! scripts.vim | endif
-endif
+-- If filetype.vim is disabled, set up the autocmd to use scripts.vim
+if vim.g.did_load_filetypes then
+ vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
+ group = "filetypedetect",
+ command = "if !did_filetype() && expand('<amatch>') !~ g:ft_ignore_pat | runtime! scripts.vim | endif",
+ })
-augroup END
-]]
+ vim.api.nvim_create_autocmd("StdinReadPost", {
+ group = "filetypedetect",
+ command = "if !did_filetype() | runtime! scripts.vim | endif",
+ })
+end
if not vim.g.ft_ignore_pat then
vim.g.ft_ignore_pat = "\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$"