; $Id: modes.rc,v 1.135 2015/01/30 09:36:57 tom Exp $
; majormodes in this file are ordered alphabetically for convenience - the
; precedence used by vile is strictly alphabetic, counting case.  Use the
; before and after qualifiers to override the precedence.

setv %filters-modes=true

; The tabstops correspond to those used for ncurses' Ada95 wrapper which in
; turn follows gnat's style.
define-mode ada
~with define-submode ada
	suffixes	'\.\(ada\|ads\|adb\|gpr\)$'
	comment-prefix	'^\s*--'
	comments	'^\s*--\s*$'
	fence-if   '^\s*\<if\>'
	fence-elif '^\s*\<elsif\>'
	fence-else '^\s*\<else\>'
	fence-fi   '^\s*\<end\s\+if\>'
	ignorecase
	notabinsert
	tabstop=3
	shiftwidth=3
~elsewith define-submode ada group 'loop'
	fence-if   '^\s*\<for\>'
	fence-fi   '^\s*\<end\s\+loop\>'
~elsewith define-submode ada group 'case'
	fence-if   '^\s*\<case\>'
	fence-else '^\s*\<when\s\+others\>'
	fence-elif '^\s*\<when\>'
	fence-fi   '^\s*\<end\s\+case\>'
;~elsewith define-submode ada group 'begin'
;	fence-if   '^\s*\<begin\>'
;	fence-else '^\s*\<exception\>'
;	fence-fi   '^\s*\<end\>'
~endwith

define-mode ant
~with define-submode ant
	before xml
	qualifiers=all
	mode-filename	'build.xml'
	pre		'^\s*<?xml\s.*'
	fence-pairs	'<>()[]{}'
	comment-prefix	'^\s*--'
	comments	'^\s*$'
~endwith

; GNU assembler (a Byzantine elaboration of AT&T)
define-mode as
~with define-submode as
	suffixes	'\.[sS]$'
~endwith

; M$ assembler (a Byzantine elaboration of Intel)
define-mode asm
~with define-submode asm
	suffixes	'\.asm$'
	fence-if   '^\s*\<\(if\|ifdef\|ifndef\)\>'
	fence-elif '^\s*\<elseif\>'
	fence-else '^\s*\<else\>'
	fence-fi   '^\s*\<endif\>'
~endwith

define-mode asp
~with define-submode asp
	before		"html"
	suffixes	'\.\(asp\|aspx\|asa\|asax\)$'
	;dos
	;percent-crlf 100
~endwith

; AutoIt version 3
define-mode au3
~with define-submode au3
	suffixes	'\.au3$'
	dos
	ignorecase
	comment-prefix	'^\s*;'
	comments	'^\s*;\s\+\s*$'
	fence-if	'^\s*\<if\>.*\<then\>\s*\(;.*\)\?$'
	fence-elif	'^\s*\<elseif\>'
	fence-else	'^\s*\<else\>'
	fence-fi	'^\s*\<endif\>'
~elsewith define-submode au3 group 'case'
	fence-if	'^\s*\<select\>'
	fence-elif	'^\s*\<case\>'
	fence-else	'^\s*\<case\s\+else\>'
	fence-fi	'^\s*\<endselect\>'
~elsewith define-submode au3 group 'func'
	fence-if	'^\s*\<func\>'
	fence-fi	'^\s*\<endfunc\>'
~elsewith define-submode au3 group 'while'
	fence-if	'^\s*\<while\>'
	fence-fi	'^\s*\<wend\>'
~elsewith define-submode au3 group 'for'
	fence-if	'^\s*\<for\>'
	fence-fi	'^\s*\<next\>'
~endwith

define-mode awk
~with define-submode awk
	suffixes	'\.awk$'
	pre '^#!\s*\(\/[^\\]*\)\?awk\>\(\s*-[\a]\+\)*\s*$'
	cindent
	cindent-chars $fences
	comment-prefix '^\s*#'
	comments   '^\s*#\s\+\s*$'
~endwith

define-mode basic
~with define-submode basic
	suffixes	'\.bas$'
	comment-prefix	"^\\s*'"
	comments   	"^\\s*'\s\\+\\s*$"
	ignorecase
	notabinsert
~endwith

define-mode bat
~with define-submode bat
	suffixes	'\.\(bat\|cmd\)$'
	pre '\s*\(@\)\?echo\s*\(on\|off\)\?$'
	dos
	ignorecase
	comment-prefix '^\s*rem\>'
	comments   '^\s*rem\>\s\+\s*$'
	fence-if	'^\s*\<setlocal\>'
	fence-fi	'^\s*\<endlocal\>'
~endwith

define-mode bnf
~with define-submode bnf
	suffixes	'\.\(bnf\)$'
~endwith

; we normally use the builtin values, but this is useful for looking at
; autoconf templates:
~with define-submode c
	mode-filename	'^llib-[\w.]*$'
~endwith

; for Lynx lynx.cfg
define-mode cfg
~with define-submode cfg
	suffixes	'\.cfg$'
	comment-prefix	'^\s*#'
	comments	'^\s*#\s*$'
~endwith

define-mode conf
~with define-submode conf
	suffixes	'\.\(config\|dat\|.*rc\|dsw\|la\)$'
	after		"yacc"
	preamble	'^[#;]'
	comment-prefix	'^\s*[#;]'
	comments	'^\s*[#;]\s*$'
