filetype.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. if vim.g.did_load_filetypes and vim.g.did_load_filetypes ~= 0 then
  2. return
  3. end
  4. -- For now, make this opt-in with a global variable
  5. if vim.g.do_filetype_lua ~= 1 then
  6. return
  7. end
  8. vim.api.nvim_create_augroup("filetypedetect", {clear = false})
  9. vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
  10. group = "filetypedetect",
  11. callback = function()
  12. vim.filetype.match(vim.fn.expand("<afile>"))
  13. end,
  14. })
  15. -- These *must* be sourced after the autocommand above is created
  16. vim.cmd [[
  17. runtime! ftdetect/*.vim
  18. runtime! ftdetect/*.lua
  19. ]]
  20. -- Set a marker so that the ftdetect scripts are not sourced a second time by filetype.vim
  21. vim.g.did_load_ftdetect = 1
  22. -- If filetype.vim is disabled, set up the autocmd to use scripts.vim
  23. if vim.g.did_load_filetypes then
  24. vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
  25. group = "filetypedetect",
  26. command = "if !did_filetype() && expand('<amatch>') !~ g:ft_ignore_pat | runtime! scripts.vim | endif",
  27. })
  28. vim.api.nvim_create_autocmd("StdinReadPost", {
  29. group = "filetypedetect",
  30. command = "if !did_filetype() | runtime! scripts.vim | endif",
  31. })
  32. end
  33. if not vim.g.ft_ignore_pat then
  34. vim.g.ft_ignore_pat = "\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$"
  35. end