robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
9a5abf0277
master
1if vim . g . did_load_filetypes then 2return 3end 4vim . g . did_load_filetypes =1 5 6vim . api . nvim_create_augroup ( 'filetypedetect' , { clear =false } ) 7 8vim . api . nvim_create_autocmd ( { 'BufRead' , 'BufNewFile' , 'StdinReadPost' } , { 9group ='filetypedetect' , 10callback =function ( ev ) 11if not vim . api . nvim_buf_is_valid ( ev . buf ) then 12return 13end 14local ft , on_detect , is_fallback =vim . filetype . match ( { 15-- The unexpanded file name is needed here. #27914 16-- However, bufname() can't be used, as it doesn't work with :doautocmd. #31306 17filename =ev . file , 18buf =ev . buf , 19} ) 20if ft then 21-- on_detect is called before setting the filetype so that it can set any buffer local 22-- variables that may be used the filetype's ftplugin 23if on_detect then 24on_detect ( ev . buf ) 25end 26 27vim . _with ( { buf =ev . buf } , function () 28vim . api . nvim_cmd ( { 29cmd ='setf' , 30args =( is_fallback and { 'FALLBACK' , ft } or { ft } ), 31} , {} ) 32end ) 33end 34end , 35} ) 36 37-- Set up the autocmd for user scripts.vim 38vim . api . nvim_create_autocmd ( { 'BufRead' , 'BufNewFile' } , { 39group ='filetypedetect' , 40command ="if !did_filetype() && expand('<amatch>') !~ g:ft_ignore_pat | runtime! scripts.vim | endif" , 41} ) 42 43vim . api . nvim_create_autocmd ( 'StdinReadPost' , { 44group ='filetypedetect' , 45command ='if !did_filetype() | runtime! scripts.vim | endif' , 46} ) 47 48if not vim . g . ft_ignore_pat then 49vim . g . ft_ignore_pat ='\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$' 50end 51 52-- These *must* be sourced after the autocommands above are created 53vim . cmd ( [[ 54augroup filetypedetect 55runtime! ftdetect/*.{vim,lua} 56augroup END 57]] )