~endwith

define-mode cpp
~with define-submode cpp
	before "c"
	mode-pathname	'.*/include/[cg]++[^/]*/.*'
	~if $filename-ic
		suffixes	'\.\(cc\|cpp\|cxx\|hh\|hpp\|hxx\)$'
	~else
		suffixes	'\.\(cc\|cpp\|cxx\|hh\|hpp\|hxx\|[CH]\|CC\)$'
	~endif
	cindent
	cindent-chars   &cat ':#' $fences
	; exhuberant ctags "--extra=q" can generate fully-qualified class::name
	identifier-expr '[~]\?\<\w\+\>\(::[~]\?\<\w\+\>\)*'
~endwith

; "C#", aka "C-flat" or "C-sharp".
define-mode cs
~with define-submode cs
	suffixes	'\.\(cs\)$'
	cindent
	cindent-chars   &cat ':#' $fences
	tabstop=4
	shiftwidth=4
	dos
	sections='^\(\([{]\)\|\(\s*\(public\|private\|protected\|static\).*[(]\)\)'
~elsewith define-submode cs group 'region'
	fence-if	'^\s*#region\>'
	fence-fi	'^\s*#endregion\>'
~endwith

define-mode csh
~with define-submode csh
	suffixes	'\.\(csh.*\|login\|logout\)$'
	pre '^#!\s*\(\/[^\\]*\)\?csh\>\(\s*-[\a]\+\)*\s*$'
	comment-prefix	'^\s*#'
	comments	'^\s*#\s*$'
	fence-if	'^\s*\<if\>.*\<then\>'
	fence-elif	'^\s*\<else\s*if\>'
	fence-else	'^\s*\<else\>'
	fence-fi	'^\s*\<endif\>'
~elsewith define-submode csh group 'case'
	fence-if	'^\s*\<switch\>\s*(.*)'
	fence-elif	'^\s*\<case\>.*:'
	fence-else	'^\s*\<default\>\s*:'
	fence-fi	'^\s*\<endsw\>'
~elsewith define-submode csh group 'loop'
	fence-if	'^\s*\<foreach\s\+.*\|while\>\s*(.*)'
	fence-fi	'^\s*\<end\>'
~endwith

define-mode css
~with define-submode css
	suffixes	'\.\(css\)$'
	ignorecase
~endwith

; disable wrapping in ".csv" files
define-mode csv
~with define-submode csv
	suffixes	'\.\(csv\)$'
	fillcol=0
	wrapmargin=0
~endwith

define-mode cweb
~with define-submode cweb
	suffixes	'\.\(w\|web\)$'
~endwith

; Fences in DCL do not work well because we really want a fence-if which
; looks for an 'if' on a line where there is no 'then'.  But here is a set of
; expressions that work by relying on matching the if-once first, so it
; excludes the if-block.
define-mode dcl
~with define-submode dcl
	suffixes	'\.\(com\|dcl\|tpu\)$'
	comment-prefix	'^\s*\$!'
	comments	'^\s*\$!\s*$'
	ignorecase
~elsewith define-submode dcl group 'if-once'
	fence-if	'^\s*\(\$\s*\)\?\<if\>.*\<then\>'
~elsewith define-submode dcl group 'if-block'
	fence-if	'^\s*\(\$\s*\)\?\<if\>'
	fence-else	'^\s*\(\$\s*\)\?\<else\>'
	fence-fi	'^\s*\(\$\s*\)\?\<endif\>'
~endwith

define-mode delphi
~with define-submode delphi
~if &sin $os 'win32'
	suffixes	'\.\(dfm\|dpr\|pas\)$'
~else
	suffixes	'\.\(dfm\|dpr\)$'
~endif
	dos
	before "pas"
	ignorecase
; no mistake - pascal fence-fi has no useful marker past the last else
	fence-if   '^\$\s*if\>'
	fence-elif '^\$\s*else\s+if\>'
	fence-fi   '^\$\s*else\>\s*$'
; I would have fences for case statements but there is too much conflict with
; block, etc
~elsewith define-submode delphi group 'unit'
	fence-if	'^\s*\<unit\>'
	fence-fi	'^\s*\<end\>\s*\.'
~elsewith define-submode delphi group 'block'
	fence-if	'^\s*\<begin\|type\>'
	fence-fi	'^\s*\<end\>\s*;'
~elsewith define-submode delphi group 'object'
	fence-if	'^\s*\<object\>'
	fence-fi	'^\s*\<end\>\s*$'
~endwith

define-mode def
~with define-submode def
	suffixes	'\.\(def\)$'
	ignorecase
	dos
~endwith

define-mode diff
~with define-submode diff
	suffixes	'\.\(patch\|dif\|diff\|diffs\|rej\)$'
	mode-filename	'^!\([[:file:]]*diff\|rcshist\).*'
	preamble	'^\(\<diff\>\|\(# patch by\)\|\(Index:\s\+[[:file:]]\+\)\|\(\(---\|\*\*\*\)\s\+[[:file:]]\+.*\d\{4\}\)\|\(^==== .* ==== content$\)\)'
	before conf
~endwith

define-mode docbook
~with define-submode docbook
	before xml
	suffixes	'\.\(docbook\|sgm\|sgml\)$'
	pre		'^\s*<?xml\s.*!DOCTYPE.*DTD DocBook'
	fence-pairs	'<>()[]{}'
	comment-prefix	'^\s*--'
	comments	'^\s*$'
