|
@@ -0,0 +1,307 @@
|
|
1
|
+" Vim syntax file
|
|
2
|
+" Language: Python
|
|
3
|
+" Maintainer: Dmitry Vasiliev <dima@hlabs.spb.ru>
|
|
4
|
+" URL: http://www.hlabs.spb.ru/vim/python.vim
|
|
5
|
+" Last Change: $Date$
|
|
6
|
+" Filenames: *.py
|
|
7
|
+" Version: 2.6.1
|
|
8
|
+" $Rev$
|
|
9
|
+"
|
|
10
|
+" Based on python.vim (from Vim 6.1 distribution)
|
|
11
|
+" by Neil Schemenauer <nas@python.ca>
|
|
12
|
+"
|
|
13
|
+" Thanks:
|
|
14
|
+"
|
|
15
|
+" Jeroen Ruigrok van der Werven
|
|
16
|
+" for the idea of highlighting for erroneous operators
|
|
17
|
+" Pedro Algarvio
|
|
18
|
+" for the patch to enable spell checking only for the right spots
|
|
19
|
+" (strings and comments)
|
|
20
|
+" John Eikenberry
|
|
21
|
+" for the patch fixing small typo
|
|
22
|
+
|
|
23
|
+"
|
|
24
|
+" Options:
|
|
25
|
+"
|
|
26
|
+" For set option do: let OPTION_NAME = 1
|
|
27
|
+" For clear option do: let OPTION_NAME = 0
|
|
28
|
+"
|
|
29
|
+" Option names:
|
|
30
|
+"
|
|
31
|
+" For highlight builtin functions:
|
|
32
|
+" python_highlight_builtins
|
|
33
|
+"
|
|
34
|
+" For highlight standard exceptions:
|
|
35
|
+" python_highlight_exceptions
|
|
36
|
+"
|
|
37
|
+" For highlight string formatting:
|
|
38
|
+" python_highlight_string_formatting
|
|
39
|
+"
|
|
40
|
+" For highlight indentation errors:
|
|
41
|
+" python_highlight_indent_errors
|
|
42
|
+"
|
|
43
|
+" For highlight trailing spaces:
|
|
44
|
+" python_highlight_space_errors
|
|
45
|
+"
|
|
46
|
+" For highlight doc-tests:
|
|
47
|
+" python_highlight_doctests
|
|
48
|
+"
|
|
49
|
+" If you want all possible Python highlighting:
|
|
50
|
+" (This option not override previously set options)
|
|
51
|
+" python_highlight_all
|
|
52
|
+"
|
|
53
|
+" For fast machines:
|
|
54
|
+" python_slow_sync
|
|
55
|
+"
|
|
56
|
+
|
|
57
|
+" For version 5.x: Clear all syntax items
|
|
58
|
+" For version 6.x: Quit when a syntax file was already loaded
|
|
59
|
+if version < 600
|
|
60
|
+ syntax clear
|
|
61
|
+elseif exists("b:current_syntax")
|
|
62
|
+ finish
|
|
63
|
+endif
|
|
64
|
+
|
|
65
|
+if exists("python_highlight_all") && python_highlight_all != 0
|
|
66
|
+ " Not override previously set options
|
|
67
|
+ if !exists("python_highlight_builtins")
|
|
68
|
+ let python_highlight_builtins = 1
|
|
69
|
+ endif
|
|
70
|
+ if !exists("python_highlight_exceptions")
|
|
71
|
+ let python_highlight_exceptions = 1
|
|
72
|
+ endif
|
|
73
|
+ if !exists("python_highlight_string_formatting")
|
|
74
|
+ let python_highlight_string_formatting = 1
|
|
75
|
+ endif
|
|
76
|
+ if !exists("python_highlight_indent_errors")
|
|
77
|
+ let python_highlight_indent_errors = 1
|
|
78
|
+ endif
|
|
79
|
+ if !exists("python_highlight_space_errors")
|
|
80
|
+ let python_highlight_space_errors = 1
|
|
81
|
+ endif
|
|
82
|
+ if !exists("python_highlight_doctests")
|
|
83
|
+ let python_highlight_doctests = 1
|
|
84
|
+ endif
|
|
85
|
+endif
|
|
86
|
+
|
|
87
|
+" Keywords
|
|
88
|
+syn keyword pythonStatement break continue del
|
|
89
|
+syn keyword pythonStatement exec return
|
|
90
|
+syn keyword pythonStatement pass raise
|
|
91
|
+syn keyword pythonStatement global assert
|
|
92
|
+syn keyword pythonStatement lambda yield
|
|
93
|
+syn keyword pythonStatement with
|
|
94
|
+syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
|
|
95
|
+syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
|
|
96
|
+syn keyword pythonRepeat for while
|
|
97
|
+syn keyword pythonConditional if elif else
|
|
98
|
+syn keyword pythonImport import from as
|
|
99
|
+syn keyword pythonException try except finally
|
|
100
|
+syn keyword pythonOperator and in is not or
|
|
101
|
+
|
|
102
|
+" Decorators (new in Python 2.4)
|
|
103
|
+syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite
|
|
104
|
+
|
|
105
|
+" Comments
|
|
106
|
+syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
|
|
107
|
+syn match pythonRun "\%^#!.*$"
|
|
108
|
+syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
|
|
109
|
+syn keyword pythonTodo TODO FIXME XXX contained
|
|
110
|
+
|
|
111
|
+" Errors
|
|
112
|
+syn match pythonError "\<\d\+\D\+\>" display
|
|
113
|
+syn match pythonError "[$?]" display
|
|
114
|
+syn match pythonError "[-+&|]\{2,}" display
|
|
115
|
+syn match pythonError "[=]\{3,}" display
|
|
116
|
+
|
|
117
|
+" TODO: Mixing spaces and tabs also may be used for pretty formatting multiline
|
|
118
|
+" statements. For now I don't know how to work around this.
|
|
119
|
+if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0
|
|
120
|
+ syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display
|
|
121
|
+endif
|
|
122
|
+
|
|
123
|
+" Trailing space errors
|
|
124
|
+if exists("python_highlight_space_errors") && python_highlight_space_errors != 0
|
|
125
|
+ syn match pythonSpaceError "\s\+$" display
|
|
126
|
+endif
|
|
127
|
+
|
|
128
|
+" Strings
|
|
129
|
+syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
|
|
130
|
+syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
|
|
131
|
+syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
132
|
+syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
133
|
+
|
|
134
|
+syn match pythonEscape +\\[abfnrtv'"\\]+ display contained
|
|
135
|
+syn match pythonEscape "\\\o\o\=\o\=" display contained
|
|
136
|
+syn match pythonEscapeError "\\\o\{,2}[89]" display contained
|
|
137
|
+syn match pythonEscape "\\x\x\{2}" display contained
|
|
138
|
+syn match pythonEscapeError "\\x\x\=\X" display contained
|
|
139
|
+syn match pythonEscape "\\$"
|
|
140
|
+
|
|
141
|
+" Unicode strings
|
|
142
|
+syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
|
|
143
|
+syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
|
|
144
|
+syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
145
|
+syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
146
|
+
|
|
147
|
+syn match pythonUniEscape "\\u\x\{4}" display contained
|
|
148
|
+syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
|
|
149
|
+syn match pythonUniEscape "\\U\x\{8}" display contained
|
|
150
|
+syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
|
|
151
|
+syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
|
|
152
|
+syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
|
|
153
|
+
|
|
154
|
+" Raw strings
|
|
155
|
+syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
|
156
|
+syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
|
157
|
+syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
|
158
|
+syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
|
159
|
+
|
|
160
|
+syn match pythonRawEscape +\\['"]+ display transparent contained
|
|
161
|
+
|
|
162
|
+" Unicode raw strings
|
|
163
|
+syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
|
|
164
|
+syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
|
|
165
|
+syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
166
|
+syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
167
|
+
|
|
168
|
+syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
|
|
169
|
+syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
|
|
170
|
+
|
|
171
|
+if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
|
|
172
|
+ " String formatting
|
|
173
|
+ syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
|
|
174
|
+ syn match pythonStrFormat "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
|
|
175
|
+endif
|
|
176
|
+
|
|
177
|
+if exists("python_highlight_doctests") && python_highlight_doctests != 0
|
|
178
|
+ " DocTests
|
|
179
|
+ syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
|
|
180
|
+ syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
|
|
181
|
+endif
|
|
182
|
+
|
|
183
|
+" Numbers (ints, longs, floats, complex)
|
|
184
|
+syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display
|
|
185
|
+syn match pythonHexNumber "\<0[xX]\>" display
|
|
186
|
+syn match pythonNumber "\<\d\+[lLjJ]\=\>" display
|
|
187
|
+syn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display
|
|
188
|
+syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
|
|
189
|
+syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display
|
|
190
|
+
|
|
191
|
+syn match pythonOctalError "\<0\o*[89]\d*[lL]\=\>" display
|
|
192
|
+syn match pythonHexError "\<0[xX]\X\+[lL]\=\>" display
|
|
193
|
+
|
|
194
|
+if exists("python_highlight_builtins") && python_highlight_builtins != 0
|
|
195
|
+ " Builtin functions, types and objects
|
|
196
|
+ syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented __debug__
|
|
197
|
+
|
|
198
|
+ syn keyword pythonBuiltinFunc __import__ abs all any apply
|
|
199
|
+ syn keyword pythonBuiltinFunc basestring bool buffer callable
|
|
200
|
+ syn keyword pythonBuiltinFunc chr classmethod cmp coerce compile complex
|
|
201
|
+ syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
|
|
202
|
+ syn keyword pythonBuiltinFunc execfile file filter float frozenset getattr
|
|
203
|
+ syn keyword pythonBuiltinFunc globals hasattr hash help hex id
|
|
204
|
+ syn keyword pythonBuiltinFunc input int intern isinstance
|
|
205
|
+ syn keyword pythonBuiltinFunc issubclass iter len list locals long map max
|
|
206
|
+ syn keyword pythonBuiltinFunc min next object oct open ord
|
|
207
|
+ syn keyword pythonBuiltinFunc pow print property range
|
|
208
|
+ syn keyword pythonBuiltinFunc raw_input reduce reload repr
|
|
209
|
+ syn keyword pythonBuiltinFunc reversed round set setattr
|
|
210
|
+ syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
|
|
211
|
+ syn keyword pythonBuiltinFunc type unichr unicode vars xrange zip
|
|
212
|
+endif
|
|
213
|
+
|
|
214
|
+if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
|
|
215
|
+ " Builtin exceptions and warnings
|
|
216
|
+ syn keyword pythonExClass BaseException
|
|
217
|
+ syn keyword pythonExClass Exception StandardError ArithmeticError
|
|
218
|
+ syn keyword pythonExClass LookupError EnvironmentError
|
|
219
|
+
|
|
220
|
+ syn keyword pythonExClass AssertionError AttributeError EOFError
|
|
221
|
+ syn keyword pythonExClass FloatingPointError GeneratorExit IOError
|
|
222
|
+ syn keyword pythonExClass ImportError IndexError KeyError
|
|
223
|
+ syn keyword pythonExClass KeyboardInterrupt MemoryError NameError
|
|
224
|
+ syn keyword pythonExClass NotImplementedError OSError OverflowError
|
|
225
|
+ syn keyword pythonExClass ReferenceError RuntimeError StopIteration
|
|
226
|
+ syn keyword pythonExClass SyntaxError IndentationError TabError
|
|
227
|
+ syn keyword pythonExClass SystemError SystemExit TypeError
|
|
228
|
+ syn keyword pythonExClass UnboundLocalError UnicodeError
|
|
229
|
+ syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
|
|
230
|
+ syn keyword pythonExClass UnicodeTranslateError ValueError
|
|
231
|
+ syn keyword pythonExClass WindowsError ZeroDivisionError
|
|
232
|
+
|
|
233
|
+ syn keyword pythonExClass Warning UserWarning DeprecationWarning
|
|
234
|
+ syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
|
|
235
|
+ syn keyword pythonExClass RuntimeWarning FutureWarning
|
|
236
|
+ syn keyword pythonExClass ImportWarning UnicodeWarning
|
|
237
|
+endif
|
|
238
|
+
|
|
239
|
+if exists("python_slow_sync") && python_slow_sync != 0
|
|
240
|
+ syn sync minlines=2000
|
|
241
|
+else
|
|
242
|
+ " This is fast but code inside triple quoted strings screws it up. It
|
|
243
|
+ " is impossible to fix because the only way to know if you are inside a
|
|
244
|
+ " triple quoted string is to start from the beginning of the file.
|
|
245
|
+ syn sync match pythonSync grouphere NONE "):$"
|
|
246
|
+ syn sync maxlines=200
|
|
247
|
+endif
|
|
248
|
+
|
|
249
|
+if version >= 508 || !exists("did_python_syn_inits")
|
|
250
|
+ if version <= 508
|
|
251
|
+ let did_python_syn_inits = 1
|
|
252
|
+ command -nargs=+ HiLink hi link <args>
|
|
253
|
+ else
|
|
254
|
+ command -nargs=+ HiLink hi def link <args>
|
|
255
|
+ endif
|
|
256
|
+
|
|
257
|
+ HiLink pythonStatement Statement
|
|
258
|
+ HiLink pythonImport Statement
|
|
259
|
+ HiLink pythonFunction Function
|
|
260
|
+ HiLink pythonConditional Conditional
|
|
261
|
+ HiLink pythonRepeat Repeat
|
|
262
|
+ HiLink pythonException Exception
|
|
263
|
+ HiLink pythonOperator Operator
|
|
264
|
+
|
|
265
|
+ HiLink pythonDecorator Define
|
|
266
|
+
|
|
267
|
+ HiLink pythonComment Comment
|
|
268
|
+ HiLink pythonCoding Special
|
|
269
|
+ HiLink pythonRun Special
|
|
270
|
+ HiLink pythonTodo Todo
|
|
271
|
+
|
|
272
|
+ HiLink pythonError Error
|
|
273
|
+ HiLink pythonIndentError Error
|
|
274
|
+ HiLink pythonSpaceError Error
|
|
275
|
+
|
|
276
|
+ HiLink pythonString String
|
|
277
|
+ HiLink pythonUniString String
|
|
278
|
+ HiLink pythonRawString String
|
|
279
|
+ HiLink pythonUniRawString String
|
|
280
|
+
|
|
281
|
+ HiLink pythonEscape Special
|
|
282
|
+ HiLink pythonEscapeError Error
|
|
283
|
+ HiLink pythonUniEscape Special
|
|
284
|
+ HiLink pythonUniEscapeError Error
|
|
285
|
+ HiLink pythonUniRawEscape Special
|
|
286
|
+ HiLink pythonUniRawEscapeError Error
|
|
287
|
+
|
|
288
|
+ HiLink pythonStrFormat Special
|
|
289
|
+
|
|
290
|
+ HiLink pythonDocTest Special
|
|
291
|
+ HiLink pythonDocTest2 Special
|
|
292
|
+
|
|
293
|
+ HiLink pythonNumber Number
|
|
294
|
+ HiLink pythonHexNumber Number
|
|
295
|
+ HiLink pythonFloat Float
|
|
296
|
+ HiLink pythonOctalError Error
|
|
297
|
+ HiLink pythonHexError Error
|
|
298
|
+
|
|
299
|
+ HiLink pythonBuiltinObj Structure
|
|
300
|
+ HiLink pythonBuiltinFunc Function
|
|
301
|
+
|
|
302
|
+ HiLink pythonExClass Structure
|
|
303
|
+
|
|
304
|
+ delcommand HiLink
|
|
305
|
+endif
|
|
306
|
+
|
|
307
|
+let b:current_syntax = "python"
|