Support \I\c, \I\cw. (Haven't bothered with \I\e since the emphasis may as
[sgt/halibut] / misc / halibut.vim
CommitLineData
4d8caeda 1" Vim syntax file
2" Language: Halibut
3" Maintainer: Jacob Nevins <jacobn+vim@chiark.greenend.org.uk>
c5785c53 4" URL: http://www.chiark.greenend.org.uk/~sgtatham/halibut/
4d8caeda 5" Filenames: *.but
a697063f 6" Version: $Id: halibut.vim,v 1.11 2004/06/19 13:27:52 jacob Exp $
4d8caeda 7
c5785c53 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.
4d8caeda 11" I have no idea if it's compatible with vim <6.1.
12
13" Based on docs in Halibut CVS 2004-03-31
14
9d62829c 15" FIXME:
16" - sync - last blank line, \quote, \lcont
17" - add "display" etc for speed?
18
4d8caeda 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
22if version < 600
23 syn clear
24elseif exists("b:current_syntax")
25 finish
26endif
27
28" Halibut is case-sensitive.
29syn case match
30
31" Fallbacks -- if these characters are seen in text and not caught by
32" anything below, it's probably a syntax violation.
33syn match butIllegalChar "{"
34syn match butIllegalChar "}"
35syn match butIllegalChar "\\"
36
37" Simple-minded fallback to highlight any command we don't recognise,
38" and assume it has textual arguments.
08f82d84 39" (matches current iscmd() in input.c; there are some oddballs which
40" don't fit this handled specially below)
41syn match butCmdGeneric "\\[A-Za-z0-9]\+" nextgroup=butTextArg
4d8caeda 42
43syn cluster butText contains=butLiteral,@butCmd,butTodo
44
08f82d84 45" The special one-character "commands".
46" XXX might want to split up? Can all these appear in \k{...}?
4d8caeda 47syn match butLiteral "\\[-{}_.\\]"
48
49" This isn't specific to Halibut, but is often useful.
50syn keyword butTodo XXX FIXME TODO
51
52" Specific processing comes after the generic stuff above.
53
54" Paragraph level stuff.
55
56" Literals -- might need to come before \e{}, \c{}
57syn region butQuoteLit matchgroup=butCmdSpecific start="\\c\_s\@=" matchgroup=NONE end="$"
58syn region butQLEmph matchgroup=butCmdSpecific start="\\e\_s\@=" matchgroup=NONE end="$" contains=butQLEmphInv
59" Highlight invalid characters in emphasis line, cos I'll never remember.
60syn match butQLEmphInv "\S\@=[^bi]" contained
61
62" Paragraph level comment -- might need to come before inline comment.
c44dc6a4 63syn region butCommentPara start="\\#" end="^\s*$" contains=butTodo
4d8caeda 64
65" Inline comments -- nested braces are honoured.
eb4d33e6 66syn region butComment matchgroup=Comment start="\\#{" skip="\\}" end="}" contains=butCommentBrace,butTodo
67syn region butCommentBrace start="{" skip="\\}" end="}" contains=butCommentBrace,butTodo contained transparent
4d8caeda 68
69" Section headings - a bit hairy. Order wrt rest of file is important.
c5785c53 70syn match butCmdSpecific "\\\(S\d\|[CAHS]\)" nextgroup=butIdentArgH
4d8caeda 71" butIdentArgH -> butTextArgH? -> this, which highlights the rest of the para:
72syn region butTextHeading start="" end="^\s*$" contained contains=@butText
c5785c53 73" Unadorned headings
74syn match butCmdSpecific "\\U\_s\@=" nextgroup=butTextHeading
4d8caeda 75" ...and overall title
c5785c53 76syn match butCmdSpecific "\\title\_s\@=" nextgroup=butTextHeading
4d8caeda 77
9d62829c 78" Bulleted lists -- arguments optional
79syn match butCmdSpecific "\\\(b\|n\|dd\)[^A-Za-z0-9]\@=" nextgroup=butIdentArg
4d8caeda 80
81" Config
82syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
83
84" Index/biblio stuff
85syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
86syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
87syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
88
89" Macros
90syn match butCmdSpecific "\\define{\@=" nextgroup=butIdentArg
91
92" Specific inline commands
93" (Some of these are defined out of paranoia about clashes with code quotes.)
a697063f 94" Indexing -- invisible entries. (includes \I\c, \I\cw; \I\e left)
95syn match butCmdSpecific "\\I\(\\cw\|\\c\)\={\@=" nextgroup=butIndexArg
4d8caeda 96" Formatting.
97syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
98syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
99syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
100syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
4d8caeda 101" Xref commands
102syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
103" Unicode literal -- a bit special.
ac415fbe 104syn match butLiteral "\\u\x\{,4}" nextgroup=butTextArg
4d8caeda 105
106" Command cluster.
be78a7b9 107syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,butComment,butQuoteLit,butQLEmph,butCommentPara,butLiteral
4d8caeda 108
109" Types of argument. XXX is this cluster still useful?
110syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
111" Generic identifier.
112syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
113" Specific chain for headings (needs to come after other heading material)
114syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
115syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
116" Specific hack for \cfg{}
117syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
118" Generic argument to be emphasised
119syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
120" Specific hack for \W{}{}
121syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
122" Specific hack for \I{}
123syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
124" Specific hack for \IM{}{}...
3df7c0ec 125syn region butIMArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
4d8caeda 126" Default argument (due to being last).
c5785c53 127syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText transparent
4d8caeda 128
129" Rune from vim 6.1 help
130if version >= 508 || !exists("did_halibut_syn_inits")
131 if version < 508
132 let did_halibut_syn_inits = 1
133 command -nargs=+ HiLink hi link <args>
134 else
135 command -nargs=+ HiLink hi def link <args>
136 endif
137
138 HiLink butCmdGeneric Statement
139 HiLink butCmdSpecific Statement
140
141 HiLink butLiteral SpecialChar
142
143 HiLink butQLEmphInv Error
144 HiLink butIllegalChar Error
145
146 HiLink butComment Comment
147 HiLink butCommentPara Comment
148
149 HiLink butDelimiter Delimiter
150
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
158
159 HiLink butTextHeading Underlined
160
161 HiLink butTodo Todo
162
163 delcommand HiLink
164endif
165
166" b: local to current buffer
167let b:current_syntax = "halibut"