3 " Maintainer: Jacob Nevins <jacobn+vim@chiark.greenend.org.uk>
4 " URL: http://www.chiark.greenend.org.uk/~sgtatham/halibut/
6 " Version: $Id: halibut.vim,v 1.5 2004/04/01 22:52:46 jtn Exp $
8 " I've never been entirely comfortable with vim's syntax highlighting
9 " facilities, so this may have all sorts of nasty loose ends, corner cases
10 " etc, but it works for me.
11 " I have no idea if it's compatible with vim <6.1.
13 " Based on docs in Halibut CVS 2004-03-31
15 " Rune from vim 6.1 help
16 " For version 5.x: Clear all syntax items
17 " For version 6.x: Quit when a syntax file was already loaded
20 elseif exists("b:current_syntax")
24 " Halibut is case-sensitive.
27 " Fallbacks -- if these characters are seen in text and not caught by
28 " anything below, it's probably a syntax violation.
29 syn match butIllegalChar "{"
30 syn match butIllegalChar "}"
31 syn match butIllegalChar "\\"
33 " Simple-minded fallback to highlight any command we don't recognise,
34 " and assume it has textual arguments.
35 " XXX highlights all of "\date)."
36 syn match butCmdGeneric "\\\(\S\&[^{}\\]\)\+" nextgroup=butTextArg
39 syn cluster butText contains=butLiteral,@butCmd,butTodo
41 syn match butLiteral "\\[-{}_.\\]"
43 " This isn't specific to Halibut, but is often useful.
44 syn keyword butTodo XXX FIXME TODO
46 " Specific processing comes after the generic stuff above.
48 " Paragraph level stuff.
50 " Literals -- might need to come before \e{}, \c{}
51 syn region butQuoteLit matchgroup=butCmdSpecific start="\\c\_s\@=" matchgroup=NONE end="$"
52 syn region butQLEmph matchgroup=butCmdSpecific start="\\e\_s\@=" matchgroup=NONE end="$" contains=butQLEmphInv
53 " Highlight invalid characters in emphasis line, cos I'll never remember.
54 syn match butQLEmphInv "\S\@=[^bi]" contained
56 " Paragraph level comment -- might need to come before inline comment.
57 syn region butCommentPara start="\\#\_s\@=" end="^\s*$" contains=butTodo
59 " Inline comments -- nested braces are honoured.
60 syn region butComment matchgroup=Comment start="\\#{" skip="\\}" end="}" contains=butCommentBrace,butTodo
61 syn region butCommentBrace start="{" skip="\\}" end="}" contains=butCommentBrace,butTodo contained transparent
63 " Section headings - a bit hairy. Order wrt rest of file is important.
64 syn match butCmdSpecific "\\\(S\d\|[CAHS]\)" nextgroup=butIdentArgH
65 " butIdentArgH -> butTextArgH? -> this, which highlights the rest of the para:
66 syn region butTextHeading start="" end="^\s*$" contained contains=@butText
68 syn match butCmdSpecific "\\U\_s\@=" nextgroup=butTextHeading
69 " ...and overall title
70 syn match butCmdSpecific "\\title\_s\@=" nextgroup=butTextHeading
73 syn match butCmdSpecific "\\\(b\|n\|dd\)" nextgroup=butIdentArg
76 syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
79 syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
80 syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
81 syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
84 syn match butCmdSpecific "\\define{\@=" nextgroup=butIdentArg
86 " Specific inline commands
87 " (Some of these are defined out of paranoia about clashes with code quotes.)
89 syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
90 syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
91 syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
92 syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
93 " Indexing -- invisible entries.
94 syn match butCmdSpecific "\\I{\@=" nextgroup=butIndexArg
96 syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
97 " Unicode literal -- a bit special.
98 syn match butLiteral "\\u\x*" nextgroup=butTextArg
101 syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,ButComment
103 " Types of argument. XXX is this cluster still useful?
104 syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
105 " Generic identifier.
106 syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
107 " Specific chain for headings (needs to come after other heading material)
108 syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
109 syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
110 " Specific hack for \cfg{}
111 syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
112 " Generic argument to be emphasised
113 syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
114 " Specific hack for \W{}{}
115 syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
116 " Specific hack for \I{}
117 syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
118 " Specific hack for \IM{}{}...
119 syn region butIMArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
120 " Default argument (due to being last).
121 syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText transparent
123 " Rune from vim 6.1 help
124 if version >= 508 || !exists("did_halibut_syn_inits")
126 let did_halibut_syn_inits = 1
127 command -nargs=+ HiLink hi link <args>
129 command -nargs=+ HiLink hi def link <args>
132 HiLink butCmdGeneric Statement
133 HiLink butCmdSpecific Statement
135 HiLink butLiteral SpecialChar
137 HiLink butQLEmphInv Error
138 HiLink butIllegalChar Error
140 HiLink butComment Comment
141 HiLink butCommentPara Comment
143 HiLink butDelimiter Delimiter
145 HiLink butIdentArg Identifier
146 HiLink butIdentArgH Identifier
147 HiLink butCfgArg Identifier
148 HiLink butEmphArg Underlined
149 HiLink butHyperArg Underlined
150 HiLink butIndexArg Identifier
151 HiLink butIMArg Identifier
153 HiLink butTextHeading Underlined
160 " b: local to current buffer
161 let b:current_syntax = "halibut"