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