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