~endwith

define-mode dtd
~with define-submode dtd
	before xml
	suffixes	'\.\(dtd\|ent\)$'
	fence-pairs	'<>()[]{}'
	comment-prefix	'^\s*--'
	comments	'^\s*$'
~endwith

; ECLiPSe (a dialect of Prolog)
define-mode ecl
~with define-submode ecl
	suffixes	'\.\(ecl\|eci\|eco\|pro\)$'
	mode-filename	'\.eclipserc$'
~endwith

; Syntax descriptions for enscript
; NOTE: Smalltalk files also may have ".st" suffix.
define-mode est
~with define-submode est
	suffixes	'\.st$'
	cindent
~endwith

; EmbeddedRuby
define-mode erb
~with define-submode erb
	suffixes	'\.erb$'
~endwith

; Erlang
define-mode erl
~with define-submode erl
	suf '\.[he]rl$'
	comment-prefix	'^\s*%'
~endwith

; Embedded SQL in C/C++
define-mode esql
~with define-submode esql
	after		make
	suffixes	'\.\(ec\|p[ch]\|pp[ch]\)$'
	cindent
	cindent-chars &cat ':#' $fences
~endwith

; forms definition.
; FIXME: The groups should not nest (extend the syntax)
define-mode fdl
~with define-submode fdl
	suffixes	'\.\<fdl\>$'
	comment-prefix '^\s*$rem\>'
	comments   '^\(\|$rem\)$'
	fence-if   '^\$\s*if\>'
	fence-elif '^\$\s*elseif\>'
	fence-else '^\$\s*else\>\s*$'
	fence-fi   '^\$\s*endif\s*$'
~elsewith define-submode fdl group 'form'
	fence-if   '^\$form\>'
	fence-fi   '^\$endform\s*$'
~elsewith define-submode fdl group 'field'
	fence-if   '^\$field\>$'
	fence-fi   '^\$endfield\s*$'
~elsewith define-submode fdl group 'group'
	fence-if   '^\$group\>'
	fence-fi   '^\$endgroup\s*$'
~elsewith define-submode fdl group 'array'
	fence-if   '^\$array\>'
	fence-fi   '^\$endarray\s*$'
~elsewith define-submode fdl group 'page'
	fence-if   '^\$page\>'
	fence-fi   '^\$endpage\s*$'
~elsewith define-submode fdl group 'scroll'
	fence-if   '^\$scroll\>'
	fence-fi   '^\$endscroll\s*$'
~elsewith define-submode fdl group 'state'
	fence-if   '^\$state\>'
	fence-fi   '^\$endstate\s*$'
~elsewith define-submode fdl group 'text'
	fence-if   '^\$text\>'
	fence-fi   '^\$endtext\s*$'
~endwith

define-mode haskell
~with define-submode haskell
	suffixes	'\.\(hs\|lhs\|hsc\)$'
~endwith

; Inherit the C-style fences for JavaScript, but add new ones for HTML
define-mode html
~with define-submode html
	suffixes	'\.\(html\|htm\|shtml\)$'
	pre		'^\s*\(<html>\|<script>\|<!doctype\|<!--\)'
	fence-pairs	'<>()[]{}'
	ignorecase
	comment-prefix	'^\s*--'
	comments	'^\s*$'
~elsewith define-submode html group 'script'
	fence-if	'^\s*<script>$'
	fence-fi	'^\s*</script>$'
~elsewith define-submode html group 'server'
	fence-if	'^\s*<server>$'
	fence-fi	'^\s*</server>$'
~elsewith define-submode html group 'html'
	fence-begin	'<--'
	fence-end	'-->'
~endwith

define-mode midl
~with define-submode midl
	suffixes	'\.\(idl\|odl\)$'
	dos
~endwith

define-mode mcrl
~with define-submode mcrl
	suffixes	'\.\(mcrl\)$'
	fence-pairs     '{}()[]'
	comment-prefix  '^\s*%'
	comments        '^\s*%.*$'
	comments	'^\s*%\s+*$'
~endwith

define-mode mvn
~with define-submode mvn
	before xml
	mode-filename	'pom\([\d.-]\+\)?\.xml'
	suffixes	'\.\(pom\)$'
	pre		'^\s*<?xml\s.*'
	fence-pairs	'<>()[]{}'
	comment-prefix	'^\s*--'
	comments	'^\s*$'
~endwith

define-mode ini
~with define-submode ini
	suffixes	'\.\(ini\|reg\|vbp\|clw\)$'
	ignorecase
	dos
~endwith

define-mode desktop
~with define-submode desktop
	suffixes	'\.\(desktop\)$'
~endwith

define-mode info
~with define-submode info
	after ti
	mode-filename	'^\(\a*\)\(info\(-\d\+\)\?\)$'
	suffixes	'\.\(info\(-\d\+\)\?\)$'
~endwith

define-mode imake
~with define-submode imake
	before "def"
	mode-filename	'^I[Mm]akefile.*$'
	pre '^\s*\(XCOMM\>\|\/\*\*\/#\)'
~endwith

; Inno Setup scripts have semicolon comments except in the Pascal scripting
; area, where it changes to "//" C++ comments, or "{...}" Pascal comments.
; The syntax highlighter knows about that, but format-til is not that smart.
define-mode iss
~with define-submode iss
	suffixes	'\.\(iss\)$'
	ignorecase
	dos
	comment-prefix	'^\s*\(;\|//\)'
	comments	'^\s*\(;\|//\)\s+*$'
