Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim support file to detect file types in scripts |
| 2 | " |
| 3 | " Maintainer: Bram Moolenaar <Bram@vim.org> |
Bram Moolenaar | 10e8ff9 | 2023-06-10 21:40:39 +0100 | [diff] [blame] | 4 | " Last change: 2023 Jun 08 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | |
| 6 | " This file is called by an autocommand for every file that has just been |
| 7 | " loaded into a buffer. It checks if the type of file can be recognized by |
| 8 | " the file contents. The autocommand is in $VIMRUNTIME/filetype.vim. |
Bram Moolenaar | 3a429ef | 2017-06-11 17:10:32 +0200 | [diff] [blame] | 9 | " |
| 10 | " Note that the pattern matches are done with =~# to avoid the value of the |
| 11 | " 'ignorecase' option making a difference. Where case is to be ignored use |
| 12 | " =~? instead. Do not use =~ anywhere. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 13 | |
| 14 | |
Bram Moolenaar | 299d8e5 | 2022-02-13 20:32:02 +0000 | [diff] [blame] | 15 | " Bail out when a FileType autocommand has already set the filetype. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 16 | if did_filetype() |
| 17 | finish |
| 18 | endif |
| 19 | |
| 20 | " Load the user defined scripts file first |
| 21 | " Only do this when the FileType autocommand has not been triggered yet |
Bram Moolenaar | f4630b6 | 2005-05-20 21:31:17 +0000 | [diff] [blame] | 22 | if exists("myscriptsfile") && filereadable(expand(myscriptsfile)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 23 | execute "source " . myscriptsfile |
| 24 | if did_filetype() |
| 25 | finish |
| 26 | endif |
| 27 | endif |
| 28 | |
Bram Moolenaar | 299d8e5 | 2022-02-13 20:32:02 +0000 | [diff] [blame] | 29 | " The main code is in a compiled function for speed. |
| 30 | call dist#script#DetectFiletype() |