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