Add stuff to butCmd para so that constructs like \c don't break inside
[sgt/halibut] / misc / halibut.vim
1 " Vim syntax file
2 " Language: Halibut
3 " Maintainer: Jacob Nevins <jacobn+vim@chiark.greenend.org.uk>
4 " URL: http://www.chiark.greenend.org.uk/~sgtatham/halibut/
5 " Filenames: *.but
6 " Version: $Id: halibut.vim,v 1.7 2004/04/01 23:21:28 jtn Exp $
7
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.
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
18 if version < 600
19 syn clear
20 elseif exists("b:current_syntax")
21 finish
22 endif
23
24 " Halibut is case-sensitive.
25 syn 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.
29 syn match butIllegalChar "{"
30 syn match butIllegalChar "}"
31 syn match butIllegalChar "\\"
32
33 " Simple-minded fallback to highlight any command we don't recognise,
34 " and assume it has textual arguments.
35 " (matches current iscmd() in input.c; there are some oddballs which
36 " don't fit this handled specially below)
37 syn match butCmdGeneric "\\[A-Za-z0-9]\+" nextgroup=butTextArg
38 " was: [A-Za-z0-9#]\+
39
40 syn cluster butText contains=butLiteral,@butCmd,butTodo
41
42 " The special one-character "commands".
43 " XXX might want to split up? Can all these appear in \k{...}?
44 syn match butLiteral "\\[-{}_.\\]"
45
46 " This isn't specific to Halibut, but is often useful.
47 syn 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{}
54 syn region butQuoteLit matchgroup=butCmdSpecific start="\\c\_s\@=" matchgroup=NONE end="$"
55 syn region butQLEmph matchgroup=butCmdSpecific start="\\e\_s\@=" matchgroup=NONE end="$" contains=butQLEmphInv
56 " Highlight invalid characters in emphasis line, cos I'll never remember.
57 syn match butQLEmphInv "\S\@=[^bi]" contained
58
59 " Paragraph level comment -- might need to come before inline comment.
60 syn region butCommentPara start="\\#\_s\@=" end="^\s*$" contains=butTodo
61
62 " Inline comments -- nested braces are honoured.
63 syn region butComment matchgroup=Comment start="\\#{" skip="\\}" end="}" contains=butCommentBrace,butTodo
64 syn region butCommentBrace start="{" skip="\\}" end="}" contains=butCommentBrace,butTodo contained transparent
65
66 " Section headings - a bit hairy. Order wrt rest of file is important.
67 syn match butCmdSpecific "\\\(S\d\|[CAHS]\)" nextgroup=butIdentArgH
68 " butIdentArgH -> butTextArgH? -> this, which highlights the rest of the para:
69 syn region butTextHeading start="" end="^\s*$" contained contains=@butText
70 " Unadorned headings
71 syn match butCmdSpecific "\\U\_s\@=" nextgroup=butTextHeading
72 " ...and overall title
73 syn match butCmdSpecific "\\title\_s\@=" nextgroup=butTextHeading
74
75 " Bulleted lists
76 syn match butCmdSpecific "\\\(b\|n\|dd\)" nextgroup=butIdentArg
77
78 " Config
79 syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
80
81 " Index/biblio stuff
82 syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
83 syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
84 syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
85
86 " Macros
87 syn 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.
92 syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
93 syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
94 syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
95 syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
96 " Indexing -- invisible entries.
97 syn match butCmdSpecific "\\I{\@=" nextgroup=butIndexArg
98 " Xref commands
99 syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
100 " Unicode literal -- a bit special.
101 syn match butLiteral "\\u\x*" nextgroup=butTextArg
102
103 " Command cluster.
104 syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,butComment,butQuoteLit,butQLEmph,butCommentPara,butLiteral
105
106 " Types of argument. XXX is this cluster still useful?
107 syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
108 " Generic identifier.
109 syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
110 " Specific chain for headings (needs to come after other heading material)
111 syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
112 syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
113 " Specific hack for \cfg{}
114 syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
115 " Generic argument to be emphasised
116 syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
117 " Specific hack for \W{}{}
118 syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
119 " Specific hack for \I{}
120 syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
121 " Specific hack for \IM{}{}...
122 syn region butIMArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
123 " Default argument (due to being last).
124 syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText transparent
125
126 " Rune from vim 6.1 help
127 if 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
161 endif
162
163 " b: local to current buffer
164 let b:current_syntax = "halibut"