; $Id: filters.rc,v 1.54 1999/04/17 15:40:09 tom Exp $

define-mode ada
~with define-submode ada
	suf "\\.\\(\\<ada\\>\\|\\<ads\\>\\|\\<adb\\>\\)$"
	comment-prefix	"^\\s*--"
	comments	"^\\s*--\\s*$"
	fence-if   "^\\s*\\<if\\>"
	fence-elif "^\\s*\\<elsif\\>"
	fence-else "^\\s*\\<else\\>"
	fence-fi   "^\\s*\\<end\\>"
	ignorecase
~elsewith define-submode ada group "begin"
	fence-if   "^\\s*\\<begin\\>"
	fence-else "^\\s*\\<exception\\>"
	fence-fi   "^\\s*\\<end\\>"
~endwith

define-mode awk
~with define-submode awk
	suf "\\.awk$"
	pre "^#!\\s*\\/.*awk\\>\\(\\s*-[a-z]\\+\\)*$"
	comment-prefix "^\\s*#"
	comments   "^\\s*#\\s\\+\\s*$"
~endwith

define-mode bat
~with define-submode bat
	suf "\\.bat$"
	pre "\\s*(@)\\?echo\\s*(on|off)\\?$"
	dos
	ignorecase
	comment-prefix "^\\s*rem\>"
	comments   "^\\s*rem\>\\s\\+\\s*$"
~endwith

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

define-mode csh
~with define-submode csh
	suf "\\.csh*"
	pre "^#!\\s*\\/.*csh\\>\\(\\s*-[a-z]\\+\\)*$"
	filtername	"vile-sh-filt -k csh"
	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\\>(.*)"
	fence-elif	"^\\s*\\<case\\>.*:"
	fence-else	"^\\s*\\<default\\>\\s*:"
~elsewith define-submode csh group "loop"
	fence-if	"^\\s*\\<foreach\\|while\\>(.*)"
	fence-fi	"^\\s*\\<end\\>"
~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
	suf "\\.com$"
	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 diff
~with define-submode diff
	suf "\\.\\(patch\\|diff\\)$"
	pre "^\\<diff\\>"
~endwith

; Inherit the C-style fences for JavaScript, but add new ones for HTML
define-mode html
~with define-submode html
	suf "\\.\\(html\\|htm\\)$"
	pre "\\(<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 imake
~with define-submode imake
	suf "I[Mm]akefile"
	pre "^\\s*XCOMM\\>"
	filtername "vile-c-filt -k imake"
~endwith
	
define-mode java
~with define-submode java
	suf "\\.java$"
	filtername "vile-c-filt -k java"
	cindent
~endwith

define-mode js
~with define-submode js
	suf "\\.js$"
	filtername "vile-c-filt -k js"
	cindent
~endwith

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

define-mode latex
~with define-submode latex
	suf "\\.\\(latex\\|ltex\\|tex\\)$"
	comment-prefix	"^\\s*%"
	comments	"^\\s*%.*$"
~endwith

define-mode lex
~with define-submode lex
	suf "\\.\\(l\\|lex\\|flex\\|flx\\)$"
	cindent
~endwith

; actually, m4 used for autoconf scripts, which is Bourne-shell
define-mode m4
~with define-submode m4
	pre "^\\s*dnl\\>"
	suf "\\.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\\>"
~endwith

define-mode mail
~with define-submode mail
	suf "\\([Mm]ail\\>\\|\\<mbox$\\)"
	pre "^\\(From \\|To: \\)"
~endwith

define-mode make
~with define-submode make
	suf "\\([Mm]akefile\\|\\.mak$\\|\\.mk$\\)"
	comment-prefix	"^\\s*[!#]"
	comments	"^\\s*[!#]\\s*$"
~if &sin $os "win32"
	ignorecase
~elsewith define-submode make group "nmake"
	fence-if   "^\\s*!if"
	fence-elif "^\\s*!elseif"
	fence-else "^\\s*!else\\>"
	fence-fi   "^\\s*!endif\\>"
~endif
~endwith

define-mode mms
~with define-submode mms
	suf "\\.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

