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