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.12 2004/07/16 12:54:59 jacob 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="\\#" 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.)
94 " Indexing -- invisible entries. (includes \I\c, \I\cw; \I\e left; no \q, \cq)
95 syn match butCmdSpecific "\\I\(\\cw\|\\c\)\={\@=" nextgroup=butIndexArg
97 syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
98 syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
99 syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
100 syn match butCmdSpecific "\\cq{\@=" nextgroup=butTextArg
101 syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
103 syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
104 " Unicode literal -- a bit special.
105 syn match butLiteral "\\u\x\{,4}" nextgroup=butTextArg
108 syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,butComment,butQuoteLit,butQLEmph,butCommentPara,butLiteral
110 " Types of argument. XXX is this cluster still useful?
111 syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
112 " Generic identifier.
113 syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
114 " Specific chain for headings (needs to come after other heading material)
115 syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
116 syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
117 " Specific hack for \cfg{}
118 syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
119 " Generic argument to be emphasised
120 syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
121 " Specific hack for \W{}{}
122 syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
123 " Specific hack for \I{}
124 syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
125 " Specific hack for \IM{}{}...
126 syn region butIMArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
127 " Default argument (due to being last).
128 syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText transparent
130 " Rune from vim 6.1 help
131 if version >= 508 || !exists("did_halibut_syn_inits")
133 let did_halibut_syn_inits = 1
134 command -nargs=+ HiLink hi link <args>
136 command -nargs=+ HiLink hi def link <args>
139 HiLink butCmdGeneric Statement
140 HiLink butCmdSpecific Statement
142 HiLink butLiteral SpecialChar
144 HiLink butQLEmphInv Error
145 HiLink butIllegalChar Error
147 HiLink butComment Comment
148 HiLink butCommentPara Comment
150 HiLink butDelimiter Delimiter
152 HiLink butIdentArg Identifier
153 HiLink butIdentArgH Identifier
154 HiLink butCfgArg Identifier
155 HiLink butEmphArg Underlined
156 HiLink butHyperArg Underlined
157 HiLink butIndexArg Identifier
158 HiLink butIMArg Identifier
160 HiLink butTextHeading Underlined
167 " b: local to current buffer
168 let b:current_syntax = "halibut"