11" Vim support file to detect file types
22"
33" Maintainer: Bram Moolenaar <[email protected] >4- " Last Change: 2017 May 27
4+ " Last Change: 2017 Jun 04
55
66" Listen very carefully, I will say this only once
77if exists (" did_load_filetypes" )
@@ -1181,14 +1181,21 @@ au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md setf markdown
11811181" Mason
11821182au BufNewFile ,BufRead *.mason,*.mhtml,*.comp setf mason
11831183
1184- " Matlab or Objective C
1184+ " Mathematica, Matlab, Murphi or Objective C
11851185au BufNewFile ,BufRead *.m call s: FTm ()
11861186
11871187func ! s: FTm ()
11881188 let n = 1
1189- while n < 10
1189+ let saw_comment = 0 " Whether we've seen a multiline comment leader.
1190+ while n < 100
11901191 let line = getline (n )
1191- if line = ~ ' ^\s*\(#\s*\(include\|import\)\>\|@import\>\|/\*\|//\)'
1192+ if line = ~ ' ^\s*/\*'
1193+ " /* ... */ is a comment in Objective C and Murphi, so we can't conclude
1194+ " it's either of them yet, but track this as a hint in case we don't see
1195+ " anything more definitive.
1196+ let saw_comment = 1
1197+ endif
1198+ if line = ~ ' ^\s*\(#\s*\(include\|import\)\>\|@import\>\|//\)'
11921199 setf objc
11931200 return
11941201 endif
@@ -1200,11 +1207,23 @@ func! s:FTm()
12001207 setf mma
12011208 return
12021209 endif
1210+ if line = ~ ' ^\c\s*\(\(type\|var\)\>\|--\)'
1211+ setf murphi
1212+ return
1213+ endif
12031214 let n = n + 1
12041215 endwhile
1205- if exists (" g:filetype_m" )
1216+
1217+ if saw_comment
1218+ " We didn't see anything definitive, but this looks like either Objective C
1219+ " or Murphi based on the comment leader. Assume the former as it is more
1220+ " common.
1221+ setf objc
1222+ elseif exists (" g:filetype_m" )
1223+ " Use user specified default filetype for .m
12061224 exe " setf " . g: filetype_m
12071225 else
1226+ " Default is matlab
12081227 setf matlab
12091228 endif
12101229endfunc
@@ -2777,12 +2796,12 @@ runtime! ftdetect/*.vim
27772796" state.
27782797augroup END
27792798
2780- " Generic configuration file (check this last , it's just guessing!)
2799+ " Generic configuration file. Use FALLBACK , it's just guessing!
27812800au filetypedetect BufNewFile,BufRead,StdinReadPost *
27822801 \ if ! did_filetype () && expand (" <amatch>" ) !~ g: ft_ignore_pat
27832802 \ && (getline (1 ) = ~ ' ^#' || getline (2 ) = ~ ' ^#' || getline (3 ) = ~ ' ^#'
27842803 \ || getline (4 ) = ~ ' ^#' || getline (5 ) = ~ ' ^#' ) |
2785- \ setf conf |
2804+ \ setf FALLBACK conf |
27862805 \ endif
27872806
27882807
0 commit comments