comparison runtime/filetype.vim @ 11459:561b76ed9d12 v8.0.0613

patch 8.0.0613: the conf filetype is used before ftdetect from packages commit https://github.com/vim/vim/commit/3e54569b17683318e0cb6693ab0024c2ad1e3e8f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 4 19:00:32 2017 +0200 patch 8.0.0613: the conf filetype is used before ftdetect from packages Problem: The conf filetype detection is done before ftdetect scripts from packages that are added later. Solution: Add the FALLBACK argument to :setfiletype. (closes #1679, closes #1693)
author Christian Brabandt <cb@256bit.org>
date Sun, 04 Jun 2017 19:15:03 +0200
parents d183d629509e
children 63b0b7b79b25
comparison
equal deleted inserted replaced
11458:8322abc9fced 11459:561b76ed9d12
1 " Vim support file to detect file types 1 " Vim support file to detect file types
2 " 2 "
3 " Maintainer: Bram Moolenaar <Bram@vim.org> 3 " Maintainer: Bram Moolenaar <Bram@vim.org>
4 " Last Change: 2017 May 27 4 " Last Change: 2017 Jun 04
5 5
6 " Listen very carefully, I will say this only once 6 " Listen very carefully, I will say this only once
7 if exists("did_load_filetypes") 7 if exists("did_load_filetypes")
8 finish 8 finish
9 endif 9 endif
1179 au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md setf markdown 1179 au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md setf markdown
1180 1180
1181 " Mason 1181 " Mason
1182 au BufNewFile,BufRead *.mason,*.mhtml,*.comp setf mason 1182 au BufNewFile,BufRead *.mason,*.mhtml,*.comp setf mason
1183 1183
1184 " Matlab or Objective C 1184 " Mathematica, Matlab, Murphi or Objective C
1185 au BufNewFile,BufRead *.m call s:FTm() 1185 au BufNewFile,BufRead *.m call s:FTm()
1186 1186
1187 func! s:FTm() 1187 func! s:FTm()
1188 let n = 1 1188 let n = 1
1189 while n < 10 1189 let saw_comment = 0 " Whether we've seen a multiline comment leader.
1190 while n < 100
1190 let line = getline(n) 1191 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\>\|//\)'
1192 setf objc 1199 setf objc
1193 return 1200 return
1194 endif 1201 endif
1195 if line =~ '^\s*%' 1202 if line =~ '^\s*%'
1196 setf matlab 1203 setf matlab
1198 endif 1205 endif
1199 if line =~ '^\s*(\*' 1206 if line =~ '^\s*(\*'
1200 setf mma 1207 setf mma
1201 return 1208 return
1202 endif 1209 endif
1210 if line =~ '^\c\s*\(\(type\|var\)\>\|--\)'
1211 setf murphi
1212 return
1213 endif
1203 let n = n + 1 1214 let n = n + 1
1204 endwhile 1215 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
1206 exe "setf " . g:filetype_m 1224 exe "setf " . g:filetype_m
1207 else 1225 else
1226 " Default is matlab
1208 setf matlab 1227 setf matlab
1209 endif 1228 endif
1210 endfunc 1229 endfunc
1211 1230
1212 " Mathematica notebook 1231 " Mathematica notebook
2775 " NOTE: The above command could have ended the filetypedetect autocmd group 2794 " NOTE: The above command could have ended the filetypedetect autocmd group
2776 " and started another one. Let's make sure it has ended to get to a consistent 2795 " and started another one. Let's make sure it has ended to get to a consistent
2777 " state. 2796 " state.
2778 augroup END 2797 augroup END
2779 2798
2780 " Generic configuration file (check this last, it's just guessing!) 2799 " Generic configuration file. Use FALLBACK, it's just guessing!
2781 au filetypedetect BufNewFile,BufRead,StdinReadPost * 2800 au filetypedetect BufNewFile,BufRead,StdinReadPost *
2782 \ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat 2801 \ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2783 \ && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#' 2802 \ && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
2784 \ || getline(4) =~ '^#' || getline(5) =~ '^#') | 2803 \ || getline(4) =~ '^#' || getline(5) =~ '^#') |
2785 \ setf conf | 2804 \ setf FALLBACK conf |
2786 \ endif 2805 \ endif
2787 2806
2788 2807
2789 " If the GUI is already running, may still need to install the Syntax menu. 2808 " If the GUI is already running, may still need to install the Syntax menu.
2790 " Don't do it when the 'M' flag is included in 'guioptions'. 2809 " Don't do it when the 'M' flag is included in 'guioptions'.