Oops, appendices.
[sgt/halibut] / misc / halibut.vim
CommitLineData
4d8caeda 1" Vim syntax file
2" Language: Halibut
3" Maintainer: Jacob Nevins <jacobn+vim@chiark.greenend.org.uk>
4" URL: FIXME
5" Filenames: *.but
116b7f38 6" Version: $Id: halibut.vim,v 1.2 2004/04/01 01:12:21 jtn Exp $
4d8caeda 7
8" I'm not proud of this. Every time I tangle with vim's syntax highlighting
9" I come away unsatisfied. Nevertheless, it seems to work.
10" I have no idea if it's compatible with vim <6.1.
11
12" Based on docs in Halibut CVS 2004-03-31
13
14" Rune from vim 6.1 help
15" For version 5.x: Clear all syntax items
16" For version 6.x: Quit when a syntax file was already loaded
17if version < 600
18 syn clear
19elseif exists("b:current_syntax")
20 finish
21endif
22
23" Halibut is case-sensitive.
24syn case match
25
26" Fallbacks -- if these characters are seen in text and not caught by
27" anything below, it's probably a syntax violation.
28syn match butIllegalChar "{"
29syn match butIllegalChar "}"
30syn match butIllegalChar "\\"
31
32" Simple-minded fallback to highlight any command we don't recognise,
33" and assume it has textual arguments.
34" XXX highlights all of "\date)."
35syn match butCmdGeneric "\\\(\S\&[^{}\\]\)\+" nextgroup=butTextArg
36" was: [A-Za-z0-9#]\+
37
38syn cluster butText contains=butLiteral,@butCmd,butTodo
39
40syn match butLiteral "\\[-{}_.\\]"
41
42" This isn't specific to Halibut, but is often useful.
43syn keyword butTodo XXX FIXME TODO
44
45" Specific processing comes after the generic stuff above.
46
47" Paragraph level stuff.
48
49" Literals -- might need to come before \e{}, \c{}
50syn region butQuoteLit matchgroup=butCmdSpecific start="\\c\_s\@=" matchgroup=NONE end="$"
51syn region butQLEmph matchgroup=butCmdSpecific start="\\e\_s\@=" matchgroup=NONE end="$" contains=butQLEmphInv
52" Highlight invalid characters in emphasis line, cos I'll never remember.
53syn match butQLEmphInv "\S\@=[^bi]" contained
54
55" Paragraph level comment -- might need to come before inline comment.
56syn region butCommentPara start="\\#\_s\@=" end="^\s*$" contains=butTodo
57
58" Inline comments -- nested braces are honoured.
59syn region butComment matchgroup=Comment start="\\#{" end="}" contains=butCommentBrace,butTodo
60syn region butCommentBrace start="{" end="}" contains=butCommentBrace,butTodo contained transparent
61
62" Section headings - a bit hairy. Order wrt rest of file is important.
116b7f38 63syn match butCmdSpecific "\\\(S\d\|[CAHSU]\)" nextgroup=butIdentArgH
4d8caeda 64" butIdentArgH -> butTextArgH? -> this, which highlights the rest of the para:
65syn region butTextHeading start="" end="^\s*$" contained contains=@butText
66" ...and overall title
67syn match butCmdSpecific "\\title" nextgroup=butTextHeading
68
69" Bulleted lists
70syn match butCmdSpecific "\\\(b\|n\|dd\)" nextgroup=butIdentArg
71
72" Config
73syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
74
75" Index/biblio stuff
76syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
77syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
78syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
79
80" Macros
81syn match butCmdSpecific "\\define{\@=" nextgroup=butIdentArg
82
83" Specific inline commands
84" (Some of these are defined out of paranoia about clashes with code quotes.)
85" Formatting.
86syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
87syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
88syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
89syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
90" Indexing -- invisible entries.
91syn match butCmdSpecific "\\I{\@=" nextgroup=butIndexArg
92" Xref commands
93syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
94" Unicode literal -- a bit special.
95syn match butLiteral "\\u\x*" nextgroup=butTextArg
96
97" Command cluster.
98syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,ButComment
99
100" Types of argument. XXX is this cluster still useful?
101syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
102" Generic identifier.
103syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
104" Specific chain for headings (needs to come after other heading material)
105syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
106syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
107" Specific hack for \cfg{}
108syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
109" Generic argument to be emphasised
110syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
111" Specific hack for \W{}{}
112syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
113" Specific hack for \I{}
114syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
115" Specific hack for \IM{}{}...
116syn region butIMArg matchgroup=butDelimited start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
117" Default argument (due to being last).
118syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText
119
120" Rune from vim 6.1 help
121if version >= 508 || !exists("did_halibut_syn_inits")
122 if version < 508
123 let did_halibut_syn_inits = 1
124 command -nargs=+ HiLink hi link <args>
125 else
126 command -nargs=+ HiLink hi def link <args>
127 endif
128
129 HiLink butCmdGeneric Statement
130 HiLink butCmdSpecific Statement
131
132 HiLink butLiteral SpecialChar
133
134 HiLink butQLEmphInv Error
135 HiLink butIllegalChar Error
136
137 HiLink butComment Comment
138 HiLink butCommentPara Comment
139
140 HiLink butDelimiter Delimiter
141
142 HiLink butIdentArg Identifier
143 HiLink butIdentArgH Identifier
144 HiLink butCfgArg Identifier
145 HiLink butEmphArg Underlined
146 HiLink butHyperArg Underlined
147 HiLink butIndexArg Identifier
148 HiLink butIMArg Identifier
149
150 HiLink butTextHeading Underlined
151
152 HiLink butTodo Todo
153
154 delcommand HiLink
155endif
156
157" b: local to current buffer
158let b:current_syntax = "halibut"