~endwith

define-mode java
~with define-submode java
	suffixes	'\.\(java\|jad\)$'
	cindent
	cindent-chars &cat ':' $fences
~endwith

define-mode js
~with define-submode js
	suffixes	'\.\(js\)$'
	cindent
	cindent-chars &cat ':' $fences
~endwith

define-mode json
~with define-submode json
	suffixes	'\.\(json\)$'
	cindent
	cindent-chars &cat ':' $fences
~endwith

define-mode jsp
~with define-submode jsp
	before		"html"
	suffixes	'\.\(jsp\)$'
	cindent
	cindent-chars &cat ':' $fences
	;dos
	;percent-crlf 100
~endwith

define-mode key
~with define-submode key
	suffixes	'\.\(key\|keywords\)$'
	comment-prefix	'^\s*:'
	comments	'^\s*:\s+*$'
~endwith

define-mode latex
~with define-submode latex
	suffixes	'\.\(latex\|ltex\|ltx\|sty\)$'
	fence-pairs='<>{}()[]'
	comment-prefix	'^\s*%'
	comments	'^\s*%.*$'
~endwith

define-mode lex
~with define-submode lex
	suffixes	'\.\(l\|ll\|lex\|flex\|flx\|gperf\)$'
	cindent
	cindent-chars &cat ':#' $fences
~endwith

define-mode lisp
~with define-submode lisp
	suffixes	'\.\(el\|lisp\|lsp\)$'
	fence-pairs='()'
	fence-begin='#|'
	fence-end='|#'
	comment-prefix ';'
~endwith

define-mode log
~with define-submode log
	mode-filename	'^\(run\|\w\?make\).*\.out$'
	suffixes	'\.\(log.*\)$'
	before "make"
~endwith

define-mode lua
~with define-submode lua
	suffixes	'\.\(lua\)$'
	cindent
	cindent-chars &cat ':#' $fences
~endwith

; actually, m4 used for autoconf scripts, which is Bourne-shell
define-mode m4
~with define-submode m4
	preamble   '\(^\s*\(divert(\|dnl\>\)\|-*- Autotest -*-\)'
	suffixes   '\.\(ac\|m4\)$'
	comment-prefix '^\s*\(dnl\|#\)'
	comments   '^\s*\(dnl\>\|#\)\s*$'
	fence-if   '^\s*\<if\>'
	fence-elif '^\s*\<elif\>'
	fence-else '^\s*\<else\>'
	fence-fi   '^\s*\<fi\>'
~elsewith define-submode m4 group 'case'
	fence-if   '^\s*\<case\>.*\<in\>'
	fence-fi   '^\s*\<esac\>'
~elsewith define-submode m4 group 'do'
	fence-if   '\(^\s*\<do\>\|;\s*\<do\>\)\s*$'
	fence-fi   '^\s*\<done\>'
~endwith

define-mode mail
~with define-submode mail
	mode-filename	'^\([Mm]ail\>.*\|\<mbox\|mutt-.*\)$'
	pre '^\(From \|To: \)'
~endwith

define-mode mailcap
~with define-submode mailcap
	mode-filename	'^[.]\?mailcap'
	before	'conf'
~endwith

define-mode make
~with define-submode make
	mode-pathname	'^.*/\(share\|lib\d*\)/pkgconfig/[[:graph:]]\+\.pc$'
	mode-filename	'^\(\(BSD\|GNU\)\?[Mm]akefile.*\|make\..*\|.*\.mak\|.*\.mk\|Jamdefs.*\|Jamfile\)$'
	preamble	'^#!\s*\(\/[^\\]*\)\?\<make\>'
	comment-prefix	'^\s*[!#]'
	comments	'^\s*[!#]\s*$'
	tabinsert
~elsewith define-submode make group 'gnumake'
	fence-if   '^[ ]*if'
	fence-else '^[ ]*else\>'
	fence-fi   '^[ ]*endif\>'
~elsewith define-submode make group 'nmake'
	fence-if   '^\s*!if'
	fence-elif '^\s*!else\s*if'
	fence-else '^\s*!else\>'
	fence-fi   '^\s*!endif\>'
~if &sin $os 'win32'
	ignorecase
~endif
~endwith

define-mode mms
~with define-submode mms
	suffixes	'\.mms$'
	comment-prefix	'^\s*[!#]'
	comments	'^\s*[!#]\s*$'
	ignorecase
	fence-if   '^\s*\.\<ifdef\>'
	fence-elif '^\s*\.\<elif\>'
	fence-else '^\s*\.\<else\>'
	fence-fi   '^\s*\.\<endif\>'
~endwith

; prevent .newsrc from being recognized as a mode that requires syntax
; highlighting, since it may contain very long lines.
define-mode newsrc
~with define-submode newsrc
	suffixes	'\.\(.*newsrc.*\)$'
	before "sh"
~endwith

define-mode nmake
~with define-submode nmake
	suffixes	'\.dsp$'
	dos
	comment-prefix	'^\s*[!#]'
	comments	'^\s*[!#]\s*$'
~with define-submode nmake group 'nmake'
	fence-if   '^\s*!if'
	fence-elif '^\s*!else\s*if'
	fence-else '^\s*!else\>'
	fence-fi   '^\s*!endif\>'
	ignorecase
