xref: /vim-8.2.3635/runtime/filetype.vim (revision 6be7f873)
1" Vim support file to detect file types
2"
3" Maintainer:	Bram Moolenaar <[email protected]>
4" Last Change:	2012 Jan 04
5
6" Listen very carefully, I will say this only once
7if exists("did_load_filetypes")
8  finish
9endif
10let did_load_filetypes = 1
11
12" Line continuation is used here, remove 'C' from 'cpoptions'
13let s:cpo_save = &cpo
14set cpo&vim
15
16augroup filetypedetect
17
18" Ignored extensions
19if exists("*fnameescape")
20au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.dpkg-dist,?\+.dpkg-old,?\+.rpmsave,?\+.rpmnew
21	\ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r"))
22au BufNewFile,BufRead *~
23	\ let s:name = expand("<afile>") |
24	\ let s:short = substitute(s:name, '\~$', '', '') |
25	\ if s:name != s:short && s:short != "" |
26	\   exe "doau filetypedetect BufRead " . fnameescape(s:short) |
27	\ endif |
28	\ unlet! s:name s:short
29au BufNewFile,BufRead ?\+.in
30	\ if expand("<afile>:t") != "configure.in" |
31	\   exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r")) |
32	\ endif
33elseif &verbose > 0
34  echomsg "Warning: some filetypes will not be recognized because this version of Vim does not have fnameescape()"
35endif
36
37" Pattern used to match file names which should not be inspected.
38" Currently finds compressed files.
39if !exists("g:ft_ignore_pat")
40  let g:ft_ignore_pat = '\.\(Z\|gz\|bz2\|zip\|tgz\)$'
41endif
42
43" Function used for patterns that end in a star: don't set the filetype if the
44" file name matches ft_ignore_pat.
45func! s:StarSetf(ft)
46  if expand("<amatch>") !~ g:ft_ignore_pat
47    exe 'setf ' . a:ft
48  endif
49endfunc
50
51" Abaqus or Trasys
52au BufNewFile,BufRead *.inp			call s:Check_inp()
53
54func! s:Check_inp()
55  if getline(1) =~ '^\*'
56    setf abaqus
57  else
58    let n = 1
59    if line("$") > 500
60      let nmax = 500
61    else
62      let nmax = line("$")
63    endif
64    while n <= nmax
65      if getline(n) =~? "^header surface data"
66	setf trasys
67	break
68      endif
69      let n = n + 1
70    endwhile
71  endif
72endfunc
73
74" A-A-P recipe
75au BufNewFile,BufRead *.aap			setf aap
76
77" A2ps printing utility
78au BufNewFile,BufRead */etc/a2ps.cfg,*/etc/a2ps/*.cfg,a2psrc,.a2psrc setf a2ps
79
80" ABAB/4
81au BufNewFile,BufRead *.abap			setf abap
82
83" ABC music notation
84au BufNewFile,BufRead *.abc			setf abc
85
86" ABEL
87au BufNewFile,BufRead *.abl			setf abel
88
89" AceDB
90au BufNewFile,BufRead *.wrm			setf acedb
91
92" Ada (83, 9X, 95)
93au BufNewFile,BufRead *.adb,*.ads,*.ada		setf ada
94if has("vms")
95  au BufNewFile,BufRead *.gpr,*.ada_m,*.adc	setf ada
96else
97  au BufNewFile,BufRead *.gpr			setf ada
98endif
99
100" AHDL
101au BufNewFile,BufRead *.tdf			setf ahdl
102
103" AMPL
104au BufNewFile,BufRead *.run			setf ampl
105
106" Ant
107au BufNewFile,BufRead build.xml			setf ant
108
109" Apache style config file
110au BufNewFile,BufRead proftpd.conf*		call s:StarSetf('apachestyle')
111
112" Apache config file
113au BufNewFile,BufRead .htaccess,*/etc/httpd/*.conf		setf apache
114
115" XA65 MOS6510 cross assembler
116au BufNewFile,BufRead *.a65			setf a65
117
118" Applescript
119au BufNewFile,BufRead *.scpt			setf applescript
120
121" Applix ELF
122au BufNewFile,BufRead *.am
123	\ if expand("<afile>") !~? 'Makefile.am\>' | setf elf | endif
124
125" ALSA configuration
126au BufNewFile,BufRead .asoundrc,*/usr/share/alsa/alsa.conf,*/etc/asound.conf setf alsaconf
127
128" Arc Macro Language
129au BufNewFile,BufRead *.aml			setf aml
130
131" Arch Inventory file
132au BufNewFile,BufRead .arch-inventory,=tagging-method	setf arch
133
134" ART*Enterprise (formerly ART-IM)
135au BufNewFile,BufRead *.art			setf art
136
137" ASN.1
138au BufNewFile,BufRead *.asn,*.asn1		setf asn
139
140" Active Server Pages (with Visual Basic Script)
141au BufNewFile,BufRead *.asa
142	\ if exists("g:filetype_asa") |
143	\   exe "setf " . g:filetype_asa |
144	\ else |
145	\   setf aspvbs |
146	\ endif
147
148" Active Server Pages (with Perl or Visual Basic Script)
149au BufNewFile,BufRead *.asp
150	\ if exists("g:filetype_asp") |
151	\   exe "setf " . g:filetype_asp |
152	\ elseif getline(1) . getline(2) . getline(3) =~? "perlscript" |
153	\   setf aspperl |
154	\ else |
155	\   setf aspvbs |
156	\ endif
157
158" Grub (must be before catch *.lst)
159au BufNewFile,BufRead */boot/grub/menu.lst,*/boot/grub/grub.conf,*/etc/grub.conf setf grub
160
161" Assembly (all kinds)
162" *.lst is not pure assembly, it has two extra columns (address, byte codes)
163au BufNewFile,BufRead *.asm,*.[sS],*.[aA],*.mac,*.lst	call s:FTasm()
164
165" This function checks for the kind of assembly that is wanted by the user, or
166" can be detected from the first five lines of the file.
167func! s:FTasm()
168  " make sure b:asmsyntax exists
169  if !exists("b:asmsyntax")
170    let b:asmsyntax = ""
171  endif
172
173  if b:asmsyntax == ""
174    call s:FTasmsyntax()
175  endif
176
177  " if b:asmsyntax still isn't set, default to asmsyntax or GNU
178  if b:asmsyntax == ""
179    if exists("g:asmsyntax")
180      let b:asmsyntax = g:asmsyntax
181    else
182      let b:asmsyntax = "asm"
183    endif
184  endif
185
186  exe "setf " . fnameescape(b:asmsyntax)
187endfunc
188
189func! s:FTasmsyntax()
190  " see if file contains any asmsyntax=foo overrides. If so, change
191  " b:asmsyntax appropriately
192  let head = " ".getline(1)." ".getline(2)." ".getline(3)." ".getline(4).
193	\" ".getline(5)." "
194  let match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s')
195  if match != ''
196    let b:asmsyntax = match
197  elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library'))
198    let b:asmsyntax = "vmasm"
199  endif
200endfunc
201
202" Macro (VAX)
203au BufNewFile,BufRead *.mar			setf vmasm
204
205" Atlas
206au BufNewFile,BufRead *.atl,*.as		setf atlas
207
208" Autoit v3
209au BufNewFile,BufRead *.au3			setf autoit
210
211" Autohotkey
212au BufNewFile,BufRead *.ahk			setf autohotkey
213
214" Automake
215au BufNewFile,BufRead [mM]akefile.am,GNUmakefile.am	setf automake
216
217" Autotest .at files are actually m4
218au BufNewFile,BufRead *.at			setf m4
219
220" Avenue
221au BufNewFile,BufRead *.ave			setf ave
222
223" Awk
224au BufNewFile,BufRead *.awk			setf awk
225
226" B
227au BufNewFile,BufRead *.mch,*.ref,*.imp		setf b
228
229" BASIC or Visual Basic
230au BufNewFile,BufRead *.bas			call s:FTVB("basic")
231
232" Check if one of the first five lines contains "VB_Name".  In that case it is
233" probably a Visual Basic file.  Otherwise it's assumed to be "alt" filetype.
234func! s:FTVB(alt)
235  if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'VB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)'
236    setf vb
237  else
238    exe "setf " . a:alt
239  endif
240endfunc
241
242" Visual Basic Script (close to Visual Basic)
243au BufNewFile,BufRead *.vbs,*.dsm,*.ctl		setf vb
244
245" IBasic file (similar to QBasic)
246au BufNewFile,BufRead *.iba,*.ibi		setf ibasic
247
248" FreeBasic file (similar to QBasic)
249au BufNewFile,BufRead *.fb,*.bi			setf freebasic
250
251" Batch file for MSDOS.
252au BufNewFile,BufRead *.bat,*.sys		setf dosbatch
253" *.cmd is close to a Batch file, but on OS/2 Rexx files also use *.cmd.
254au BufNewFile,BufRead *.cmd
255	\ if getline(1) =~ '^/\*' | setf rexx | else | setf dosbatch | endif
256
257" Batch file for 4DOS
258au BufNewFile,BufRead *.btm			call s:FTbtm()
259func! s:FTbtm()
260  if exists("g:dosbatch_syntax_for_btm") && g:dosbatch_syntax_for_btm
261    setf dosbatch
262  else
263    setf btm
264  endif
265endfunc
266
267" BC calculator
268au BufNewFile,BufRead *.bc			setf bc
269
270" BDF font
271au BufNewFile,BufRead *.bdf			setf bdf
272
273" BibTeX bibliography database file
274au BufNewFile,BufRead *.bib			setf bib
275
276" BibTeX Bibliography Style
277au BufNewFile,BufRead *.bst			setf bst
278
279" BIND configuration
280au BufNewFile,BufRead named.conf,rndc.conf	setf named
281
282" BIND zone
283au BufNewFile,BufRead named.root		setf bindzone
284au BufNewFile,BufRead *.db			call s:BindzoneCheck('')
285
286func! s:BindzoneCheck(default)
287  if getline(1).getline(2).getline(3).getline(4) =~ '^; <<>> DiG [0-9.]\+ <<>>\|BIND.*named\|$ORIGIN\|$TTL\|IN\s\+SOA'
288    setf bindzone
289  elseif a:default != ''
290    exe 'setf ' . a:default
291  endif
292endfunc
293
294" Blank
295au BufNewFile,BufRead *.bl			setf blank
296
297" Blkid cache file
298au BufNewFile,BufRead */etc/blkid.tab,*/etc/blkid.tab.old   setf xml
299
300" C or lpc
301au BufNewFile,BufRead *.c			call s:FTlpc()
302
303func! s:FTlpc()
304  if exists("g:lpc_syntax_for_c")
305    let lnum = 1
306    while lnum <= 12
307      if getline(lnum) =~# '^\(//\|inherit\|private\|protected\|nosave\|string\|object\|mapping\|mixed\)'
308	setf lpc
309	return
310      endif
311      let lnum = lnum + 1
312    endwhile
313  endif
314  setf c
315endfunc
316
317" Calendar
318au BufNewFile,BufRead calendar			setf calendar
319
320" C#
321au BufNewFile,BufRead *.cs			setf cs
322
323" Cabal
324au BufNewFile,BufRead *.cabal			setf cabal
325
326" Cdrdao TOC
327au BufNewFile,BufRead *.toc			setf cdrtoc
328
329" Cdrdao config
330au BufNewFile,BufRead */etc/cdrdao.conf,*/etc/defaults/cdrdao,*/etc/default/cdrdao,.cdrdao	setf cdrdaoconf
331
332" Cfengine
333au BufNewFile,BufRead cfengine.conf		setf cfengine
334
335" ChaiScript
336au BufRead,BufNewFile *.chai			setf chaiscript
337
338" Comshare Dimension Definition Language
339au BufNewFile,BufRead *.cdl			setf cdl
340
341" Conary Recipe
342au BufNewFile,BufRead *.recipe			setf conaryrecipe
343
344" Controllable Regex Mutilator
345au BufNewFile,BufRead *.crm			setf crm
346
347" Cyn++
348au BufNewFile,BufRead *.cyn			setf cynpp
349
350" Cynlib
351" .cc and .cpp files can be C++ or Cynlib.
352au BufNewFile,BufRead *.cc
353	\ if exists("cynlib_syntax_for_cc")|setf cynlib|else|setf cpp|endif
354au BufNewFile,BufRead *.cpp
355	\ if exists("cynlib_syntax_for_cpp")|setf cynlib|else|setf cpp|endif
356
357" C++
358au BufNewFile,BufRead *.cxx,*.c++,*.hh,*.hxx,*.hpp,*.ipp,*.moc,*.tcc,*.inl setf cpp
359if has("fname_case")
360  au BufNewFile,BufRead *.C,*.H setf cpp
361endif
362
363" .h files can be C, Ch C++, ObjC or ObjC++.
364" Set c_syntax_for_h if you want C, ch_syntax_for_h if you want Ch. ObjC is
365" detected automatically.
366au BufNewFile,BufRead *.h			call s:FTheader()
367
368func! s:FTheader()
369  if match(getline(1, min([line("$"), 200])), '^@\(interface\|end\|class\)') > -1
370    setf objc
371  elseif exists("g:c_syntax_for_h")
372    setf c
373  elseif exists("g:ch_syntax_for_h")
374    setf ch
375  else
376    setf cpp
377  endif
378endfunc
379
380" Ch (CHscript)
381au BufNewFile,BufRead *.chf			setf ch
382
383" TLH files are C++ headers generated by Visual C++'s #import from typelibs
384au BufNewFile,BufRead *.tlh			setf cpp
385
386" Cascading Style Sheets
387au BufNewFile,BufRead *.css			setf css
388
389" Century Term Command Scripts (*.cmd too)
390au BufNewFile,BufRead *.con			setf cterm
391
392" Changelog
393au BufNewFile,BufRead changelog.Debian,changelog.dch,NEWS.Debian,NEWS.dch
394					\	setf debchangelog
395
396au BufNewFile,BufRead [cC]hange[lL]og
397	\  if getline(1) =~ '; urgency='
398	\|   setf debchangelog
399	\| else
400	\|   setf changelog
401	\| endif
402
403au BufNewFile,BufRead NEWS
404	\  if getline(1) =~ '; urgency='
405	\|   setf debchangelog
406	\| endif
407
408" CHILL
409au BufNewFile,BufRead *..ch			setf chill
410
411" Changes for WEB and CWEB or CHILL
412au BufNewFile,BufRead *.ch			call s:FTchange()
413
414" This function checks if one of the first ten lines start with a '@'.  In
415" that case it is probably a change file.
416" If the first line starts with # or ! it's probably a ch file.
417" If a line has "main", "include", "//" ir "/*" it's probably ch.
418" Otherwise CHILL is assumed.
419func! s:FTchange()
420  let lnum = 1
421  while lnum <= 10
422    if getline(lnum)[0] == '@'
423      setf change
424      return
425    endif
426    if lnum == 1 && (getline(1)[0] == '#' || getline(1)[0] == '!')
427      setf ch
428      return
429    endif
430    if getline(lnum) =~ "MODULE"
431      setf chill
432      return
433    endif
434    if getline(lnum) =~ 'main\s*(\|#\s*include\|//'
435      setf ch
436      return
437    endif
438    let lnum = lnum + 1
439  endwhile
440  setf chill
441endfunc
442
443" ChordPro
444au BufNewFile,BufRead *.chopro,*.crd,*.cho,*.crdpro,*.chordpro	setf chordpro
445
446" Clean
447au BufNewFile,BufRead *.dcl,*.icl		setf clean
448
449" Clever
450au BufNewFile,BufRead *.eni			setf cl
451
452" Clever or dtd
453au BufNewFile,BufRead *.ent			call s:FTent()
454
455func! s:FTent()
456  " This function checks for valid cl syntax in the first five lines.
457  " Look for either an opening comment, '#', or a block start, '{".
458  " If not found, assume SGML.
459  let lnum = 1
460  while lnum < 6
461    let line = getline(lnum)
462    if line =~ '^\s*[#{]'
463      setf cl
464      return
465    elseif line !~ '^\s*$'
466      " Not a blank line, not a comment, and not a block start,
467      " so doesn't look like valid cl code.
468      break
469    endif
470    let lnum = lnum + 1
471  endw
472  setf dtd
473endfunc
474
475" Clipper (or FoxPro; could also be eviews)
476au BufNewFile,BufRead *.prg
477	\ if exists("g:filetype_prg") |
478	\   exe "setf " . g:filetype_prg |
479	\ else |
480	\   setf clipper |
481	\ endif
482
483" Cmake
484au BufNewFile,BufRead CMakeLists.txt,*.cmake,*.cmake.in		setf cmake
485
486" Cmusrc
487au BufNewFile,BufRead */.cmus/{autosave,rc,command-history,*.theme} setf cmusrc
488au BufNewFile,BufRead */cmus/{rc,*.theme}			setf cmusrc
489
490" Cobol
491au BufNewFile,BufRead *.cbl,*.cob,*.lib	setf cobol
492"   cobol or zope form controller python script? (heuristic)
493au BufNewFile,BufRead *.cpy
494	\ if getline(1) =~ '^##' |
495	\   setf python |
496	\ else |
497	\   setf cobol |
498	\ endif
499
500" Coco/R
501au BufNewFile,BufRead *.atg			setf coco
502
503" Cold Fusion
504au BufNewFile,BufRead *.cfm,*.cfi,*.cfc		setf cf
505
506" Configure scripts
507au BufNewFile,BufRead configure.in,configure.ac setf config
508
509" CUDA  Cumpute Unified Device Architecture
510au BufNewFile,BufRead *.cu			setf cuda
511
512" WildPackets EtherPeek Decoder
513au BufNewFile,BufRead *.dcd			setf dcd
514
515" Enlightenment configuration files
516au BufNewFile,BufRead *enlightenment/*.cfg	setf c
517
518" Eterm
519au BufNewFile,BufRead *Eterm/*.cfg		setf eterm
520
521" Lynx config files
522au BufNewFile,BufRead lynx.cfg			setf lynx
523
524" Quake
525au BufNewFile,BufRead *baseq[2-3]/*.cfg,*id1/*.cfg	setf quake
526au BufNewFile,BufRead *quake[1-3]/*.cfg			setf quake
527
528" Quake C
529au BufNewFile,BufRead *.qc			setf c
530
531" Configure files
532au BufNewFile,BufRead *.cfg			setf cfg
533
534" Cucumber
535au BufNewFile,BufRead *.feature			setf cucumber
536
537" Communicating Sequential Processes
538au BufNewFile,BufRead *.csp,*.fdr		setf csp
539
540" CUPL logic description and simulation
541au BufNewFile,BufRead *.pld			setf cupl
542au BufNewFile,BufRead *.si			setf cuplsim
543
544" Debian Control
545au BufNewFile,BufRead */debian/control		setf debcontrol
546au BufNewFile,BufRead control
547	\  if getline(1) =~ '^Source:'
548	\|   setf debcontrol
549	\| endif
550
551" Debian Sources.list
552au BufNewFile,BufRead */etc/apt/sources.list		setf debsources
553au BufNewFile,BufRead */etc/apt/sources.list.d/*.list	setf debsources
554
555" Deny hosts
556au BufNewFile,BufRead denyhosts.conf		setf denyhosts
557
558" dnsmasq(8) configuration files
559au BufNewFile,BufRead */etc/dnsmasq.conf	setf dnsmasq
560
561" ROCKLinux package description
562au BufNewFile,BufRead *.desc			setf desc
563
564" the D language or dtrace
565au BufNewFile,BufRead *.d			call s:DtraceCheck()
566
567func! s:DtraceCheck()
568  let lines = getline(1, min([line("$"), 100]))
569  if match(lines, '^module\>\|^import\>') > -1
570    " D files often start with a module and/or import statement.
571    setf d
572  elseif match(lines, '^#!\S\+dtrace\|#pragma\s\+D\s\+option\|:\S\{-}:\S\{-}:') > -1
573    setf dtrace
574  else
575    setf d
576  endif
577endfunc
578
579" Desktop files
580au BufNewFile,BufRead *.desktop,.directory	setf desktop
581
582" Dict config
583au BufNewFile,BufRead dict.conf,.dictrc		setf dictconf
584
585" Dictd config
586au BufNewFile,BufRead dictd.conf		setf dictdconf
587
588" Diff files
589au BufNewFile,BufRead *.diff,*.rej,*.patch	setf diff
590
591" Dircolors
592au BufNewFile,BufRead .dir_colors,.dircolors,*/etc/DIR_COLORS	setf dircolors
593
594" Diva (with Skill) or InstallShield
595au BufNewFile,BufRead *.rul
596	\ if getline(1).getline(2).getline(3).getline(4).getline(5).getline(6) =~? 'InstallShield' |
597	\   setf ishd |
598	\ else |
599	\   setf diva |
600	\ endif
601
602" DCL (Digital Command Language - vms) or DNS zone file
603au BufNewFile,BufRead *.com			call s:BindzoneCheck('dcl')
604
605" DOT
606au BufNewFile,BufRead *.dot			setf dot
607
608" Dylan - lid files
609au BufNewFile,BufRead *.lid			setf dylanlid
610
611" Dylan - intr files (melange)
612au BufNewFile,BufRead *.intr			setf dylanintr
613
614" Dylan
615au BufNewFile,BufRead *.dylan			setf dylan
616
617" Microsoft Module Definition
618au BufNewFile,BufRead *.def			setf def
619
620" Dracula
621au BufNewFile,BufRead *.drac,*.drc,*lvs,*lpe	setf dracula
622
623" Datascript
624au BufNewFile,BufRead *.ds			setf datascript
625
626" dsl
627au BufNewFile,BufRead *.dsl			setf dsl
628
629" DTD (Document Type Definition for XML)
630au BufNewFile,BufRead *.dtd			setf dtd
631
632" EDIF (*.edf,*.edif,*.edn,*.edo)
633au BufNewFile,BufRead *.ed\(f\|if\|n\|o\)	setf edif
634
635" Embedix Component Description
636au BufNewFile,BufRead *.ecd			setf ecd
637
638" Eiffel or Specman
639au BufNewFile,BufRead *.e,*.E			call s:FTe()
640
641" Elinks configuration
642au BufNewFile,BufRead */etc/elinks.conf,*/.elinks/elinks.conf	setf elinks
643
644func! s:FTe()
645  let n = 1
646  while n < 100 && n < line("$")
647    if getline(n) =~ "^\\s*\\(<'\\|'>\\)\\s*$"
648      setf specman
649      return
650    endif
651    let n = n + 1
652  endwhile
653  setf eiffel
654endfunc
655
656" ERicsson LANGuage; Yaws is erlang too
657au BufNewFile,BufRead *.erl,*.hrl,*.yaws	setf erlang
658
659" Elm Filter Rules file
660au BufNewFile,BufRead filter-rules		setf elmfilt
661
662" ESMTP rc file
663au BufNewFile,BufRead *esmtprc			setf esmtprc
664
665" ESQL-C
666au BufNewFile,BufRead *.ec,*.EC			setf esqlc
667
668" Esterel
669au BufNewFile,BufRead *.strl			setf esterel
670
671" Essbase script
672au BufNewFile,BufRead *.csc			setf csc
673
674" Exim
675au BufNewFile,BufRead exim.conf			setf exim
676
677" Expect
678au BufNewFile,BufRead *.exp			setf expect
679
680" Exports
681au BufNewFile,BufRead exports			setf exports
682
683" Falcon
684au BufNewFile,BufRead *.fal			setf falcon
685
686" Fantom
687au BufNewFile,BufRead *.fan,*.fwt		setf fan
688
689" Factor
690au BufNewFile,BufRead *.factor			setf factor
691
692" Fetchmail RC file
693au BufNewFile,BufRead .fetchmailrc		setf fetchmail
694
695" FlexWiki - disabled, because it has side effects when a .wiki file
696" is not actually FlexWiki
697"au BufNewFile,BufRead *.wiki			setf flexwiki
698
699" Focus Executable
700au BufNewFile,BufRead *.fex,*.focexec		setf focexec
701
702" Focus Master file (but not for auto.master)
703au BufNewFile,BufRead auto.master		setf conf
704au BufNewFile,BufRead *.mas,*.master		setf master
705
706" Forth
707au BufNewFile,BufRead *.fs,*.ft			setf forth
708
709" Reva Forth
710au BufNewFile,BufRead *.frt			setf reva
711
712" Fortran
713if has("fname_case")
714  au BufNewFile,BufRead *.F,*.FOR,*.FPP,*.FTN,*.F77,*.F90,*.F95,*.F03,*.F08	 setf fortran
715endif
716au BufNewFile,BufRead   *.f,*.for,*.fortran,*.fpp,*.ftn,*.f77,*.f90,*.f95,*.f03,*.f08  setf fortran
717
718" Framescript
719au BufNewFile,BufRead *.fsl			setf framescript
720
721" FStab
722au BufNewFile,BufRead fstab,mtab		setf fstab
723
724" GDB command files
725au BufNewFile,BufRead .gdbinit			setf gdb
726
727" GDMO
728au BufNewFile,BufRead *.mo,*.gdmo		setf gdmo
729
730" Gedcom
731au BufNewFile,BufRead *.ged,lltxxxxx.txt	setf gedcom
732
733" Git
734au BufNewFile,BufRead *.git/COMMIT_EDITMSG setf gitcommit
735au BufNewFile,BufRead *.git/config,.gitconfig,.gitmodules setf gitconfig
736au BufNewFile,BufRead git-rebase-todo      setf gitrebase
737au BufNewFile,BufRead .msg.[0-9]*
738      \ if getline(1) =~ '^From.*# This line is ignored.$' |
739      \   setf gitsendemail |
740      \ endif
741au BufNewFile,BufRead *.git/**
742      \ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
743      \   setf git |
744      \ endif
745
746" Gkrellmrc
747au BufNewFile,BufRead gkrellmrc,gkrellmrc_?	setf gkrellmrc
748
749" GP scripts (2.0 and onward)
750au BufNewFile,BufRead *.gp,.gprc		setf gp
751
752" GPG
753au BufNewFile,BufRead */.gnupg/options		setf gpg
754au BufNewFile,BufRead */.gnupg/gpg.conf		setf gpg
755au BufNewFile,BufRead */usr/**/gnupg/options.skel setf gpg
756
757" gnash(1) configuration files
758au BufNewFile,BufRead gnashrc,.gnashrc,gnashpluginrc,.gnashpluginrc setf gnash
759
760" Gitolite
761au BufNewFile,BufRead gitolite.conf		setf gitolite
762au BufNewFile,BufRead */gitolite-admin/conf/*	call s:StarSetf('gitolite')
763au BufNewFile,BufRead {,.}gitolite.rc,example.gitolite.rc 	setf perl
764
765" Gnuplot scripts
766au BufNewFile,BufRead *.gpi			setf gnuplot
767
768" GrADS scripts
769au BufNewFile,BufRead *.gs			setf grads
770
771" Gretl
772au BufNewFile,BufRead *.gretl			setf gretl
773
774" Groovy
775au BufNewFile,BufRead *.groovy			setf groovy
776
777" GNU Server Pages
778au BufNewFile,BufRead *.gsp			setf gsp
779
780" Group file
781au BufNewFile,BufRead */etc/group,*/etc/group-,*/etc/group.edit,*/etc/gshadow,*/etc/gshadow-,*/etc/gshadow.edit,*/var/backups/group.bak,*/var/backups/gshadow.bak  setf group
782
783" GTK RC
784au BufNewFile,BufRead .gtkrc,gtkrc		setf gtkrc
785
786" Haml
787au BufNewFile,BufRead *.haml			setf haml
788
789" Hamster Classic | Playground files
790au BufNewFile,BufRead *.hsc,*.hsm		setf hamster
791
792" Haskell
793au BufNewFile,BufRead *.hs,*.hs-boot		setf haskell
794au BufNewFile,BufRead *.lhs			setf lhaskell
795au BufNewFile,BufRead *.chs			setf chaskell
796
797" Haste
798au BufNewFile,BufRead *.ht			setf haste
799au BufNewFile,BufRead *.htpp			setf hastepreproc
800
801" Hercules
802au BufNewFile,BufRead *.vc,*.ev,*.rs,*.sum,*.errsum	setf hercules
803
804" HEX (Intel)
805au BufNewFile,BufRead *.hex,*.h32		setf hex
806
807" Tilde (must be before HTML)
808au BufNewFile,BufRead *.t.html			setf tilde
809
810" HTML (.shtml and .stm for server side)
811au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm  call s:FThtml()
812
813" Distinguish between HTML, XHTML and Django
814func! s:FThtml()
815  let n = 1
816  while n < 10 && n < line("$")
817    if getline(n) =~ '\<DTD\s\+XHTML\s'
818      setf xhtml
819      return
820    endif
821    if getline(n) =~ '{%\s*\(extends\|block\)\>'
822      setf htmldjango
823      return
824    endif
825    let n = n + 1
826  endwhile
827  setf html
828endfunc
829
830" HTML with Ruby - eRuby
831au BufNewFile,BufRead *.erb,*.rhtml		setf eruby
832
833" HTML with M4
834au BufNewFile,BufRead *.html.m4			setf htmlm4
835
836" HTML Cheetah template
837au BufNewFile,BufRead *.tmpl			setf htmlcheetah
838
839" Host config
840au BufNewFile,BufRead */etc/host.conf		setf hostconf
841
842" Hosts access
843au BufNewFile,BufRead */etc/hosts.allow,*/etc/hosts.deny  setf hostsaccess
844
845" Hyper Builder
846au BufNewFile,BufRead *.hb			setf hb
847
848" Icon
849au BufNewFile,BufRead *.icn			setf icon
850
851" IDL (Interface Description Language)
852au BufNewFile,BufRead *.idl			call s:FTidl()
853
854" Distinguish between standard IDL and MS-IDL
855func! s:FTidl()
856  let n = 1
857  while n < 50 && n < line("$")
858    if getline(n) =~ '^\s*import\s\+"\(unknwn\|objidl\)\.idl"'
859      setf msidl
860      return
861    endif
862    let n = n + 1
863  endwhile
864  setf idl
865endfunc
866
867" Microsoft IDL (Interface Description Language)  Also *.idl
868" MOF = WMI (Windows Management Instrumentation) Managed Object Format
869au BufNewFile,BufRead *.odl,*.mof		setf msidl
870
871" Icewm menu
872au BufNewFile,BufRead */.icewm/menu		setf icemenu
873
874" Indent profile (must come before IDL *.pro!)
875au BufNewFile,BufRead .indent.pro		setf indent
876au BufNewFile,BufRead indent.pro		call s:ProtoCheck('indent')
877
878" IDL (Interactive Data Language)
879au BufNewFile,BufRead *.pro			call s:ProtoCheck('idlang')
880
881" Distinguish between "default" and Cproto prototype file. */
882func! s:ProtoCheck(default)
883  " Cproto files have a comment in the first line and a function prototype in
884  " the second line, it always ends in ";".  Indent files may also have
885  " comments, thus we can't match comments to see the difference.
886  " IDL files can have a single ';' in the second line, require at least one
887  " chacter before the ';'.
888  if getline(2) =~ '.;$'
889    setf cpp
890  else
891    exe 'setf ' . a:default
892  endif
893endfunc
894
895
896" Indent RC
897au BufNewFile,BufRead indentrc			setf indent
898
899" Inform
900au BufNewFile,BufRead *.inf,*.INF		setf inform
901
902" Initng
903au BufNewFile,BufRead */etc/initng/**/*.i,*.ii	setf initng
904
905" Ipfilter
906au BufNewFile,BufRead ipf.conf,ipf6.conf,ipf.rules	setf ipfilter
907
908" Informix 4GL (source - canonical, include file, I4GL+M4 preproc.)
909au BufNewFile,BufRead *.4gl,*.4gh,*.m4gl	setf fgl
910
911" .INI file for MSDOS
912au BufNewFile,BufRead *.ini			setf dosini
913
914" SysV Inittab
915au BufNewFile,BufRead inittab			setf inittab
916
917" Inno Setup
918au BufNewFile,BufRead *.iss			setf iss
919
920" JAL
921au BufNewFile,BufRead *.jal,*.JAL		setf jal
922
923" Jam
924au BufNewFile,BufRead *.jpl,*.jpr		setf jam
925
926" Java
927au BufNewFile,BufRead *.java,*.jav		setf java
928
929" JavaCC
930au BufNewFile,BufRead *.jj,*.jjt		setf javacc
931
932" JavaScript, ECMAScript
933au BufNewFile,BufRead *.js,*.javascript,*.es,*.jsx,*.json   setf javascript
934
935" Java Server Pages
936au BufNewFile,BufRead *.jsp			setf jsp
937
938" Java Properties resource file (note: doesn't catch font.properties.pl)
939au BufNewFile,BufRead *.properties,*.properties_??,*.properties_??_??	setf jproperties
940au BufNewFile,BufRead *.properties_??_??_*	call s:StarSetf('jproperties')
941
942" Jess
943au BufNewFile,BufRead *.clp			setf jess
944
945" Jgraph
946au BufNewFile,BufRead *.jgr			setf jgraph
947
948" Jovial
949au BufNewFile,BufRead *.jov,*.j73,*.jovial	setf jovial
950
951" Kixtart
952au BufNewFile,BufRead *.kix			setf kix
953
954" Kimwitu[++]
955au BufNewFile,BufRead *.k			setf kwt
956
957" KDE script
958au BufNewFile,BufRead *.ks			setf kscript
959
960" Kconfig
961au BufNewFile,BufRead Kconfig,Kconfig.debug	setf kconfig
962
963" Lace (ISE)
964au BufNewFile,BufRead *.ace,*.ACE		setf lace
965
966" Latte
967au BufNewFile,BufRead *.latte,*.lte		setf latte
968
969" Limits
970au BufNewFile,BufRead */etc/limits,*/etc/*limits.conf,*/etc/*limits.d/*.conf	setf limits
971
972" LambdaProlog (*.mod too, see Modsim)
973au BufNewFile,BufRead *.sig			setf lprolog
974
975" LDAP LDIF
976au BufNewFile,BufRead *.ldif			setf ldif
977
978" Ld loader
979au BufNewFile,BufRead *.ld			setf ld
980
981" Lex
982au BufNewFile,BufRead *.lex,*.l			setf lex
983
984" Libao
985au BufNewFile,BufRead */etc/libao.conf,*/.libao	setf libao
986
987" Libsensors
988au BufNewFile,BufRead */etc/sensors.conf,*/etc/sensors3.conf	setf sensors
989
990" LFTP
991au BufNewFile,BufRead lftp.conf,.lftprc,*lftp/rc	setf lftp
992
993" Lifelines (or Lex for C++!)
994au BufNewFile,BufRead *.ll			setf lifelines
995
996" Lilo: Linux loader
997au BufNewFile,BufRead lilo.conf			setf lilo
998
999" Lisp (*.el = ELisp, *.cl = Common Lisp, *.jl = librep Lisp)
1000if has("fname_case")
1001  au BufNewFile,BufRead *.lsp,*.lisp,*.el,*.cl,*.jl,*.L,.emacs,.sawfishrc setf lisp
1002else
1003  au BufNewFile,BufRead *.lsp,*.lisp,*.el,*.cl,*.jl,.emacs,.sawfishrc setf lisp
1004endif
1005
1006" SBCL implementation of Common Lisp
1007au BufNewFile,BufRead sbclrc,.sbclrc		setf lisp
1008
1009" Liquid
1010au BufNewFile,BufRead *.liquid			setf liquid
1011
1012" Lite
1013au BufNewFile,BufRead *.lite,*.lt		setf lite
1014
1015" LiteStep RC files
1016au BufNewFile,BufRead */LiteStep/*/*.rc		setf litestep
1017
1018" Login access
1019au BufNewFile,BufRead */etc/login.access	setf loginaccess
1020
1021" Login defs
1022au BufNewFile,BufRead */etc/login.defs		setf logindefs
1023
1024" Logtalk
1025au BufNewFile,BufRead *.lgt			setf logtalk
1026
1027" LOTOS
1028au BufNewFile,BufRead *.lot,*.lotos		setf lotos
1029
1030" Lout (also: *.lt)
1031au BufNewFile,BufRead *.lou,*.lout		setf lout
1032
1033" Lua
1034au BufNewFile,BufRead *.lua			setf lua
1035
1036" Linden Scripting Language (Second Life)
1037au BufNewFile,BufRead *.lsl			setf lsl
1038
1039" Lynx style file (or LotusScript!)
1040au BufNewFile,BufRead *.lss			setf lss
1041
1042" M4
1043au BufNewFile,BufRead *.m4
1044	\ if expand("<afile>") !~? 'html.m4$\|fvwm2rc' | setf m4 | endif
1045
1046" MaGic Point
1047au BufNewFile,BufRead *.mgp			setf mgp
1048
1049" Mail (for Elm, trn, mutt, muttng, rn, slrn)
1050au BufNewFile,BufRead snd.\d\+,.letter,.letter.\d\+,.followup,.article,.article.\d\+,pico.\d\+,mutt{ng,}-*-\w\+,mutt[[:alnum:]_-]\{6\},ae\d\+.txt,/tmp/SLRN[0-9A-Z.]\+,*.eml setf mail
1051
1052" Mail aliases
1053au BufNewFile,BufRead */etc/mail/aliases,*/etc/aliases	setf mailaliases
1054
1055" Mailcap configuration file
1056au BufNewFile,BufRead .mailcap,mailcap		setf mailcap
1057
1058" Makefile
1059au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak,*.dsp setf make
1060
1061" MakeIndex
1062au BufNewFile,BufRead *.ist,*.mst		setf ist
1063
1064" Manpage
1065au BufNewFile,BufRead *.man			setf man
1066
1067" Man config
1068au BufNewFile,BufRead */etc/man.conf,man.config	setf manconf
1069
1070" Maple V
1071au BufNewFile,BufRead *.mv,*.mpl,*.mws		setf maple
1072
1073" Map (UMN mapserver config file)
1074au BufNewFile,BufRead *.map			setf map
1075
1076" Markdown
1077au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,README.md  setf markdown
1078
1079" Mason
1080au BufNewFile,BufRead *.mason,*.mhtml		setf mason
1081
1082" Matlab or Objective C
1083au BufNewFile,BufRead *.m			call s:FTm()
1084
1085func! s:FTm()
1086  let n = 1
1087  while n < 10
1088    let line = getline(n)
1089    if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\|//\)'
1090      setf objc
1091      return
1092    endif
1093    if line =~ '^\s*%'
1094      setf matlab
1095      return
1096    endif
1097    if line =~ '^\s*(\*'
1098      setf mma
1099      return
1100    endif
1101    let n = n + 1
1102  endwhile
1103  if exists("g:filetype_m")
1104    exe "setf " . g:filetype_m
1105  else
1106    setf matlab
1107  endif
1108endfunc
1109
1110" Mathematica notebook
1111au BufNewFile,BufRead *.nb			setf mma
1112
1113" Maya Extension Language
1114au BufNewFile,BufRead *.mel			setf mel
1115
1116" Mercurial config (looks like generic config file)
1117au BufNewFile,BufRead *.hgrc,*hgrc		setf cfg
1118
1119" Messages (logs mostly)
1120au BufNewFile,BufRead */log/{auth,cron,daemon,debug,kern,lpr,mail,messages,news/news,syslog,user}{,.log,.err,.info,.warn,.crit,.notice}{,.[0-9]*,-[0-9]*} setf messages
1121
1122" Metafont
1123au BufNewFile,BufRead *.mf			setf mf
1124
1125" MetaPost
1126au BufNewFile,BufRead *.mp			setf mp
1127
1128" MGL
1129au BufNewFile,BufRead *.mgl			setf mgl
1130
1131" MMIX or VMS makefile
1132au BufNewFile,BufRead *.mms			call s:FTmms()
1133
1134" Symbian meta-makefile definition (MMP)
1135au BufNewFile,BufRead *.mmp			setf mmp
1136
1137func! s:FTmms()
1138  let n = 1
1139  while n < 10
1140    let line = getline(n)
1141    if line =~ '^\s*\(%\|//\)' || line =~ '^\*'
1142      setf mmix
1143      return
1144    endif
1145    if line =~ '^\s*#'
1146      setf make
1147      return
1148    endif
1149    let n = n + 1
1150  endwhile
1151  setf mmix
1152endfunc
1153
1154
1155" Modsim III (or LambdaProlog)
1156au BufNewFile,BufRead *.mod
1157	\ if getline(1) =~ '\<module\>' |
1158	\   setf lprolog |
1159	\ else |
1160	\   setf modsim3 |
1161	\ endif
1162
1163" Modula 2
1164au BufNewFile,BufRead *.m2,*.DEF,*.MOD,*.md,*.mi setf modula2
1165
1166" Modula 3 (.m3, .i3, .mg, .ig)
1167au BufNewFile,BufRead *.[mi][3g]		setf modula3
1168
1169" Monk
1170au BufNewFile,BufRead *.isc,*.monk,*.ssc,*.tsc	setf monk
1171
1172" MOO
1173au BufNewFile,BufRead *.moo			setf moo
1174
1175" Modconf
1176au BufNewFile,BufRead */etc/modules.conf,*/etc/modules,*/etc/conf.modules setf modconf
1177
1178" Mplayer config
1179au BufNewFile,BufRead mplayer.conf,*/.mplayer/config	setf mplayerconf
1180
1181" Moterola S record
1182au BufNewFile,BufRead *.s19,*.s28,*.s37		setf srec
1183
1184" Mrxvtrc
1185au BufNewFile,BufRead mrxvtrc,.mrxvtrc		setf mrxvtrc
1186
1187" Msql
1188au BufNewFile,BufRead *.msql			setf msql
1189
1190" Mysql
1191au BufNewFile,BufRead *.mysql			setf mysql
1192
1193" Mutt setup files (must be before catch *.rc)
1194au BufNewFile,BufRead */etc/Muttrc.d/*		call s:StarSetf('muttrc')
1195
1196" M$ Resource files
1197au BufNewFile,BufRead *.rc			setf rc
1198
1199" MuPAD source
1200au BufRead,BufNewFile *.mu			setf mupad
1201
1202" Mush
1203au BufNewFile,BufRead *.mush			setf mush
1204
1205" Mutt setup file (also for Muttng)
1206au BufNewFile,BufRead Mutt{ng,}rc		setf muttrc
1207
1208" Nano
1209au BufNewFile,BufRead */etc/nanorc,.nanorc	setf nanorc
1210
1211" Nastran input/DMAP
1212"au BufNewFile,BufRead *.dat			setf nastran
1213
1214" Natural
1215au BufNewFile,BufRead *.NS[ACGLMNPS]		setf natural
1216
1217" Netrc
1218au BufNewFile,BufRead .netrc			setf netrc
1219
1220" Ninja file
1221au BufNewFile,BufRead *.ninja			setf ninja
1222
1223" Novell netware batch files
1224au BufNewFile,BufRead *.ncf			setf ncf
1225
1226" Nroff/Troff (*.ms and *.t are checked below)
1227au BufNewFile,BufRead *.me
1228	\ if expand("<afile>") != "read.me" && expand("<afile>") != "click.me" |
1229	\   setf nroff |
1230	\ endif
1231au BufNewFile,BufRead *.tr,*.nr,*.roff,*.tmac,*.mom	setf nroff
1232au BufNewFile,BufRead *.[1-9]			call s:FTnroff()
1233
1234" This function checks if one of the first five lines start with a dot.  In
1235" that case it is probably an nroff file: 'filetype' is set and 1 is returned.
1236func! s:FTnroff()
1237  if getline(1)[0] . getline(2)[0] . getline(3)[0] . getline(4)[0] . getline(5)[0] =~ '\.'
1238    setf nroff
1239    return 1
1240  endif
1241  return 0
1242endfunc
1243
1244" Nroff or Objective C++
1245au BufNewFile,BufRead *.mm			call s:FTmm()
1246
1247func! s:FTmm()
1248  let n = 1
1249  while n < 10
1250    let line = getline(n)
1251    if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\)'
1252      setf objcpp
1253      return
1254    endif
1255    let n = n + 1
1256  endwhile
1257  setf nroff
1258endfunc
1259
1260" Not Quite C
1261au BufNewFile,BufRead *.nqc			setf nqc
1262
1263" NSIS
1264au BufNewFile,BufRead *.nsi			setf nsis
1265
1266" OCAML
1267au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly	setf ocaml
1268
1269" Occam
1270au BufNewFile,BufRead *.occ			setf occam
1271
1272" Omnimark
1273au BufNewFile,BufRead *.xom,*.xin		setf omnimark
1274
1275" OpenROAD
1276au BufNewFile,BufRead *.or			setf openroad
1277
1278" OPL
1279au BufNewFile,BufRead *.[Oo][Pp][Ll]		setf opl
1280
1281" Oracle config file
1282au BufNewFile,BufRead *.ora			setf ora
1283
1284" Packet filter conf
1285au BufNewFile,BufRead pf.conf			setf pf
1286
1287" Pam conf
1288au BufNewFile,BufRead */etc/pam.conf		setf pamconf
1289
1290" PApp
1291au BufNewFile,BufRead *.papp,*.pxml,*.pxsl	setf papp
1292
1293" Password file
1294au BufNewFile,BufRead */etc/passwd,*/etc/passwd-,*/etc/passwd.edit,*/etc/shadow,*/etc/shadow-,*/etc/shadow.edit,*/var/backups/passwd.bak,*/var/backups/shadow.bak setf passwd
1295
1296" Pascal (also *.p)
1297au BufNewFile,BufRead *.pas			setf pascal
1298
1299" Delphi project file
1300au BufNewFile,BufRead *.dpr			setf pascal
1301
1302" PDF
1303au BufNewFile,BufRead *.pdf			setf pdf
1304
1305" Perl
1306if has("fname_case")
1307  au BufNewFile,BufRead *.pl,*.PL		call s:FTpl()
1308else
1309  au BufNewFile,BufRead *.pl			call s:FTpl()
1310endif
1311au BufNewFile,BufRead *.plx,*.al		setf perl
1312au BufNewFile,BufRead *.p6,*.pm6		setf perl6
1313
1314func! s:FTpl()
1315  if exists("g:filetype_pl")
1316    exe "setf " . g:filetype_pl
1317  else
1318    " recognize Prolog by specific text in the first non-empty line
1319    " require a blank after the '%' because Perl uses "%list" and "%translate"
1320    let l = getline(nextnonblank(1))
1321    if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-'
1322      setf prolog
1323    else
1324      setf perl
1325    endif
1326  endif
1327endfunc
1328
1329" Perl, XPM or XPM2
1330au BufNewFile,BufRead *.pm
1331	\ if getline(1) =~ "XPM2" |
1332	\   setf xpm2 |
1333	\ elseif getline(1) =~ "XPM" |
1334	\   setf xpm |
1335	\ else |
1336	\   setf perl |
1337	\ endif
1338
1339" Perl POD
1340au BufNewFile,BufRead *.pod			setf pod
1341
1342" Php, php3, php4, etc.
1343" Also Phtml (was used for PHP 2 in the past)
1344" Also .ctp for Cake template file
1345au BufNewFile,BufRead *.php,*.php\d,*.phtml,*.ctp	setf php
1346
1347" Pike
1348au BufNewFile,BufRead *.pike,*.lpc,*.ulpc,*.pmod setf pike
1349
1350" Pinfo config
1351au BufNewFile,BufRead */etc/pinforc,*/.pinforc	setf pinfo
1352
1353" Palm Resource compiler
1354au BufNewFile,BufRead *.rcp			setf pilrc
1355
1356" Pine config
1357au BufNewFile,BufRead .pinerc,pinerc,.pinercex,pinercex		setf pine
1358
1359" PL/M (also: *.inp)
1360au BufNewFile,BufRead *.plm,*.p36,*.pac		setf plm
1361
1362" PL/SQL
1363au BufNewFile,BufRead *.pls,*.plsql		setf plsql
1364
1365" PLP
1366au BufNewFile,BufRead *.plp			setf plp
1367
1368" PO and PO template (GNU gettext)
1369au BufNewFile,BufRead *.po,*.pot		setf po
1370
1371" Postfix main config
1372au BufNewFile,BufRead main.cf			setf pfmain
1373
1374" PostScript (+ font files, encapsulated PostScript, Adobe Illustrator)
1375au BufNewFile,BufRead *.ps,*.pfa,*.afm,*.eps,*.epsf,*.epsi,*.ai	  setf postscr
1376
1377" PostScript Printer Description
1378au BufNewFile,BufRead *.ppd			setf ppd
1379
1380" Povray
1381au BufNewFile,BufRead *.pov			setf pov
1382
1383" Povray configuration
1384au BufNewFile,BufRead .povrayrc			setf povini
1385
1386" Povray, PHP or assembly
1387au BufNewFile,BufRead *.inc			call s:FTinc()
1388
1389func! s:FTinc()
1390  if exists("g:filetype_inc")
1391    exe "setf " . g:filetype_inc
1392  else
1393    let lines = getline(1).getline(2).getline(3)
1394    if lines =~? "perlscript"
1395      setf aspperl
1396    elseif lines =~ "<%"
1397      setf aspvbs
1398    elseif lines =~ "<?"
1399      setf php
1400    else
1401      call s:FTasmsyntax()
1402      if exists("b:asmsyntax")
1403	exe "setf " . fnameescape(b:asmsyntax)
1404      else
1405	setf pov
1406      endif
1407    endif
1408  endif
1409endfunc
1410
1411" Printcap and Termcap
1412au BufNewFile,BufRead *printcap
1413	\ let b:ptcap_type = "print" | setf ptcap
1414au BufNewFile,BufRead *termcap
1415	\ let b:ptcap_type = "term" | setf ptcap
1416
1417" PCCTS / ANTRL
1418"au BufNewFile,BufRead *.g			setf antrl
1419au BufNewFile,BufRead *.g			setf pccts
1420
1421" PPWizard
1422au BufNewFile,BufRead *.it,*.ih			setf ppwiz
1423
1424" Obj 3D file format
1425" TODO: is there a way to avoid MS-Windows Object files?
1426au BufNewFile,BufRead *.obj			setf obj
1427
1428" Oracle Pro*C/C++
1429au BufNewFile,BufRead *.pc			setf proc
1430
1431" Privoxy actions file
1432au BufNewFile,BufRead *.action			setf privoxy
1433
1434" Procmail
1435au BufNewFile,BufRead .procmail,.procmailrc	setf procmail
1436
1437" Progress or CWEB
1438au BufNewFile,BufRead *.w			call s:FTprogress_cweb()
1439
1440func! s:FTprogress_cweb()
1441  if exists("g:filetype_w")
1442    exe "setf " . g:filetype_w
1443    return
1444  endif
1445  if getline(1) =~ '&ANALYZE' || getline(3) =~ '&GLOBAL-DEFINE'
1446    setf progress
1447  else
1448    setf cweb
1449  endif
1450endfunc
1451
1452" Progress or assembly
1453au BufNewFile,BufRead *.i			call s:FTprogress_asm()
1454
1455func! s:FTprogress_asm()
1456  if exists("g:filetype_i")
1457    exe "setf " . g:filetype_i
1458    return
1459  endif
1460  " This function checks for an assembly comment the first ten lines.
1461  " If not found, assume Progress.
1462  let lnum = 1
1463  while lnum <= 10 && lnum < line('$')
1464    let line = getline(lnum)
1465    if line =~ '^\s*;' || line =~ '^\*'
1466      call s:FTasm()
1467      return
1468    elseif line !~ '^\s*$' || line =~ '^/\*'
1469      " Not an empty line: Doesn't look like valid assembly code.
1470      " Or it looks like a Progress /* comment
1471      break
1472    endif
1473    let lnum = lnum + 1
1474  endw
1475  setf progress
1476endfunc
1477
1478" Progress or Pascal
1479au BufNewFile,BufRead *.p			call s:FTprogress_pascal()
1480
1481func! s:FTprogress_pascal()
1482  if exists("g:filetype_p")
1483    exe "setf " . g:filetype_p
1484    return
1485  endif
1486  " This function checks for valid Pascal syntax in the first ten lines.
1487  " Look for either an opening comment or a program start.
1488  " If not found, assume Progress.
1489  let lnum = 1
1490  while lnum <= 10 && lnum < line('$')
1491    let line = getline(lnum)
1492    if line =~ '^\s*\(program\|unit\|procedure\|function\|const\|type\|var\)\>'
1493	\ || line =~ '^\s*{' || line =~ '^\s*(\*'
1494      setf pascal
1495      return
1496    elseif line !~ '^\s*$' || line =~ '^/\*'
1497      " Not an empty line: Doesn't look like valid Pascal code.
1498      " Or it looks like a Progress /* comment
1499      break
1500    endif
1501    let lnum = lnum + 1
1502  endw
1503  setf progress
1504endfunc
1505
1506
1507" Software Distributor Product Specification File (POSIX 1387.2-1995)
1508au BufNewFile,BufRead *.psf			setf psf
1509au BufNewFile,BufRead INDEX,INFO
1510	\ if getline(1) =~ '^\s*\(distribution\|installed_software\|root\|bundle\|product\)\s*$' |
1511	\   setf psf |
1512	\ endif
1513
1514" Prolog
1515au BufNewFile,BufRead *.pdb			setf prolog
1516
1517" Promela
1518au BufNewFile,BufRead *.pml			setf promela
1519
1520" Protocols
1521au BufNewFile,BufRead */etc/protocols		setf protocols
1522
1523" Pyrex
1524au BufNewFile,BufRead *.pyx,*.pxd		setf pyrex
1525
1526" Python
1527au BufNewFile,BufRead *.py,*.pyw		setf python
1528
1529" Quixote (Python-based web framework)
1530au BufNewFile,BufRead *.ptl			setf python
1531
1532" Radiance
1533au BufNewFile,BufRead *.rad,*.mat		setf radiance
1534
1535" Ratpoison config/command files
1536au BufNewFile,BufRead .ratpoisonrc,ratpoisonrc	setf ratpoison
1537
1538" RCS file
1539au BufNewFile,BufRead *\,v			setf rcs
1540
1541" Readline
1542au BufNewFile,BufRead .inputrc,inputrc		setf readline
1543
1544" Registry for MS-Windows
1545au BufNewFile,BufRead *.reg
1546	\ if getline(1) =~? '^REGEDIT[0-9]*\s*$\|^Windows Registry Editor Version \d*\.\d*\s*$' | setf registry | endif
1547
1548" Renderman Interface Bytestream
1549au BufNewFile,BufRead *.rib			setf rib
1550
1551" Rexx
1552au BufNewFile,BufRead *.rexx,*.rex,*.jrexx,*.rxj,*.orx	setf rexx
1553
1554" R (Splus)
1555if has("fname_case")
1556  au BufNewFile,BufRead *.s,*.S			setf r
1557else
1558  au BufNewFile,BufRead *.s			setf r
1559endif
1560
1561" R Help file
1562if has("fname_case")
1563  au BufNewFile,BufRead *.rd,*.Rd		setf rhelp
1564else
1565  au BufNewFile,BufRead *.rd			setf rhelp
1566endif
1567
1568" R noweb file
1569if has("fname_case")
1570  au BufNewFile,BufRead *.Rnw,*.rnw,*.Snw,*.snw		setf rnoweb
1571else
1572  au BufNewFile,BufRead *.rnw,*.snw			setf rnoweb
1573endif
1574
1575" Rexx, Rebol or R
1576au BufNewFile,BufRead *.r,*.R			call s:FTr()
1577
1578func! s:FTr()
1579  let max = line("$") > 50 ? 50 : line("$")
1580
1581  for n in range(1, max)
1582    " Rebol is easy to recognize, check for that first
1583    if getline(n) =~? '\<REBOL\>'
1584      setf rebol
1585      return
1586    endif
1587  endfor
1588
1589  for n in range(1, max)
1590    " R has # comments
1591    if getline(n) =~ '^\s*#'
1592      setf r
1593      return
1594    endif
1595    " Rexx has /* comments */
1596    if getline(n) =~ '^\s*/\*'
1597      setf rexx
1598      return
1599    endif
1600  endfor
1601
1602  " Nothing recognized, use user default or assume Rexx
1603  if exists("g:filetype_r")
1604    exe "setf " . g:filetype_r
1605  else
1606    " Rexx used to be the default, but R appears to be much more popular.
1607    setf r
1608  endif
1609endfunc
1610
1611" Remind
1612au BufNewFile,BufRead .reminders,*.remind,*.rem		setf remind
1613
1614" Resolv.conf
1615au BufNewFile,BufRead resolv.conf		setf resolv
1616
1617" Relax NG Compact
1618au BufNewFile,BufRead *.rnc			setf rnc
1619
1620" RPL/2
1621au BufNewFile,BufRead *.rpl			setf rpl
1622
1623" Robots.txt
1624au BufNewFile,BufRead robots.txt		setf robots
1625
1626" Rpcgen
1627au BufNewFile,BufRead *.x			setf rpcgen
1628
1629" reStructuredText Documentation Format
1630au BufNewFile,BufRead *.rst			setf rst
1631
1632" RTF
1633au BufNewFile,BufRead *.rtf			setf rtf
1634
1635" Interactive Ruby shell
1636au BufNewFile,BufRead .irbrc,irbrc		setf ruby
1637
1638" Ruby
1639au BufNewFile,BufRead *.rb,*.rbw		setf ruby
1640
1641" RubyGems
1642au BufNewFile,BufRead *.gemspec			setf ruby
1643
1644" Rackup
1645au BufNewFile,BufRead *.ru			setf ruby
1646
1647" Bundler
1648au BufNewFile,BufRead Gemfile			setf ruby
1649
1650" Ruby on Rails
1651au BufNewFile,BufRead *.builder,*.rxml,*.rjs	setf ruby
1652
1653" Rantfile and Rakefile is like Ruby
1654au BufNewFile,BufRead [rR]antfile,*.rant,[rR]akefile,*.rake	setf ruby
1655
1656" S-lang (or shader language, or SmallLisp)
1657au BufNewFile,BufRead *.sl			setf slang
1658
1659" Samba config
1660au BufNewFile,BufRead smb.conf			setf samba
1661
1662" SAS script
1663au BufNewFile,BufRead *.sas			setf sas
1664
1665" Sass
1666au BufNewFile,BufRead *.sass			setf sass
1667
1668" Sather
1669au BufNewFile,BufRead *.sa			setf sather
1670
1671" Scilab
1672au BufNewFile,BufRead *.sci,*.sce		setf scilab
1673
1674" SCSS
1675au BufNewFile,BufRead *.scss			setf scss
1676
1677" SD: Streaming Descriptors
1678au BufNewFile,BufRead *.sd			setf sd
1679
1680" SDL
1681au BufNewFile,BufRead *.sdl,*.pr		setf sdl
1682
1683" sed
1684au BufNewFile,BufRead *.sed			setf sed
1685
1686" Sieve (RFC 3028)
1687au BufNewFile,BufRead *.siv			setf sieve
1688
1689" Sendmail
1690au BufNewFile,BufRead sendmail.cf		setf sm
1691
1692" Sendmail .mc files are actually m4.  Could also be MS Message text file.
1693au BufNewFile,BufRead *.mc			call s:McSetf()
1694
1695func! s:McSetf()
1696  " Rely on the file to start with a comment.
1697  " MS message text files use ';', Sendmail files use '#' or 'dnl'
1698  for lnum in range(1, min([line("$"), 20]))
1699    let line = getline(lnum)
1700    if line =~ '^\s*\(#\|dnl\)'
1701      setf m4  " Sendmail .mc file
1702      return
1703    elseif line =~ '^\s*;'
1704      setf msmessages  " MS Message text file
1705      return
1706    endif
1707  endfor
1708  setf m4  " Default: Sendmail .mc file
1709endfunc
1710
1711" Services
1712au BufNewFile,BufRead */etc/services		setf services
1713
1714" Service Location config
1715au BufNewFile,BufRead */etc/slp.conf		setf slpconf
1716
1717" Service Location registration
1718au BufNewFile,BufRead */etc/slp.reg		setf slpreg
1719
1720" Service Location SPI
1721au BufNewFile,BufRead */etc/slp.spi		setf slpspi
1722
1723" Setserial config
1724au BufNewFile,BufRead */etc/serial.conf		setf setserial
1725
1726" SGML
1727au BufNewFile,BufRead *.sgm,*.sgml
1728	\ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'linuxdoc' |
1729	\   setf sgmllnx |
1730	\ elseif getline(1) =~ '<!DOCTYPE.*DocBook' || getline(2) =~ '<!DOCTYPE.*DocBook' |
1731	\   let b:docbk_type="sgml" |
1732	\   setf docbk |
1733	\ else |
1734	\   setf sgml |
1735	\ endif
1736
1737" SGMLDECL
1738au BufNewFile,BufRead *.decl,*.dcl,*.dec
1739	\ if getline(1).getline(2).getline(3) =~? '^<!SGML' |
1740	\    setf sgmldecl |
1741	\ endif
1742
1743" SGML catalog file
1744au BufNewFile,BufRead catalog			setf catalog
1745au BufNewFile,BufRead sgml.catalog*		call s:StarSetf('catalog')
1746
1747" Shell scripts (sh, ksh, bash, bash2, csh); Allow .profile_foo etc.
1748" Gentoo ebuilds are actually bash scripts
1749au BufNewFile,BufRead .bashrc*,bashrc,bash.bashrc,.bash_profile*,.bash_logout*,*.bash,*.ebuild call SetFileTypeSH("bash")
1750au BufNewFile,BufRead .kshrc*,*.ksh call SetFileTypeSH("ksh")
1751au BufNewFile,BufRead */etc/profile,.profile*,*.sh,*.env call SetFileTypeSH(getline(1))
1752
1753" Also called from scripts.vim.
1754func! SetFileTypeSH(name)
1755  if expand("<amatch>") =~ g:ft_ignore_pat
1756    return
1757  endif
1758  if a:name =~ '\<csh\>'
1759    " Some .sh scripts contain #!/bin/csh.
1760    call SetFileTypeShell("csh")
1761    return
1762  elseif a:name =~ '\<tcsh\>'
1763    " Some .sh scripts contain #!/bin/tcsh.
1764    call SetFileTypeShell("tcsh")
1765    return
1766  elseif a:name =~ '\<ksh\>'
1767    let b:is_kornshell = 1
1768    if exists("b:is_bash")
1769      unlet b:is_bash
1770    endif
1771    if exists("b:is_sh")
1772      unlet b:is_sh
1773    endif
1774  elseif exists("g:bash_is_sh") || a:name =~ '\<bash\>' || a:name =~ '\<bash2\>'
1775    let b:is_bash = 1
1776    if exists("b:is_kornshell")
1777      unlet b:is_kornshell
1778    endif
1779    if exists("b:is_sh")
1780      unlet b:is_sh
1781    endif
1782  elseif a:name =~ '\<sh\>'
1783    let b:is_sh = 1
1784    if exists("b:is_kornshell")
1785      unlet b:is_kornshell
1786    endif
1787    if exists("b:is_bash")
1788      unlet b:is_bash
1789    endif
1790  endif
1791  call SetFileTypeShell("sh")
1792endfunc
1793
1794" For shell-like file types, check for an "exec" command hidden in a comment,
1795" as used for Tcl.
1796" Also called from scripts.vim, thus can't be local to this script.
1797func! SetFileTypeShell(name)
1798  if expand("<amatch>") =~ g:ft_ignore_pat
1799    return
1800  endif
1801  let l = 2
1802  while l < 20 && l < line("$") && getline(l) =~ '^\s*\(#\|$\)'
1803    " Skip empty and comment lines.
1804    let l = l + 1
1805  endwhile
1806  if l < line("$") && getline(l) =~ '\s*exec\s' && getline(l - 1) =~ '^\s*#.*\\$'
1807    " Found an "exec" line after a comment with continuation
1808    let n = substitute(getline(l),'\s*exec\s\+\([^ ]*/\)\=', '', '')
1809    if n =~ '\<tclsh\|\<wish'
1810      setf tcl
1811      return
1812    endif
1813  endif
1814  exe "setf " . a:name
1815endfunc
1816
1817" tcsh scripts
1818au BufNewFile,BufRead .tcshrc*,*.tcsh,tcsh.tcshrc,tcsh.login	call SetFileTypeShell("tcsh")
1819
1820" csh scripts, but might also be tcsh scripts (on some systems csh is tcsh)
1821au BufNewFile,BufRead .login*,.cshrc*,csh.cshrc,csh.login,csh.logout,*.csh,.alias  call s:CSH()
1822
1823func! s:CSH()
1824  if exists("g:filetype_csh")
1825    call SetFileTypeShell(g:filetype_csh)
1826  elseif &shell =~ "tcsh"
1827    call SetFileTypeShell("tcsh")
1828  else
1829    call SetFileTypeShell("csh")
1830  endif
1831endfunc
1832
1833" Z-Shell script
1834au BufNewFile,BufRead .zprofile,*/etc/zprofile,.zfbfmarks  setf zsh
1835au BufNewFile,BufRead .zsh*,.zlog*,.zcompdump*  call s:StarSetf('zsh')
1836au BufNewFile,BufRead *.zsh			setf zsh
1837
1838" Scheme
1839au BufNewFile,BufRead *.scm,*.ss		setf scheme
1840
1841" Screen RC
1842au BufNewFile,BufRead .screenrc,screenrc	setf screen
1843
1844" Simula
1845au BufNewFile,BufRead *.sim			setf simula
1846
1847" SINDA
1848au BufNewFile,BufRead *.sin,*.s85		setf sinda
1849
1850" SiSU
1851au BufNewFile,BufRead *.sst,*.ssm,*.ssi,*.-sst,*._sst setf sisu
1852au BufNewFile,BufRead *.sst.meta,*.-sst.meta,*._sst.meta setf sisu
1853
1854" SKILL
1855au BufNewFile,BufRead *.il,*.ils,*.cdf		setf skill
1856
1857" SLRN
1858au BufNewFile,BufRead .slrnrc			setf slrnrc
1859au BufNewFile,BufRead *.score			setf slrnsc
1860
1861" Smalltalk (and TeX)
1862au BufNewFile,BufRead *.st			setf st
1863au BufNewFile,BufRead *.cls
1864	\ if getline(1) =~ '^%' |
1865	\  setf tex |
1866	\ else |
1867	\  setf st |
1868	\ endif
1869
1870" Smarty templates
1871au BufNewFile,BufRead *.tpl			setf smarty
1872
1873" SMIL or XML
1874au BufNewFile,BufRead *.smil
1875	\ if getline(1) =~ '<?\s*xml.*?>' |
1876	\   setf xml |
1877	\ else |
1878	\   setf smil |
1879	\ endif
1880
1881" SMIL or SNMP MIB file
1882au BufNewFile,BufRead *.smi
1883	\ if getline(1) =~ '\<smil\>' |
1884	\   setf smil |
1885	\ else |
1886	\   setf mib |
1887	\ endif
1888
1889" SMITH
1890au BufNewFile,BufRead *.smt,*.smith		setf smith
1891
1892" Snobol4 and spitbol
1893au BufNewFile,BufRead *.sno,*.spt		setf snobol4
1894
1895" SNMP MIB files
1896au BufNewFile,BufRead *.mib,*.my		setf mib
1897
1898" Snort Configuration
1899au BufNewFile,BufRead *.hog,snort.conf,vision.conf	setf hog
1900au BufNewFile,BufRead *.rules			call s:FTRules()
1901
1902let s:ft_rules_udev_rules_pattern = '^\s*\cudev_rules\s*=\s*"\([^"]\{-1,}\)/*".*'
1903func! s:FTRules()
1904  let path = expand('<amatch>:p')
1905  if path =~ '^/\(etc/udev/\%(rules\.d/\)\=.*\.rules\|lib/udev/\%(rules\.d/\)\=.*\.rules\)$'
1906    setf udevrules
1907    return
1908  endif
1909  if path =~ '^/etc/ufw/'
1910    setf conf  " Better than hog
1911    return
1912  endif
1913  try
1914    let config_lines = readfile('/etc/udev/udev.conf')
1915  catch /^Vim\%((\a\+)\)\=:E484/
1916    setf hog
1917    return
1918  endtry
1919  let dir = expand('<amatch>:p:h')
1920  for line in config_lines
1921    if line =~ s:ft_rules_udev_rules_pattern
1922      let udev_rules = substitute(line, s:ft_rules_udev_rules_pattern, '\1', "")
1923      if dir == udev_rules
1924        setf udevrules
1925      endif
1926      break
1927    endif
1928  endfor
1929  setf hog
1930endfunc
1931
1932
1933" Spec (Linux RPM)
1934au BufNewFile,BufRead *.spec			setf spec
1935
1936" Speedup (AspenTech plant simulator)
1937au BufNewFile,BufRead *.speedup,*.spdata,*.spd	setf spup
1938
1939" Slice
1940au BufNewFile,BufRead *.ice			setf slice
1941
1942" Spice
1943au BufNewFile,BufRead *.sp,*.spice		setf spice
1944
1945" Spyce
1946au BufNewFile,BufRead *.spy,*.spi		setf spyce
1947
1948" Squid
1949au BufNewFile,BufRead squid.conf		setf squid
1950
1951" SQL for Oracle Designer
1952au BufNewFile,BufRead *.tyb,*.typ,*.tyc,*.pkb,*.pks	setf sql
1953
1954" SQL
1955au BufNewFile,BufRead *.sql			call s:SQL()
1956
1957func! s:SQL()
1958  if exists("g:filetype_sql")
1959    exe "setf " . g:filetype_sql
1960  else
1961    setf sql
1962  endif
1963endfunc
1964
1965" SQLJ
1966au BufNewFile,BufRead *.sqlj			setf sqlj
1967
1968" SQR
1969au BufNewFile,BufRead *.sqr,*.sqi		setf sqr
1970
1971" OpenSSH configuration
1972au BufNewFile,BufRead ssh_config,*/.ssh/config	setf sshconfig
1973
1974" OpenSSH server configuration
1975au BufNewFile,BufRead sshd_config		setf sshdconfig
1976
1977" Stata
1978au BufNewFile,BufRead *.ado,*.class,*.do,*.imata,*.mata   setf stata
1979
1980" SMCL
1981au BufNewFile,BufRead *.hlp,*.ihlp,*.smcl	setf smcl
1982
1983" Stored Procedures
1984au BufNewFile,BufRead *.stp			setf stp
1985
1986" Standard ML
1987au BufNewFile,BufRead *.sml			setf sml
1988
1989" Sratus VOS command macro
1990au BufNewFile,BufRead *.cm			setf voscm
1991
1992" Sysctl
1993au BufNewFile,BufRead */etc/sysctl.conf,*/etc/sysctl.d/*.conf	setf sysctl
1994
1995" Synopsys Design Constraints
1996au BufNewFile,BufRead *.sdc			setf sdc
1997
1998" Sudoers
1999au BufNewFile,BufRead */etc/sudoers,sudoers.tmp	setf sudoers
2000
2001" SVG (Scalable Vector Graphics)
2002au BufNewFile,BufRead *.svg			setf svg
2003
2004" If the file has an extension of 't' and is in a directory 't' then it is
2005" almost certainly a Perl test file.
2006" If the first line starts with '#' and contains 'perl' it's probably a Perl
2007" file.
2008" (Slow test) If a file contains a 'use' statement then it is almost certainly
2009" a Perl file.
2010func! s:FTperl()
2011  if expand("%:e") == 't' && expand("%:p:h:t") == 't'
2012    setf perl
2013    return 1
2014  endif
2015  if getline(1)[0] == '#' && getline(1) =~ 'perl'
2016    setf perl
2017    return 1
2018  endif
2019  if search('^use\s\s*\k', 'nc', 30)
2020    setf perl
2021    return 1
2022  endif
2023  return 0
2024endfunc
2025
2026" Tads (or Nroff or Perl test file)
2027au BufNewFile,BufRead *.t
2028	\ if !s:FTnroff() && !s:FTperl() | setf tads | endif
2029
2030" Tags
2031au BufNewFile,BufRead tags			setf tags
2032
2033" TAK
2034au BufNewFile,BufRead *.tak			setf tak
2035
2036" Task
2037au BufRead,BufNewFile {pending,completed,undo}.data  setf taskdata
2038au BufRead,BufNewFile *.task                    setf taskedit
2039
2040" Tcl (JACL too)
2041au BufNewFile,BufRead *.tcl,*.tk,*.itcl,*.itk,*.jacl	setf tcl
2042
2043" TealInfo
2044au BufNewFile,BufRead *.tli			setf tli
2045
2046" Telix Salt
2047au BufNewFile,BufRead *.slt			setf tsalt
2048
2049" Terminfo
2050au BufNewFile,BufRead *.ti			setf terminfo
2051
2052" TeX
2053au BufNewFile,BufRead *.latex,*.sty,*.dtx,*.ltx,*.bbl	setf tex
2054au BufNewFile,BufRead *.tex			call s:FTtex()
2055
2056" Choose context, plaintex, or tex (LaTeX) based on these rules:
2057" 1. Check the first line of the file for "%&<format>".
2058" 2. Check the first 1000 non-comment lines for LaTeX or ConTeXt keywords.
2059" 3. Default to "latex" or to g:tex_flavor, can be set in user's vimrc.
2060func! s:FTtex()
2061  let firstline = getline(1)
2062  if firstline =~ '^%&\s*\a\+'
2063    let format = tolower(matchstr(firstline, '\a\+'))
2064    let format = substitute(format, 'pdf', '', '')
2065    if format == 'tex'
2066      let format = 'plain'
2067    endif
2068  else
2069    " Default value, may be changed later:
2070    let format = exists("g:tex_flavor") ? g:tex_flavor : 'plain'
2071    " Save position, go to the top of the file, find first non-comment line.
2072    let save_cursor = getpos('.')
2073    call cursor(1,1)
2074    let firstNC = search('^\s*[^[:space:]%]', 'c', 1000)
2075    if firstNC " Check the next thousand lines for a LaTeX or ConTeXt keyword.
2076      let lpat = 'documentclass\>\|usepackage\>\|begin{\|newcommand\>\|renewcommand\>'
2077      let cpat = 'start\a\+\|setup\a\+\|usemodule\|enablemode\|enableregime\|setvariables\|useencoding\|usesymbols\|stelle\a\+\|verwende\a\+\|stel\a\+\|gebruik\a\+\|usa\a\+\|imposta\a\+\|regle\a\+\|utilisemodule\>'
2078      let kwline = search('^\s*\\\%(' . lpat . '\)\|^\s*\\\(' . cpat . '\)',
2079			      \ 'cnp', firstNC + 1000)
2080      if kwline == 1	" lpat matched
2081	let format = 'latex'
2082      elseif kwline == 2	" cpat matched
2083	let format = 'context'
2084      endif		" If neither matched, keep default set above.
2085      " let lline = search('^\s*\\\%(' . lpat . '\)', 'cn', firstNC + 1000)
2086      " let cline = search('^\s*\\\%(' . cpat . '\)', 'cn', firstNC + 1000)
2087      " if cline > 0
2088      "   let format = 'context'
2089      " endif
2090      " if lline > 0 && (cline == 0 || cline > lline)
2091      "   let format = 'tex'
2092      " endif
2093    endif " firstNC
2094    call setpos('.', save_cursor)
2095  endif " firstline =~ '^%&\s*\a\+'
2096
2097  " Translation from formats to file types.  TODO:  add AMSTeX, RevTex, others?
2098  if format == 'plain'
2099    setf plaintex
2100  elseif format == 'context'
2101    setf context
2102  else " probably LaTeX
2103    setf tex
2104  endif
2105  return
2106endfunc
2107
2108" ConTeXt
2109au BufNewFile,BufRead tex/context/*/*.tex,*.mkii,*.mkiv   setf context
2110
2111" Texinfo
2112au BufNewFile,BufRead *.texinfo,*.texi,*.txi	setf texinfo
2113
2114" TeX configuration
2115au BufNewFile,BufRead texmf.cnf			setf texmf
2116
2117" Tidy config
2118au BufNewFile,BufRead .tidyrc,tidyrc		setf tidy
2119
2120" TF mud client
2121au BufNewFile,BufRead *.tf,.tfrc,tfrc		setf tf
2122
2123" TPP - Text Presentation Program
2124au BufNewFile,BufReadPost *.tpp			setf tpp
2125
2126" Treetop
2127au BufRead,BufNewFile *.treetop			setf treetop
2128
2129" Trustees
2130au BufNewFile,BufRead trustees.conf		setf trustees
2131
2132" TSS - Geometry
2133au BufNewFile,BufReadPost *.tssgm		setf tssgm
2134
2135" TSS - Optics
2136au BufNewFile,BufReadPost *.tssop		setf tssop
2137
2138" TSS - Command Line (temporary)
2139au BufNewFile,BufReadPost *.tsscl		setf tsscl
2140
2141" Motif UIT/UIL files
2142au BufNewFile,BufRead *.uit,*.uil		setf uil
2143
2144" Udev conf
2145au BufNewFile,BufRead */etc/udev/udev.conf	setf udevconf
2146
2147" Udev permissions
2148au BufNewFile,BufRead */etc/udev/permissions.d/*.permissions setf udevperm
2149"
2150" Udev symlinks config
2151au BufNewFile,BufRead */etc/udev/cdsymlinks.conf	setf sh
2152
2153" UnrealScript
2154au BufNewFile,BufRead *.uc			setf uc
2155
2156" Updatedb
2157au BufNewFile,BufRead */etc/updatedb.conf	setf updatedb
2158
2159" Upstart (init(8)) config files
2160au BufNewFile,BufRead */etc/init/*.conf,*/.init/*.conf          setf upstart
2161au BufNewFile,BufRead */etc/init/*.override,*/.init/*.override  setf upstart
2162
2163" Vera
2164au BufNewFile,BufRead *.vr,*.vri,*.vrh		setf vera
2165
2166" Verilog HDL
2167au BufNewFile,BufRead *.v			setf verilog
2168
2169" Verilog-AMS HDL
2170au BufNewFile,BufRead *.va,*.vams		setf verilogams
2171
2172" VHDL
2173au BufNewFile,BufRead *.hdl,*.vhd,*.vhdl,*.vbe,*.vst  setf vhdl
2174au BufNewFile,BufRead *.vhdl_[0-9]*		call s:StarSetf('vhdl')
2175
2176" Vim script
2177au BufNewFile,BufRead *.vim,*.vba,.exrc,_exrc	setf vim
2178
2179" Viminfo file
2180au BufNewFile,BufRead .viminfo,_viminfo		setf viminfo
2181
2182" Virata Config Script File or Drupal module
2183au BufRead,BufNewFile *.hw,*.module,*.pkg
2184	\ if getline(1) =~ '<?php' |
2185	\   setf php |
2186	\ else |
2187	\   setf virata |
2188	\ endif
2189
2190" Visual Basic (also uses *.bas) or FORM
2191au BufNewFile,BufRead *.frm			call s:FTVB("form")
2192
2193" SaxBasic is close to Visual Basic
2194au BufNewFile,BufRead *.sba			setf vb
2195
2196" Vgrindefs file
2197au BufNewFile,BufRead vgrindefs			setf vgrindefs
2198
2199" VRML V1.0c
2200au BufNewFile,BufRead *.wrl			setf vrml
2201
2202" Webmacro
2203au BufNewFile,BufRead *.wm			setf webmacro
2204
2205" Wget config
2206au BufNewFile,BufRead .wgetrc,wgetrc		setf wget
2207
2208" Website MetaLanguage
2209au BufNewFile,BufRead *.wml			setf wml
2210
2211" Winbatch
2212au BufNewFile,BufRead *.wbt			setf winbatch
2213
2214" WSML
2215au BufNewFile,BufRead *.wsml			setf wsml
2216
2217" WvDial
2218au BufNewFile,BufRead wvdial.conf,.wvdialrc	setf wvdial
2219
2220" CVS RC file
2221au BufNewFile,BufRead .cvsrc			setf cvsrc
2222
2223" CVS commit file
2224au BufNewFile,BufRead cvs\d\+			setf cvs
2225
2226" WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment
2227" lines in a WEB file).
2228au BufNewFile,BufRead *.web
2229	\ if getline(1)[0].getline(2)[0].getline(3)[0].getline(4)[0].getline(5)[0] =~ "%" |
2230	\   setf web |
2231	\ else |
2232	\   setf winbatch |
2233	\ endif
2234
2235" Windows Scripting Host and Windows Script Component
2236au BufNewFile,BufRead *.ws[fc]			setf wsh
2237
2238" XHTML
2239au BufNewFile,BufRead *.xhtml,*.xht		setf xhtml
2240
2241" X Pixmap (dynamically sets colors, use BufEnter to make it work better)
2242au BufEnter *.xpm
2243	\ if getline(1) =~ "XPM2" |
2244	\   setf xpm2 |
2245	\ else |
2246	\   setf xpm |
2247	\ endif
2248au BufEnter *.xpm2				setf xpm2
2249
2250" XFree86 config
2251au BufNewFile,BufRead XF86Config
2252	\ if getline(1) =~ '\<XConfigurator\>' |
2253	\   let b:xf86conf_xfree86_version = 3 |
2254	\ endif |
2255	\ setf xf86conf
2256au BufNewFile,BufRead */xorg.conf.d/*.conf
2257	\ let b:xf86conf_xfree86_version = 4 |
2258	\ setf xf86conf
2259
2260" Xorg config
2261au BufNewFile,BufRead xorg.conf,xorg.conf-4	let b:xf86conf_xfree86_version = 4 | setf xf86conf
2262
2263" Xinetd conf
2264au BufNewFile,BufRead */etc/xinetd.conf		setf xinetd
2265
2266" XS Perl extension interface language
2267au BufNewFile,BufRead *.xs			setf xs
2268
2269" X resources file
2270au BufNewFile,BufRead .Xdefaults,.Xpdefaults,.Xresources,xdm-config,*.ad setf xdefaults
2271
2272" Xmath
2273au BufNewFile,BufRead *.msc,*.msf		setf xmath
2274au BufNewFile,BufRead *.ms
2275	\ if !s:FTnroff() | setf xmath | endif
2276
2277" XML  specific variants: docbk and xbl
2278au BufNewFile,BufRead *.xml			call s:FTxml()
2279
2280func! s:FTxml()
2281  let n = 1
2282  while n < 100 && n < line("$")
2283    let line = getline(n)
2284    if line =~ '<!DOCTYPE.*DocBook'
2285      let b:docbk_type = "xml"
2286      setf docbk
2287      return
2288    endif
2289    if line =~ 'xmlns:xbl="http://www.mozilla.org/xbl"'
2290      setf xbl
2291      return
2292    endif
2293    let n += 1
2294  endwhile
2295  setf xml
2296endfunc
2297
2298" XMI (holding UML models) is also XML
2299au BufNewFile,BufRead *.xmi			setf xml
2300
2301" CSPROJ files are Visual Studio.NET's XML-based project config files
2302au BufNewFile,BufRead *.csproj,*.csproj.user	setf xml
2303
2304" Qt Linguist translation source and Qt User Interface Files are XML
2305au BufNewFile,BufRead *.ts,*.ui			setf xml
2306
2307" TPM's are RDF-based descriptions of TeX packages (Nikolai Weibull)
2308au BufNewFile,BufRead *.tpm			setf xml
2309
2310" Xdg menus
2311au BufNewFile,BufRead */etc/xdg/menus/*.menu	setf xml
2312
2313" ATI graphics driver configuration
2314au BufNewFile,BufRead fglrxrc			setf xml
2315
2316" XLIFF (XML Localisation Interchange File Format) is also XML
2317au BufNewFile,BufRead *.xlf			setf xml
2318au BufNewFile,BufRead *.xliff			setf xml
2319
2320" X11 xmodmap (also see below)
2321au BufNewFile,BufRead *Xmodmap			setf xmodmap
2322
2323" Xquery
2324au BufNewFile,BufRead *.xq,*.xql,*.xqm,*.xquery,*.xqy	setf xquery
2325
2326" XSD
2327au BufNewFile,BufRead *.xsd			setf xsd
2328
2329" Xslt
2330au BufNewFile,BufRead *.xsl,*.xslt		setf xslt
2331
2332" Yacc
2333au BufNewFile,BufRead *.yy			setf yacc
2334
2335" Yacc or racc
2336au BufNewFile,BufRead *.y			call s:FTy()
2337
2338func! s:FTy()
2339  let n = 1
2340  while n < 100 && n < line("$")
2341    let line = getline(n)
2342    if line =~ '^\s*%'
2343      setf yacc
2344      return
2345    endif
2346    if getline(n) =~ '^\s*\(#\|class\>\)' && getline(n) !~ '^\s*#\s*include'
2347      setf racc
2348      return
2349    endif
2350    let n = n + 1
2351  endwhile
2352  setf yacc
2353endfunc
2354
2355
2356" Yaml
2357au BufNewFile,BufRead *.yaml,*.yml		setf yaml
2358
2359" yum conf (close enough to dosini)
2360au BufNewFile,BufRead */etc/yum.conf 		setf dosini
2361
2362" Zope
2363"   dtml (zope dynamic template markup language), pt (zope page template),
2364"   cpt (zope form controller page template)
2365au BufNewFile,BufRead *.dtml,*.pt,*.cpt		call s:FThtml()
2366"   zsql (zope sql method)
2367au BufNewFile,BufRead *.zsql			call s:SQL()
2368
2369" Z80 assembler asz80
2370au BufNewFile,BufRead *.z8a			setf z8a
2371
2372augroup END
2373
2374
2375" Source the user-specified filetype file, for backwards compatibility with
2376" Vim 5.x.
2377if exists("myfiletypefile") && filereadable(expand(myfiletypefile))
2378  execute "source " . myfiletypefile
2379endif
2380
2381
2382" Check for "*" after loading myfiletypefile, so that scripts.vim is only used
2383" when there are no matching file name extensions.
2384" Don't do this for compressed files.
2385augroup filetypedetect
2386au BufNewFile,BufRead *
2387	\ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2388	\ | runtime! scripts.vim | endif
2389au StdinReadPost * if !did_filetype() | runtime! scripts.vim | endif
2390
2391
2392" Extra checks for when no filetype has been detected now.  Mostly used for
2393" patterns that end in "*".  E.g., "zsh*" matches "zsh.vim", but that's a Vim
2394" script file.
2395" Most of these should call s:StarSetf() to avoid names ending in .gz and the
2396" like are used.
2397
2398" More Apache config files
2399au BufNewFile,BufRead access.conf*,apache.conf*,apache2.conf*,httpd.conf*,srm.conf*	call s:StarSetf('apache')
2400au BufNewFile,BufRead */etc/apache2/*.conf*,*/etc/apache2/conf.*/*,*/etc/apache2/mods-*/*,*/etc/apache2/sites-*/*,*/etc/httpd/conf.d/*.conf*		call s:StarSetf('apache')
2401
2402" Asterisk config file
2403au BufNewFile,BufRead *asterisk/*.conf*		call s:StarSetf('asterisk')
2404au BufNewFile,BufRead *asterisk*/*voicemail.conf* call s:StarSetf('asteriskvm')
2405
2406" Bazaar version control
2407au BufNewFile,BufRead bzr_log.*			setf bzr
2408
2409" BIND zone
2410au BufNewFile,BufRead */named/db.*,*/bind/db.*	call s:StarSetf('bindzone')
2411
2412" Calendar
2413au BufNewFile,BufRead */.calendar/*,
2414	\*/share/calendar/*/calendar.*,*/share/calendar/calendar.*
2415	\					call s:StarSetf('calendar')
2416
2417" Changelog
2418au BufNewFile,BufRead [cC]hange[lL]og*
2419	\ if getline(1) =~ '; urgency='
2420	\|  call s:StarSetf('debchangelog')
2421	\|else
2422	\|  call s:StarSetf('changelog')
2423	\|endif
2424
2425" Crontab
2426au BufNewFile,BufRead crontab,crontab.*,*/etc/cron.d/*		call s:StarSetf('crontab')
2427
2428" dnsmasq(8) configuration
2429au BufNewFile,BufRead */etc/dnsmasq.d/*		call s:StarSetf('dnsmasq')
2430
2431" Dracula
2432au BufNewFile,BufRead drac.*			call s:StarSetf('dracula')
2433
2434" Fvwm
2435au BufNewFile,BufRead */.fvwm/*			call s:StarSetf('fvwm')
2436au BufNewFile,BufRead *fvwmrc*,*fvwm95*.hook
2437	\ let b:fvwm_version = 1 | call s:StarSetf('fvwm')
2438au BufNewFile,BufRead *fvwm2rc*
2439	\ if expand("<afile>:e") == "m4"
2440	\|  call s:StarSetf('fvwm2m4')
2441	\|else
2442	\|  let b:fvwm_version = 2 | call s:StarSetf('fvwm')
2443	\|endif
2444
2445" Gedcom
2446au BufNewFile,BufRead */tmp/lltmp*		call s:StarSetf('gedcom')
2447
2448" GTK RC
2449au BufNewFile,BufRead .gtkrc*,gtkrc*		call s:StarSetf('gtkrc')
2450
2451" Jam
2452au BufNewFile,BufRead Prl*.*,JAM*.*		call s:StarSetf('jam')
2453
2454" Jargon
2455au! BufNewFile,BufRead *jarg*
2456	\ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'THIS IS THE JARGON FILE'
2457	\|  call s:StarSetf('jargon')
2458	\|endif
2459
2460" Kconfig
2461au BufNewFile,BufRead Kconfig.*			call s:StarSetf('kconfig')
2462
2463" Lilo: Linux loader
2464au BufNewFile,BufRead lilo.conf*		call s:StarSetf('lilo')
2465
2466" Logcheck
2467au BufNewFile,BufRead */etc/logcheck/*.d*/*	call s:StarSetf('logcheck')
2468
2469" Makefile
2470au BufNewFile,BufRead [mM]akefile*		call s:StarSetf('make')
2471
2472" Ruby Makefile
2473au BufNewFile,BufRead [rR]akefile*		call s:StarSetf('ruby')
2474
2475" Mail (also matches muttrc.vim, so this is below the other checks)
2476au BufNewFile,BufRead mutt[[:alnum:]._-]\{6\}	setf mail
2477
2478" Modconf
2479au BufNewFile,BufRead */etc/modutils/*
2480	\ if executable(expand("<afile>")) != 1
2481	\|  call s:StarSetf('modconf')
2482	\|endif
2483au BufNewFile,BufRead */etc/modprobe.*		call s:StarSetf('modconf')
2484
2485" Mutt setup file
2486au BufNewFile,BufRead .mutt{ng,}rc*,*/.mutt{ng,}/mutt{ng,}rc*	call s:StarSetf('muttrc')
2487au BufNewFile,BufRead mutt{ng,}rc*,Mutt{ng,}rc*		call s:StarSetf('muttrc')
2488
2489" Nroff macros
2490au BufNewFile,BufRead tmac.*			call s:StarSetf('nroff')
2491
2492" Pam conf
2493au BufNewFile,BufRead */etc/pam.d/*		call s:StarSetf('pamconf')
2494
2495" Printcap and Termcap
2496au BufNewFile,BufRead *printcap*
2497	\ if !did_filetype()
2498	\|  let b:ptcap_type = "print" | call s:StarSetf('ptcap')
2499	\|endif
2500au BufNewFile,BufRead *termcap*
2501	\ if !did_filetype()
2502	\|  let b:ptcap_type = "term" | call s:StarSetf('ptcap')
2503	\|endif
2504
2505" Remind
2506au BufNewFile,BufRead .reminders*		call s:StarSetf('remind')
2507
2508" Vim script
2509au BufNewFile,BufRead *vimrc*			call s:StarSetf('vim')
2510
2511" Subversion commit file
2512au BufNewFile,BufRead svn-commit*.tmp		setf svn
2513
2514" X resources file
2515au BufNewFile,BufRead Xresources*,*/app-defaults/*,*/Xresources/* call s:StarSetf('xdefaults')
2516
2517" XFree86 config
2518au BufNewFile,BufRead XF86Config-4*
2519	\ let b:xf86conf_xfree86_version = 4 | call s:StarSetf('xf86conf')
2520au BufNewFile,BufRead XF86Config*
2521	\ if getline(1) =~ '\<XConfigurator\>'
2522	\|  let b:xf86conf_xfree86_version = 3
2523	\|endif
2524	\|call s:StarSetf('xf86conf')
2525
2526" X11 xmodmap
2527au BufNewFile,BufRead *xmodmap*			call s:StarSetf('xmodmap')
2528
2529" Xinetd conf
2530au BufNewFile,BufRead */etc/xinetd.d/*		call s:StarSetf('xinetd')
2531
2532" yum conf (close enough to dosini)
2533au BufNewFile,BufRead */etc/yum.repos.d/* 	call s:StarSetf('dosini')
2534
2535" Z-Shell script
2536au BufNewFile,BufRead zsh*,zlog*		call s:StarSetf('zsh')
2537
2538
2539" Plain text files, needs to be far down to not override others.  This avoids
2540" the "conf" type being used if there is a line starting with '#'.
2541au BufNewFile,BufRead *.txt,*.text		setf text
2542
2543
2544" Use the filetype detect plugins.  They may overrule any of the previously
2545" detected filetypes.
2546runtime! ftdetect/*.vim
2547
2548
2549" Generic configuration file (check this last, it's just guessing!)
2550au BufNewFile,BufRead,StdinReadPost *
2551	\ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2552	\    && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
2553	\	|| getline(4) =~ '^#' || getline(5) =~ '^#') |
2554	\   setf conf |
2555	\ endif
2556
2557augroup END
2558
2559
2560" If the GUI is already running, may still need to install the Syntax menu.
2561" Don't do it when the 'M' flag is included in 'guioptions'.
2562if has("menu") && has("gui_running")
2563      \ && !exists("did_install_syntax_menu") && &guioptions !~# "M"
2564  source <sfile>:p:h/menu.vim
2565endif
2566
2567" Function called for testing all functions defined here.  These are
2568" script-local, thus need to be executed here.
2569" Returns a string with error messages (hopefully empty).
2570func! TestFiletypeFuncs(testlist)
2571  let output = ''
2572  for f in a:testlist
2573    try
2574      exe f
2575    catch
2576      let output = output . "\n" . f . ": " . v:exception
2577    endtry
2578  endfor
2579  return output
2580endfunc
2581
2582" Restore 'cpoptions'
2583let &cpo = s:cpo_save
2584unlet s:cpo_save
2585