3 " Maintainer: Jacob Nevins <jacobn+vim@chiark.greenend.org.uk>
6 " Version: $Id: halibut.vim,v 1.3 2004/04/01 22:21:23 jtn Exp $
8 " I'm not proud of this. Every time I tangle with vim's syntax highlighting
9 " I come away unsatisfied. Nevertheless, it seems to work.
10 " I have no idea if it's compatible with vim <6.1.
12 " Based on docs in Halibut CVS 2004-03-31
14 " Rune from vim 6.1 help
15 " For version 5.x: Clear all syntax items
16 " For version 6.x: Quit when a syntax file was already loaded
19 elseif exists("b:current_syntax")
23 " Halibut is case-sensitive.
26 " Fallbacks -- if these characters are seen in text and not caught by
27 " anything below, it's probably a syntax violation.
28 syn match butIllegalChar "{"
29 syn match butIllegalChar "}"
30 syn match butIllegalChar "\\"
32 " Simple-minded fallback to highlight any command we don't recognise,
33 " and assume it has textual arguments.
34 " XXX highlights all of "\date)."
35 syn match butCmdGeneric "\\\(\S\&[^{}\\]\)\+" nextgroup=butTextArg
38 syn cluster butText contains=butLiteral,@butCmd,butTodo
40 syn match butLiteral "\\[-{}_.\\]"
42 " This isn't specific to Halibut, but is often useful.
43 syn keyword butTodo XXX FIXME TODO
45 " Specific processing comes after the generic stuff above.
47 " Paragraph level stuff.
49 " Literals -- might need to come before \e{}, \c{}
50 syn region butQuoteLit matchgroup=butCmdSpecific start="\\c\_s\@=" matchgroup=NONE end="$"
51 syn region butQLEmph matchgroup=butCmdSpecific start="\\e\_s\@=" matchgroup=NONE end="$" contains=butQLEmphInv
52 " Highlight invalid characters in emphasis line, cos I'll never remember.
53 syn match butQLEmphInv "\S\@=[^bi]" contained
55 " Paragraph level comment -- might need to come before inline comment.
56 syn region butCommentPara start="\\#\_s\@=" end="^\s*$" contains=butTodo
58 " Inline comments -- nested braces are honoured.
59 syn region butComment matchgroup=Comment start="\\#{" end="}" contains=butCommentBrace,butTodo
60 syn region butCommentBrace start="{" end="}" contains=butCommentBrace,butTodo contained transparent
62 " Section headings - a bit hairy. Order wrt rest of file is important.
63 syn match butCmdSpecific "\\\(S\d\|[CAHSU]\)" nextgroup=butIdentArgH
64 " butIdentArgH -> butTextArgH? -> this, which highlights the rest of the para:
65 syn region butTextHeading start="" end="^\s*$" contained contains=@butText
66 " ...and overall title
67 syn match butCmdSpecific "\\title" nextgroup=butTextHeading
70 syn match butCmdSpecific "\\\(b\|n\|dd\)" nextgroup=butIdentArg
73 syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
76 syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
77 syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
78 syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
81 syn match butCmdSpecific "\\define{\@=" nextgroup=butIdentArg
83 " Specific inline commands
84 " (Some of these are defined out of paranoia about clashes with code quotes.)
86 syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
87 syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
88 syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
89 syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
90 " Indexing -- invisible entries.
91 syn match butCmdSpecific "\\I{\@=" nextgroup=butIndexArg
93 syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
94 " Unicode literal -- a bit special.
95 syn match butLiteral "\\u\x*" nextgroup=butTextArg
98 syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,ButComment
100 " Types of argument. XXX is this cluster still useful?
101 syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
102 " Generic identifier.
103 syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
104 " Specific chain for headings (needs to come after other heading material)
105 syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
106 syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
107 " Specific hack for \cfg{}
108 syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
109 " Generic argument to be emphasised
110 syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
111 " Specific hack for \W{}{}
112 syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
113 " Specific hack for \I{}
114 syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
115 " Specific hack for \IM{}{}...
116 syn region butIMArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
117 " Default argument (due to being last).
118 syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText
120 " Rune from vim 6.1 help
121 if version >= 508 || !exists("did_halibut_syn_inits")
123 let did_halibut_syn_inits = 1
124 command -nargs=+ HiLink hi link <args>
126 command -nargs=+ HiLink hi def link <args>
129 HiLink butCmdGeneric Statement
130 HiLink butCmdSpecific Statement
132 HiLink butLiteral SpecialChar
134 HiLink butQLEmphInv Error
135 HiLink butIllegalChar Error
137 HiLink butComment Comment
138 HiLink butCommentPara Comment
140 HiLink butDelimiter Delimiter
142 HiLink butIdentArg Identifier
143 HiLink butIdentArgH Identifier
144 HiLink butCfgArg Identifier
145 HiLink butEmphArg Underlined
146 HiLink butHyperArg Underlined
147 HiLink butIndexArg Identifier
148 HiLink butIMArg Identifier
150 HiLink butTextHeading Underlined
157 " b: local to current buffer
158 let b:current_syntax = "halibut"