~endwith
~endwith

define-mode nr
~with define-submode nr
	after		"sh"
	suffixes	'\.\(\([1-9ln][a-z]\?\)\|me\|mm\|ms\|man\|tmac\)$'
	preamble	'^\.\(\\"\|[[:alpha:]]\)'
	comment-prefix	'^\.\\"'
	comments	'^\.\\"\s*$'
~endwith

define-mode nsis
~with define-submode nsis
	suffixes	'\.\(nsi\|nsh\)$'
	ignorecase
	dos
~endwith

define-mode objc
~with define-submode objc
	suffixes	'\.\(m\)$'
~elsewith define-submode objc group 'classes'
	fence-if       '^\s*@\(interface\|implementation\|protocol\).*$'
	fence-fi       '^\s*@end\s*$'
~elsewith define-submode objc group 'try'
	fence-if       '^\s*@try\>.*'
	fence-elif     '^\s*@catch\>.*'
	fence-fi       '^\s*@finally\>.*'
~endwith

define-mode pas
~with define-submode pas
	suffixes	'\.\(p\|pas\|pp\)$'
~endwith

define-mode pc
~with define-submode pc
	mode-filename	'^\(\<printcap.*\)$'
	comment-prefix	'^\s*[:#]'
	comments	'^\s*[:#]\s*$'
~endwith

; 'do' should really be a separate group, but since ambiguous fence-fi is
; very expensive to resolve, we combine it with the similar 'while' group.
define-mode perl
~with define-submode perl
	preamble	'^#!\s*\(\/[^\\]*\)\?\<perl[0-9]*\>'
	suffixes	'\.\(pl\|pm\|PL\|pod\)$'
	mode-pathname	'^.*perl.*\.t$'
	before		"mail"
	cindent
	cindent-chars  &cat ':' $fences
	comment-prefix '^\s*#'
	comments       '^\s*#\s*$'
	fence-pairs    '{}()[]<>'
	fence-if       '^\s*if\>.*{'
	fence-elif     '^\s*}\s*elsif\s*(.*{'
	fence-else     '^\s*}\s*else\s*{'
	fence-fi       '^\s*}\s*$'
