91d7e9a2c4c44e32a226dac62e68f51252229309
[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.9 2004/04/02 00:03:10 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 " FIXME:
16 " - sync - last blank line, \quote, \lcont
17 " - add "display" etc for speed?
18
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
22 if version < 600
23 syn clear
24 elseif exists("b:current_syntax")
25 finish
26 endif
27
28 " Halibut is case-sensitive.
29 syn 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.
33 syn match butIllegalChar "{"
34 syn match butIllegalChar "}"
35 syn match butIllegalChar "\\"
36
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
42
43 syn cluster butText contains=butLiteral,@butCmd,butTodo
44
45 " The special one-character "commands".
46 " XXX might want to split up? Can all these appear in \k{...}?
47 syn match butLiteral "\\[-{}_.\\]"
48
49 " This isn't specific to Halibut, but is often useful.
50 syn 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{}
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
61
62 " Paragraph level comment -- might need to come before inline comment.
63 syn region butCommentPara start="\\#\_s\@=" end="^\s*$" contains=butTodo
64
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
68
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
73 " Unadorned headings
74 syn match butCmdSpecific "\\U\_s\@=" nextgroup=butTextHeading
75 " ...and overall title
76 syn match butCmdSpecific "\\title\_s\@=" nextgroup=butTextHeading
77
78 " Bulleted lists -- arguments optional
79 syn match butCmdSpecific "\\\(b\|n\|dd\)[^A-Za-z0-9]\@=" nextgroup=butIdentArg
80
81 " Config
82 syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
83
84 " Index/biblio stuff
85 syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
86 syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
87 syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
88
89 " Macros
90 syn match butCmdSpecific "\\define{\@=" nextgroup=butIdentArg
91
92 " Specific inline commands
93 " (Some of these are defined out of paranoia about clashes with code quotes.)
94 " Formatting.
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
101 " Xref commands
102 syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
103 " Unicode literal -- a bit special.
104 syn match butLiteral "\\u\x\{,4}" nextgroup=butTextArg
105
106 " Command cluster.
107 syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,butComment,butQuoteLit,butQLEmph,butCommentPara,butLiteral
108
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
128
129 " Rune from vim 6.1 help
130 if 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
164 endif
165
166 " b: local to current buffer
167 let b:current_syntax = "halibut"