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