98d884a398bb464db9bd09f4249b4eea534e98c2
[sgt/halibut] / misc / halibut.vim
1 " Vim syntax file
2 " Language: Halibut
3 " Maintainer: Jacob Nevins <jacobn+vim@chiark.greenend.org.uk>
4 " URL: FIXME
5 " Filenames: *.but
6 " Version: $Id: halibut.vim,v 1.3 2004/04/01 22:21:23 jtn Exp $
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
17 if version < 600
18 syn clear
19 elseif exists("b:current_syntax")
20 finish
21 endif
22
23 " Halibut is case-sensitive.
24 syn 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.
28 syn match butIllegalChar "{"
29 syn match butIllegalChar "}"
30 syn 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)."
35 syn match butCmdGeneric "\\\(\S\&[^{}\\]\)\+" nextgroup=butTextArg
36 " was: [A-Za-z0-9#]\+
37
38 syn cluster butText contains=butLiteral,@butCmd,butTodo
39
40 syn match butLiteral "\\[-{}_.\\]"
41
42 " This isn't specific to Halibut, but is often useful.
43 syn 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{}
50 syn region butQuoteLit matchgroup=butCmdSpecific start="\\c\_s\@=" matchgroup=NONE end="$"
51 syn region butQLEmph matchgroup=butCmdSpecific start="\\e\_s\@=" matchgroup=NONE end="$" contains=butQLEmphInv
52 " Highlight invalid characters in emphasis line, cos I'll never remember.
53 syn match butQLEmphInv "\S\@=[^bi]" contained
54
55 " Paragraph level comment -- might need to come before inline comment.
56 syn region butCommentPara start="\\#\_s\@=" end="^\s*$" contains=butTodo
57
58 " Inline comments -- nested braces are honoured.
59 syn region butComment matchgroup=Comment start="\\#{" end="}" contains=butCommentBrace,butTodo
60 syn region butCommentBrace start="{" end="}" contains=butCommentBrace,butTodo contained transparent
61
62 " Section headings - a bit hairy. Order wrt rest of file is important.
63 syn match butCmdSpecific "\\\(S\d\|[CAHSU]\)" nextgroup=butIdentArgH
64 " butIdentArgH -> butTextArgH? -> this, which highlights the rest of the para:
65 syn region butTextHeading start="" end="^\s*$" contained contains=@butText
66 " ...and overall title
67 syn match butCmdSpecific "\\title" nextgroup=butTextHeading
68
69 " Bulleted lists
70 syn match butCmdSpecific "\\\(b\|n\|dd\)" nextgroup=butIdentArg
71
72 " Config
73 syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
74
75 " Index/biblio stuff
76 syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
77 syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
78 syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
79
80 " Macros
81 syn 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.
86 syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
87 syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
88 syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
89 syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
90 " Indexing -- invisible entries.
91 syn match butCmdSpecific "\\I{\@=" nextgroup=butIndexArg
92 " Xref commands
93 syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
94 " Unicode literal -- a bit special.
95 syn match butLiteral "\\u\x*" nextgroup=butTextArg
96
97 " Command cluster.
98 syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,ButComment
99
100 " Types of argument. XXX is this cluster still useful?
101 syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
102 " Generic identifier.
103 syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
104 " Specific chain for headings (needs to come after other heading material)
105 syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
106 syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
107 " Specific hack for \cfg{}
108 syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
109 " Generic argument to be emphasised
110 syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
111 " Specific hack for \W{}{}
112 syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
113 " Specific hack for \I{}
114 syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
115 " Specific hack for \IM{}{}...
116 syn region butIMArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
117 " Default argument (due to being last).
118 syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText
119
120 " Rune from vim 6.1 help
121 if 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
155 endif
156
157 " b: local to current buffer
158 let b:current_syntax = "halibut"