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.9 2004/04/02 00:03:10 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
16 " - sync - last blank line, \quote, \lcont
17 " - add "display" etc for speed?
19 " Rune from vim 6.1 help
20 " For version 5.x: Clear all syntax items
21 " For version 6.x: Quit when a syntax file was already loaded
24 elseif exists("b:current_syntax")
28 " Halibut is case-sensitive.
31 " Fallbacks -- if these characters are seen in text and not caught by
32 " anything below, it's probably a syntax violation.
33 syn match butIllegalChar "{"
34 syn match butIllegalChar "}"
35 syn match butIllegalChar "\\"
37 " Simple-minded fallback to highlight any command we don't recognise,
38 " and assume it has textual arguments.
39 " (matches current iscmd() in input.c; there are some oddballs which
40 " don't fit this handled specially below)
41 syn match butCmdGeneric "\\[A-Za-z0-9]\+" nextgroup=butTextArg
43 syn cluster butText contains=butLiteral,@butCmd,butTodo
45 " The special one-character "commands".
46 " XXX might want to split up? Can all these appear in \k{...}?
47 syn match butLiteral "\\[-{}_.\\]"
49 " This isn't specific to Halibut, but is often useful.
50 syn keyword butTodo XXX FIXME TODO
52 " Specific processing comes after the generic stuff above.
54 " Paragraph level stuff.
56 " Literals -- might need to come before \e{}, \c{}
57 syn region butQuoteLit matchgroup=butCmdSpecific start="\\c\_s\@=" matchgroup=NONE end="$"
58 syn region butQLEmph matchgroup=butCmdSpecific start="\\e\_s\@=" matchgroup=NONE end="$" contains=butQLEmphInv
59 " Highlight invalid characters in emphasis line, cos I'll never remember.
60 syn match butQLEmphInv "\S\@=[^bi]" contained
62 " Paragraph level comment -- might need to come before inline comment.
63 syn region butCommentPara start="\\#\_s\@=" end="^\s*$" contains=butTodo
65 " Inline comments -- nested braces are honoured.
66 syn region butComment matchgroup=Comment start="\\#{" skip="\\}" end="}" contains=butCommentBrace,butTodo
67 syn region butCommentBrace start="{" skip="\\}" end="}" contains=butCommentBrace,butTodo contained transparent
69 " Section headings - a bit hairy. Order wrt rest of file is important.
70 syn match butCmdSpecific "\\\(S\d\|[CAHS]\)" nextgroup=butIdentArgH
71 " butIdentArgH -> butTextArgH? -> this, which highlights the rest of the para:
72 syn region butTextHeading start="" end="^\s*$" contained contains=@butText
74 syn match butCmdSpecific "\\U\_s\@=" nextgroup=butTextHeading
75 " ...and overall title
76 syn match butCmdSpecific "\\title\_s\@=" nextgroup=butTextHeading
78 " Bulleted lists -- arguments optional
79 syn match butCmdSpecific "\\\(b\|n\|dd\)[^A-Za-z0-9]\@=" nextgroup=butIdentArg
82 syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
85 syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
86 syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
87 syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
90 syn match butCmdSpecific "\\define{\@=" nextgroup=butIdentArg
92 " Specific inline commands
93 " (Some of these are defined out of paranoia about clashes with code quotes.)
95 syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
96 syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
97 syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
98 syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
99 " Indexing -- invisible entries.
100 syn match butCmdSpecific "\\I{\@=" nextgroup=butIndexArg
102 syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
103 " Unicode literal -- a bit special.
104 syn match butLiteral "\\u\x\{,4}" nextgroup=butTextArg
107 syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,butComment,butQuoteLit,butQLEmph,butCommentPara,butLiteral
109 " Types of argument. XXX is this cluster still useful?
110 syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
111 " Generic identifier.
112 syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
113 " Specific chain for headings (needs to come after other heading material)
114 syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
115 syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
116 " Specific hack for \cfg{}
117 syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
118 " Generic argument to be emphasised
119 syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
120 " Specific hack for \W{}{}
121 syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
122 " Specific hack for \I{}
123 syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
124 " Specific hack for \IM{}{}...
125 syn region butIMArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
126 " Default argument (due to being last).
127 syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText transparent
129 " Rune from vim 6.1 help
130 if version >= 508 || !exists("did_halibut_syn_inits")
132 let did_halibut_syn_inits = 1
133 command -nargs=+ HiLink hi link <args>
135 command -nargs=+ HiLink hi def link <args>
138 HiLink butCmdGeneric Statement
139 HiLink butCmdSpecific Statement
141 HiLink butLiteral SpecialChar
143 HiLink butQLEmphInv Error
144 HiLink butIllegalChar Error
146 HiLink butComment Comment
147 HiLink butCommentPara Comment
149 HiLink butDelimiter Delimiter
151 HiLink butIdentArg Identifier
152 HiLink butIdentArgH Identifier
153 HiLink butCfgArg Identifier
154 HiLink butEmphArg Underlined
155 HiLink butHyperArg Underlined
156 HiLink butIndexArg Identifier
157 HiLink butIMArg Identifier
159 HiLink butTextHeading Underlined
166 " b: local to current buffer
167 let b:current_syntax = "halibut"