define-mode nr
~with define-submode nr
	suf "\\.\\(\\([1-9ln][a-z]\\?\\)\\|man\\)$"
	pre "^\\.\\\\\""
	comment-prefix	"^\\.\\\\\""
	comments	"^\\.\\\\\"\\s*$"
~endwith

define-mode pas
~with define-submode pas
	suf "\\.\\(p|pas\\)$"
~endwith

define-mode perl
~with define-submode perl
	pre "^#\\s*!\\s*\\/.*perl\\>"
	suf "\\.\\(pl\\|pm\\)$"
	cindent
	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*$"
~elsewith define-submode perl group "while"
	fence-if       "^\\s*\\(while\\|unless\\)\\>.*{"
	fence-fi       "^\\s*}\\s*$"
~elsewith define-submode perl group "do"
	fence-if       "^\\s*do\\>.*{"
	fence-fi       "^\\s*}"
~endwith

define-mode sccs
~with define-submode sccs
	suf "\\<s\\."
	pre "^\\001h"
~elsewith define-submode sccs group "delete"
	fence-if       "^\\001D\\s\\+[0-9]\\+$"
	fence-fi       "^\\001E\\s\\+[0-9]\\+$"
~elsewith define-submode sccs group "insert"
	fence-if       "^\\001I\\s\\+[0-9]\\+$"
	fence-fi       "^\\001E\\s\\+[0-9]\\+$"
~endwith

; This is matched after "csh", and will pick up /bin/sh, /bin/bash, /bin/ksh
define-mode sh
~with define-submode sh
	suf "\\.sh$"
	pre "^#!\\s*\\/.*sh\\>\\s*\\(-[a-z]\\+\\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

define-mode sql
~with define-submode sql
	suf "\\.sql$"
	pre "^\\s*\\remark\\>$"
	comment-prefix	"^\\s*rem\\(ark\\)\\?"
	comments	"^\\s*rem\\(ark\\)\\?\\s*$"
	ignorecase
~endwith

define-mode tc
~with define-submode tc
	suf "\\(\\.tc\\|\\<termcap[^/]*\\)$"
	comment-prefix	"^\\s*[:#]"
	comments	"^\\s*[:#]\\s*$"
~endwith

define-mode tcl
~with define-submode tcl
	suf "\\(\\.tcl\\)$"
	pre "^#!\\s*\\/.*wish\\>\\(\\s*-[a-z]\\+\\)*$"
	comment-prefix	"^\\s*[:#]"
	comments	"^\\s*[:#]\\s*$"
~endwith

define-mode ti
~with define-submode ti
	suf "\\(\\.ti\\|\\<terminfo[^/]*\\)$"
	comment-prefix	"^\\s*[:#]"
	comments	"^\\s*[:#]\\s*$"
~endwith

define-mode txt
~with define-submode txt
	suf "\\.\\(txt\\|doc\\|hlp\\)$"
	comment-prefix	"^\\s*--"
	comments	"^\\s*--\\s*$"
~endwith

; define-mode vile
~with define-submode vile
	suf "\\(\\.vilerc\\|\\.rc$\\)"
	comment-prefix	"^\\s*;"
	comments	"^\\s*;\\s*$"
	fence-if	"\\s*~if\\>"
	fence-elif	"\\s*~elseif\\>"
	fence-else	"\\s*~else\\>"
	fence-fi	"\\s*~endif\\>"
~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\\)"
	fence-fi	"\\s*~endm\\>"
~endwith

define-mode yacc
~with define-submode yacc
	suf "\\.\\(y\\|yacc\\)$"
	cindent
~endwith

store-procedure HighlightFilter
    ~if &not &seq $majormode ""
	~local $curcol $curline
	~local %filtername
	~hidden goto-beginning-of-file
	~if &seq $filtername ""
		set-variable %filtername &cat &cat "vile-" $majormode "-filt"
		~hidden attribute-from-filter end-of-file %filtername
	~else
		~hidden attribute-from-filter end-of-file $filtername
	~endif
    ~endif
~endm
store-procedure HighlightFilterMsg
	HighlightFilter
	write-message "[Attaching attributes...]"
~endm
bind-key HighlightFilterMsg ^X-q
