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