Oops, fix bracing comment stuff.
[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.5 2004/04/01 22:52:46 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 " XXX highlights all of "\date)."
36 syn match butCmdGeneric "\\\(\S\&[^{}\\]\)\+" nextgroup=butTextArg
37 " was: [A-Za-z0-9#]\+
38
39 syn cluster butText contains=butLiteral,@butCmd,butTodo
40
41 syn match butLiteral "\\[-{}_.\\]"
42
43 " This isn't specific to Halibut, but is often useful.
44 syn 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{}
51 syn region butQuoteLit matchgroup=butCmdSpecific start="\\c\_s\@=" matchgroup=NONE end="$"
52 syn region butQLEmph matchgroup=butCmdSpecific start="\\e\_s\@=" matchgroup=NONE end="$" contains=butQLEmphInv
53 " Highlight invalid characters in emphasis line, cos I'll never remember.
54 syn match butQLEmphInv "\S\@=[^bi]" contained
55
56 " Paragraph level comment -- might need to come before inline comment.
57 syn region butCommentPara start="\\#\_s\@=" end="^\s*$" contains=butTodo
58
59 " Inline comments -- nested braces are honoured.
60 syn region butComment matchgroup=Comment start="\\#{" skip="\\}" end="}" contains=butCommentBrace,butTodo
61 syn region butCommentBrace start="{" skip="\\}" end="}" contains=butCommentBrace,butTodo contained transparent
62
63 " Section headings - a bit hairy. Order wrt rest of file is important.
64 syn match butCmdSpecific "\\\(S\d\|[CAHS]\)" nextgroup=butIdentArgH
65 " butIdentArgH -> butTextArgH? -> this, which highlights the rest of the para:
66 syn region butTextHeading start="" end="^\s*$" contained contains=@butText
67 " Unadorned headings
68 syn match butCmdSpecific "\\U\_s\@=" nextgroup=butTextHeading
69 " ...and overall title
70 syn match butCmdSpecific "\\title\_s\@=" nextgroup=butTextHeading
71
72 " Bulleted lists
73 syn match butCmdSpecific "\\\(b\|n\|dd\)" nextgroup=butIdentArg
74
75 " Config
76 syn match butCmdSpecific "\\cfg{\@=" nextgroup=butCfgArg
77
78 " Index/biblio stuff
79 syn match butCmdSpecific "\\IM{\@=" nextgroup=butIMArg
80 syn match butCmdSpecific "\\BR\={\@=" nextgroup=butIdentArg
81 syn match butCmdSpecific "\\nocite{\@=" nextgroup=butIdentArg
82
83 " Macros
84 syn 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.
89 syn match butCmdSpecific "\\e{\@=" nextgroup=butEmphArg
90 syn match butCmdSpecific "\\c{\@=" nextgroup=butTextArg
91 syn match butCmdSpecific "\\cw{\@=" nextgroup=butTextArg
92 syn match butCmdSpecific "\\W{\@=" nextgroup=butHyperArg
93 " Indexing -- invisible entries.
94 syn match butCmdSpecific "\\I{\@=" nextgroup=butIndexArg
95 " Xref commands
96 syn match butCmdSpecific "\\[kK]{\@=" nextgroup=butIdentArg
97 " Unicode literal -- a bit special.
98 syn match butLiteral "\\u\x*" nextgroup=butTextArg
99
100 " Command cluster.
101 syn cluster butCmd contains=butCmdGeneric,butCmdSpecific,ButComment
102
103 " Types of argument. XXX is this cluster still useful?
104 syn cluster butArgument contains=butTextArg,butIdentArg,butEmphArgmbutCfgArg,butIdentArgH,butTextArgH
105 " Generic identifier.
106 syn region butIdentArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=butLiteral
107 " Specific chain for headings (needs to come after other heading material)
108 syn region butTextArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextHeading contained contains=@butText
109 syn region butIdentArgH matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butTextArgH,butTextHeading contained contains=butLiteral
110 " Specific hack for \cfg{}
111 syn region butCfgArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=butCfgArg contained contains=butLiteral
112 " Generic argument to be emphasised
113 syn region butEmphArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
114 " Specific hack for \W{}{}
115 syn region butHyperArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butTextArg
116 " Specific hack for \I{}
117 syn region butIndexArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained contains=@butText
118 " Specific hack for \IM{}{}...
119 syn region butIMArg matchgroup=butDelimiter start="{" skip="\\}" end="}" contained nextgroup=butIMArg contains=@butText
120 " Default argument (due to being last).
121 syn region butTextArg matchgroup=butDelimiter start="{" skip="\\}" end="}" nextgroup=@butArgument contained contains=@butText transparent
122
123 " Rune from vim 6.1 help
124 if 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
158 endif
159
160 " b: local to current buffer
161 let b:current_syntax = "halibut"