;- The trailing "}" in the different perl groups makes it ambiguous and not
;- easy to use (so they're commented out).  Note that the default (if) group
;- still relies on having the "}" on the same lines as the elsif and else
;- keywords.
;~elsewith define-submode perl group 'while'
;	fence-if       '^\s*\(sub\|foreach\|while\|unless\|do\)\>.*{'
;	fence-fi       '^\s*}'
~endwith

define-mode php
~with define-submode php
	suffixes	'\.\(php\)$'
	preamble	'\(<?php\)\|\(^#!\s*\(\/[^\\]*\)\?\<php\>\(\s*-[\a]\+\)*\s*$\)'
~endwith

; gettext message files
define-mode pot
~with define-submode pot
	suffixes	'\.\(pot\|po\)$'
	comment-prefix '^#'
	comments       '^#\s*$'
~endwith

define-mode powershell
~with define-submode powershell
	suffixes	'\.\(ps1\)$'
	ignorecase
	comment-prefix	'^\s*#'
	comments	'^\s*#\s\+\s*$'
~endwith

define-mode prolog
~with define-submode prolog
	before perl
	qualifiers=all
	pre '^\s*\(\/\*\|%\|:-\)'
	mode-filename	'.plrc$'
	suffixes	'\.pl$'
~endwith

; PostScript
define-mode ps
~with define-submode ps
	suffixes	'\.ps$'
~endwith

; Python
define-mode py
~with define-submode py
	pre '^\(\(#!\s*\(\/[^\\]*\)\?\<python[\d_.-]*\>\)\(\(\s*[-]\+[\a]*\s*\)\?\|:\)\)\s*$'
	suffixes	'\.py$'
	comment-prefix '^\s*#'
	comments   '^\s*#\s\+\s*$'
	tabstop=8
	shiftwidth=4
~endwith

; Ruby
define-mode rb
~with define-submode rb
	pre '^#!\s*\(\/[^\\]*\)\?\<ruby[0-9]*\>'
	suffixes	'\.rb$'
~endwith

define-mode rc
~with define-submode rc
	after "vile"
	suffixes	'\.rc\d*$'
	preamble	'^\s*[^;"]'
	qualifiers=all
	comment-prefix	'^\s*//'
	comments	'^\s*//\s*$'
~endwith

define-mode rexx
~with define-submode rexx
	pre '^#!\s*\(\/[^\\]*\)\?\<\(rexx\|regina\|rxcurses\|r\)\>'
	suffixes	'\.\(cmd\|rexx\)$'
	~if &not &seq $os "win32"
		before "bat"
	~endif
	comment-prefix '^\s*#'
	comments   '^\s*#\s\+\s*$'
~endwith

; I capitalized the majormode RCS/SCCS names because matches are made in
; alphabetic order (usually not a problem, but conflicting with other modes,
; such as 'makemode').  Comma is normally not part of a filename, except for
; RCS archives.
define-mode RCS
~with define-submode RCS
	mode-filename	'^[\w_.-]\+,v$'
~endwith

define-mode rpm
~with define-submode rpm
	suffixes	'\.spec$'
	fence-if	'^\s*%if\>'
	fence-else	'^\s*%else\>'
	fence-fi	'^\s*%endif\>'
~endwith

define-mode rtf
~with define-submode rtf
	preamble	'^{\\rtf\d'
	suffixes	'\.rtf$'
	dos
	notabinsert
~endwith

; (see RCS)
define-mode SCCS
~with define-submode SCCS
	mode-filename	'^s\.'
	pre '^\h'
~elsewith define-submode SCCS group 'delete'
	fence-if       '^\D\s\+\(\d\+\)$'
	fence-fi       '^\E\s\+\(\d\+\)$'
~elsewith define-submode SCCS group 'insert'
	fence-if       '^\I\s\+\(\d\+\)$'
	fence-fi       '^\E\s\+\(\d\+\)$'
~endwith

define-mode scheme
~with define-submode scheme
	suffixes	'\.\(scm\|ss\)$'
	fence-pairs	'[]()'
	fence-begin	'#|'
	fence-end	'|#'
	comment-prefix	';'
~endwith

define-mode sed
~with define-submode sed
	suffixes	'\.\(sed\)$'
	pre '^#!\s*\(\/[^\\]*\)\?\<sed\>\(\s*-[\a]*\s*\)\*\s*$'
	comment-prefix	'^\s*#'
	comments	'^\s*#\s*$'
~endwith

; This is matched after 'csh', and will pick up /bin/sh, /bin/bash
; FIXME "Jamrules" is something like sh, but uses different rules for "^", etc.
define-mode sh
~with define-submode sh
	mode-filename	'^\(\.profile\|Jamrules\)$'
	suffixes	'\(\.\(sh\|shar\|.*shrc\)$\)'
	preamble	'^\(\(#!\s*\(\/[^\\]*\)\?sh\>\(\s*[-]\+[\a]*\s*\)\?\)\|:\)\s*$'
	comment-prefix	'^\s*[:#]'
	comments	'^\s*[:#]\s*$'
	fence-if	'^\s*\<if\>'
	fence-elif	'^\s*\<elif\>'
	fence-else	'^\s*\<else\>'
	fence-fi	'^\s*\<fi\>'
~elsewith define-submode sh group 'case'
	fence-if	'^\s*\<case\>.*\<in\>'
	fence-elif	'^\s*[^ 	)]\+)'
	fence-else	'^\s*\*)'
	fence-fi	'^\s*\<esac\>'
~elsewith define-submode sh group 'do'
	fence-if	'\(^\s*\<do\>\|;\s*\<do\>\)\s*$'
	fence-fi	'^\s*\<done\>'
~endwith

derive-mode bash sh
~with define-submode bash
	before sh
	mode-filename	'^\(\.bash_[a-z]\+$\)'
	suffixes	'\(\.\(bash_[a-z]\+$\|ebuild\)\)'
	preamble	'^\(\(#!\s*\(\/[^\\]*\)\?bash\>\(\s*[-]\+[\a]*\s*\)\?\)\|:\)\s*$'
~endwith

derive-mode ksh sh
~with define-submode ksh
	before bash
	mode-filename	'^\([a-z.-]*kshrc\)$'
	suffixes	'\(\.\(ksh\)$\)'
	preamble	'^\(\(#!\s*\(\/[^\\]*\)\?ksh\>\(\s*[-]\+[\a]*\s*\)\?\)\|:\)\s*$'
~endwith

derive-mode zsh sh
~with define-submode zsh
	before bash
	mode-filename	'^\(\.\)?z\(shenv\|profile\|shrc\|login\|logout\)$'
	suffixes	'\(\.\(zsh\)$\)'
	preamble	'^\(\(#!\s*\(\/[^\\]*\)\?zsh\>\(\s*[-]\+[\a]*\s*\)\?\)\|:\)\s*$'
~endwith

define-mode sml
~with define-submode sml
	suffixes	'\.sml$'
	comment-prefix	'^\s*[*]'
	fence-begin="(\\*"
	fence-end="\\*)"
~endwith

define-mode sql
~with define-submode sql
	before "bat"
	suffixes	'\.\(ddl\|sql\|pks\|pkb\|pkg\|pls\|plb\|fnc\)$'
	pre '^\s*\(rem\>.*$\|remark\>.*$\|set\s\+echo\s\+\(on\|off\)\?$\)'
	comment-prefix	'^\s*rem\(ark\)\?'
	comments	'^\s*rem\(ark\)\?\s*$'
	ignorecase
	; PL/SQL
	fence-if   '^\s*if\>'
	fence-elif '^\s*elseif\>'
	fence-else '^\s*else\>\s*$'
	fence-fi   '^\s*end\s\+if\s*;'
~elsewith define-submode sql group 'loop'
	fence-if   '^\s*while\>.*\<loop\>'
	fence-fi   '^\s*end\s\+loop\s*;'
~elsewith define-submode sql group 'block'
	fence-if   '^\s*begin\>'
	fence-else '^\s*exception\>'
	fence-fi   '^\s*end\s*;'
~endwith

define-mode tags
~with define-submode tags
	mode-filename	'^tags$'
	comment-prefix	'^!_'
	comments	'^!_$'
~endwith

; VILE's mktbls
define-mode tbl
~with define-submode tbl
	mode-filename	'^\(modetbl\|cmdtbl\)$'
	comment-prefix	'^\s*#'
	comments	'^\s*#\s*$'
~endwith

define-mode tc
~with define-submode tc
	mode-filename	'^termcap.*$'
	suffixes	'\.\(tc\|tcap\|termcap\)$'
	comment-prefix	'^\s*[:#]'
	comments	'^\s*[:#]\s*$'
~endwith

; DCE uses Tcl - http://www.opengroup.org/tech/rfc/rfc68.2.html
define-mode tcl
~with define-submode tcl
	before "sh"
	suffixes	'\.\(tcl\|exp\|psm\)$'
	pre '^#!\s*\(\/[^\\]*\)\?\<\(dcecp\|wish\|wishx\|tclsh\|tcl\|expectk\)[0-9.]*\>\(\s*-[\a]\+\)*\s*$'
	comment-prefix	'^\s*[:#]'
	comments	'^\s*[:#]\s*$'
~endwith

define-mode tex
~with define-submode tex
	suffixes	'\.\(tex\)$'
	fence-pairs='<>{}()[]'
	comment-prefix	'^\s*%'
	comments	'^\s*%.*$'
~endwith

define-mode texi
~with define-submode texi
	suffixes	'\.\(texi\|txi\|texinfo\)$'
~endwith

define-mode ti
~with define-submode ti
	before "sh"
	preamble	'^#\s*Reconstructed via infocmp'
	mode-filename	'^\<terminfo\(\.src\)\?$'
	suffixes	'\.\(ti\|tic\|tinfo\|terminfo\)$'
	comment-prefix	'^\s*[:#]'
	comments	'^\s*[:#]\s*$'
~endwith

define-mode txt
~with define-submode txt
	mode-filename	'^\(\(TODO\|\(\(.*-\)\?README\)\|CHANGES\|[Cc]hange[Ll]og\|COPYING\).*\)$'
	preamble	'-\*- text -\*-'
	suffixes	'\.\(txt\|doc\|hlp\)$'
	comment-prefix	'^\s*--'
	comments	'^\s*--\s*$'
~endwith

~local %vb-access
setv %vb-access '^\s*\(\(Public\|Private\|Protected\|Friend\|Overloads\|Overridable\|Overrides\|Static\|Shared\)\s\+\)*'

define-mode vb
~with define-submode vb
	before		"basic"
	suffixes	'\.\(vb\)$'
	qualifiers=all
	comment-prefix	"^\\s*'"
	comments	"^\\s*'\\s\\+\\s*$"
	dos
	ignorecase
	notabinsert
	tabstop=4
	shiftwidth=4
	; disallow continuation lines, or if-then-statement lines
	fence-if	"^\\s*if\\>.*\\<then\\>\\(\\s*\'.*\\)\\?$"
	fence-elif	'^\s*elseif\>'
	fence-else	'^\s*else\>'
	fence-fi	'^\s*end\s\+if\>'
	sections	&cat %vb-access '\(Sub\|Function\|Property\|Enum\)'
~elsewith define-submode vb group 'for-loop'
	fence-if	'^\s*for\>'
	fence-fi	'^\s*next\>'
~elsewith define-submode vb group 'while-loop'
	fence-if	'^\s*while\>'
	fence-fi	'^\s*wend\>'
~elsewith define-submode vb group 'with'
	fence-if	'^\s*with\>'
	fence-fi	'^\s*end\s\+with\>'
~elsewith define-submode vb group 'case'
	fence-if	'^\s*\<select\s\+case\>'
	fence-elif	'^\s*\<case\>'
	fence-else	'^\s*\<case\s\+else\>'
	fence-fi	'^\s*\<end\s\+select\>'
~elsewith define-submode vb group 'sub'
	fence-if	&cat %vb-access 'sub\>'
	fence-fi	'^\s*end\s\+sub\>'
~elsewith define-submode vb group 'function'
	fence-if	&cat %vb-access 'function\>'
	fence-fi	'^\s*end\s\+function\>'
~elsewith define-submode vb group 'property'
	fence-if	&cat %vb-access 'property\>'
	fence-fi	'^\s*end\s\+property\>'
~elsewith define-submode vb group 'try'
	fence-if	'^\s*try\>'
	fence-elif	'^\s*catch\>'
	fence-else	'^\s*finally\>'
	fence-fi	'^\s*end\s\+try\>'
~elsewith define-submode vb group 'class'
	fence-if	'^\s*class\>'
	fence-fi	'^\s*end\s\+class\>'
~elsewith define-submode vb group 'region'
	fence-if	'^\s*#region\>'
	fence-fi	'^\s*#end\s\+region\>'
~endwith

~local %vb6-access
setv %vb6-access '^\(\(Public\|Private\|Protected\|Friend\)\s\+\)*'

define-mode vb6
~with define-submode vb6
	before		"basic"
	suffixes	'\.\(bas\|cls\|ctl\|frm\|dsr\)$'
	pre		'\(^VERSION\|VB_Name\)'
	qualifiers=all
	comment-prefix	"^\\s*'"
	comments	"^\\s*'\\s\\+\\s*$"
	dos
	ignorecase
	notabinsert
	tabstop=4
	shiftwidth=4
	; disallow continuation lines, or if-then-statement lines
	fence-if	"^\\s*if\\>.*\\<then\\>\\(\\s*\'.*\\)\\?$"
	fence-elif	'^\s*elseif\>'
	fence-else	'^\s*else\>'
	fence-fi	'^\s*end\s\+if\>'
	sections	&cat %vb6-access '\(Sub\|Function\|Property\)'
~elsewith define-submode vb6 group 'for-loop'
	fence-if	'^\s*for\>'
	fence-fi	'^\s*next\>'
~elsewith define-submode vb6 group 'while-loop'
	fence-if	'^\s*while\>'
	fence-fi	'^\s*wend\>'
~elsewith define-submode vb6 group 'sub'
	fence-if	&cat %vb6-access 'sub\>'
	fence-fi	'^\s*end\s\+sub\>'
~elsewith define-submode vb6 group 'function'
	fence-if	&cat %vb6-access 'function\>'
	fence-fi	'^\s*end\s\+function\>'
~elsewith define-submode vb6 group 'property'
	fence-if	&cat %vb6-access 'property\>'
	fence-fi	'^\s*end\s\+property\>'
~elsewith define-submode vb6 group 'with'
	fence-if	'^\s*with\>'
	fence-fi	'^\s*end\s\+with\>'
~elsewith define-submode vb6 group 'case'
	fence-if	'^\s*\<select\s\+case\>'
	fence-elif	'^\s*\<case\>'
	fence-else	'^\s*\<case\s\+else\>'
	fence-fi	'^\s*\<end\s\+select\>'
~endwith

derive-mode vbs vb6
~with define-submode vbs
	before		"basic"
	suffixes	'\.\(vbs\)$'
	comment-prefix	"^\\s*'"
~endwith
remove-submode vbs preamble

define-mode vlog
~with define-submode vlog
	suffixes	'\.v$'
	cindent
	cindent-chars $fences
~endwith

; "define-mode vile" is builtin
~with define-submode vile
	before "sh"
	mode-pathname	'\(vile.*/.*rc\)$'
	mode-filename	'^\(\.\?vile.*rc\)$'
	suffixes	'\.\(exrc\|vile\)$'
	comment-prefix	'^\s*;'
	comments	'^\s*;\s*$'
	fence-if	'^\s*~if\>'
	fence-elif	'^\s*~elseif\>'
	fence-else	'^\s*~else\>'
	fence-fi	'^\s*~endif\>'
	sections	'^\s*\(define-mode\|\(\d\+\s*\)\?\(store-\(macro\|procedure\|operator\)\)\)'
~elsewith define-submode vile group 'while'
	fence-if	'^\s*~while\>'
	fence-fi	'^\s*~endwhile\>'
~elsewith define-submode vile group 'with'
	fence-if	'^\s*~with\>'
	fence-elif	'^\s*~elsewith\>'
	fence-fi	'^\s*~endwith\>'
~elsewith define-submode vile group 'macro'
	fence-if	'^\s*\(\d\+\s*\)\?store-\(macro\|procedure\|operator\)'
	fence-fi	'^\s*~endm\>'
~endwith

define-mode vim
~with define-submode vim
	suffixes	'\.\(vim\|vimrc\)$'
	comment-prefix	'^\s*"'
	before "make"
	comments	'^\s*"\s*$'
	fence-if	'^\s*if\>'
	fence-elif	'^\s*elseif\>'
	fence-else	'^\s*else\>'
	fence-fi	'^\s*endif\>'
~elsewith define-submode vim group 'while'
	fence-if	'^\s*while\>'
	fence-fi	'^\s*endwhile\>'
~elsewith define-submode vim group 'function'
	fence-if	'^\s*function\>'
	fence-fi	'^\s*endfunction\>'
~endwith

define-mode wbt
~with define-submode wbt
	suffixes	'\.\(wbt\)$'
	ignorecase
~endwith

define-mode xq
~with define-submode xq
	suffixes	'\.\(xq\|xqy\|xquery\)$'
	fence-pairs	'<>()[]{}'
	comment-prefix	'^\s*--'
	comments	'^\s*$'
~endwith

define-mode xml
~with define-submode xml
	suffixes	'\.\(xml\)$'
	pre		'^\s*<?xml\s'
	fence-pairs	'<>()[]{}'
	comment-prefix	'^\s*--'
	comments	'^\s*$'
~endwith

define-mode xpm
~with define-submode xpm
	suffixes	'\.\(xpm\|xbm\)$'
	preamble	'\s*\/\* XPM \*\/\s*$'
	cindent
	cindent-chars &cat ':' $fences
~endwith

define-mode xres
~with define-submode xres
	mode-filename	'^\(!appres\)\|\(\.\(Xdefaults\|xmodmap\)\(-.\+$\)\?\)$'
	suffixes	'\.\(ad\)$'
	~if &not $filename-ic
		mode-pathname	'\(app-defaults/[A-Z][A-Z0-9]*\([a-z0-9-][A-Z]\?\.\?\)\+\)$'
	~endif
	comment-prefix	'^\s*!'
	comments	'^\s*!\s*$'
~endwith

define-mode xs
~with define-submode xs
	suffixes	'\.xs$'
	cindent
	cindent-chars &cat ':' $fences
~endwith

define-mode xsl
~with define-submode xsl
;	qualifiers=all
	before		xml
	suffixes	'\.\(xsl\|xslt\|xsd\)$'
;	pre		'^\s*<?xml\s'
	fence-pairs	'<>()[]{}'
	comment-prefix	'^\s*--'
	comments	'^\s*$'
~endwith

define-mode yacc
~with define-submode yacc
	suffixes	'\.\(y\|yy\|yacc\)$'
	cindent
	cindent-chars &cat ':#' $fences
~endwith
