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