; $Id: filters.rc,v 1.210 2007/10/21 19:22:26 tom Exp $
; majormodes in this file are ordered alphabetically for convenience - the
; precedence used by vile is strictly alphabetic, counting case.

; This file depends upon modes.rc, which may have been source'd by vileinit.rc
; so we will check if it was not source'd.
~if &error %filters-modes
	source modes.rc
~elseif &seq %filters-modes ''
	source modes.rc
~endif
unsetv %filters-modes

define-mode cpp
~with define-submode cpp
	filtername	'vile-c-filt -k cpp'
~endwith

define-mode cs
~with define-submode cs
	filtername	'vile-c-filt -k cs'
~endwith

define-mode csh
~with define-submode csh
	filtername	'vile-sh-filt -k csh'
~endwith

; using txt filter will highlight quoted strings
define-mode csv
~with define-submode csv
	filtername	'vile-txt-filt'
~endwith

define-mode delphi
~with define-submode delphi
	filtername	'vile-pas-filt -k delphi'
~endwith

define-mode docbook
~with define-submode docbook
	filtername	'vile-xml-filt -k docbook'
~endwith

define-mode java
~with define-submode java
	filtername	'vile-c-filt -j -p -k java'
~endwith

define-mode js
~with define-submode js
	filtername	'vile-c-filt -j -s -p -k js'
~endwith

define-mode jsp
~with define-submode jsp
	filtername	'vile-html-filt -j'
~endwith

define-mode latex
~with define-submode latex
	filtername	'vile-latex-filt -a'
~endwith

define-mode nmake
~with define-submode nmake
	filtername	'vile-make-filt'
~endwith

define-mode nsis
~with define-submode nsis
	filtername	'vile-conf-filt -k nsis'
~endwith

define-mode pc
~with define-submode pc
	filtername	'vile-tc-filt -k pc'
~endwith

define-mode rb
~with define-submode rb
	filtername	'vile-ruby-filt -k rb'
~endwith

define-mode RCS
~with define-submode RCS
	filtername	'vile-rcs-filt'
~endwith

define-mode SCCS
~with define-submode SCCS
	filtername	'vile-sccs-filt'
~endwith

~with define-submode scheme
	filtername	'vile-lisp-filt -k scheme'
~endwith

define-mode tex
~with define-submode tex
	filtername	'vile-latex-filt -k tex'
~endwith

define-mode vb
~with define-submode vb
	filtername	'vile-basic-filt -k vb'
~endwith

define-mode vbs
~with define-submode vbs
	filtername	'vile-basic-filt -k vb'
~endwith

define-mode vim
~with define-submode vim
	filtername	'vile-vile-filt -k vim'
~endwith

define-mode xpm
~with define-submode xpm
	filtername	'vile-c-filt'
~endwith

store-procedure HighlightFilter 'Invoke syntax-highlighting filter on the current buffer'
    ~if &not $highlight
	~return
    ~elseif &seq $majormode ''
	~return
    ~elseif &filter $majormode
	~local $curcol $curline
	~hidden goto-beginning-of-file
	~hidden attribute-directly end-of-file $majormode
	~return
    ~else
	~local $curcol $curline
	~local %filtername %filterpath %filteropts
	~hidden goto-beginning-of-file
	~if &seq $filtername ''
		set-variable %filtername &cat &cat 'vile-' $majormode '-filt'
	~else
		set-variable %filtername $filtername
	~endif
	set-variable %filterpath &word 0 %filtername
	set-variable %filteropts &right %filtername &add 1 &len %filterpath
	~if &seq '' &lookup e+p &cat %filterpath $exec-suffix
		set-variable %filterpath &lookup e+l &cat %filterpath $exec-suffix
	~endif
	~if &not &seq %filterpath ''
		~hidden attribute-from-filter end-of-file &cat &pquote %filterpath &cat %filteropts &cat ' -t' $tabstop
	~endif
    ~endif
~endm
store-procedure HighlightFilterMsg 'Attach highlighting to the current buffer'
	HighlightFilter
	write-message '[Attaching attributes...]'
~endm
bind-key HighlightFilterMsg ^X-q

store-procedure HighlightClear 'Clear all highlighting from the current buffer'
	~local $curcol $curline
	~hidden goto-beginning-of-file
	~hidden clear-attributes-til goto-char
~endm
bind-key HighlightClear ^X-Q

store-procedure set-highlighting ma 'Set a majormode and invoke highlighting'
	; show-variables
	write-message $1
	~force setl $1
	HighlightFilter
~endm

; Normally filtermsgs is off since it would slow down autocolor.  This macro
; turns it on temporarily to create an error-buffer which can be used to walk
; through the syntax errors.
store-procedure show-filtermsgs 'Show syntax-filter error messages for current buffer'
	~local $filtermsgs $highlight
	set highlight
	~if &not $highlight
		write-message 'Cannot setup highlighting'
	~elseif &seq $majormode ''
		write-message 'No majormode is associated with this buffer'
	~elseif &filter $majormode
		set filtermsgs
		; make sure there are no prior results to confuse us
		~if &isa buffer '[Filter Messages]'
			~quiet ~hidden kill-buffer '[Filter Messages]'
		~endif
		HighlightFilter
		~if &isa buffer '[Filter Messages]'
			popup-buffer '[Filter Messages]'
			goto-beginning-of-file
			error-buffer '[Filter Messages]'
		~else
			write-message 'No messages found'
		~endif
	~else
		write-message 'This only works for built-in filters'
	~endif
~endm

; If we have built-in filters, and colors are available, simply turn on
; the syntax highlighting.
~if &and \
	&not &error $filter-list \
	&not &error $ncolors
	setv $read-hook HighlightFilter
	set autocolor=5000
	setv $autocolor-hook HighlightFilter
~endif
