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