Mercurial > hg > RemoteEditor > vim7
comparison runtime/syntax/python.vim @ 0:76efa0be13f1
Initial revision
author | atsuki |
---|---|
date | Sat, 10 Nov 2007 15:07:22 +0900 |
parents | |
children | c16898406ff2 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:76efa0be13f1 |
---|---|
1 " Vim syntax file | |
2 " Language: Python | |
3 " Maintainer: Neil Schemenauer <nas@python.ca> | |
4 " Updated: 2006-10-15 | |
5 " Added Python 2.4 features 2006 May 4 (Dmitry Vasiliev) | |
6 " | |
7 " Options to control Python syntax highlighting: | |
8 " | |
9 " For highlighted numbers: | |
10 " | |
11 " let python_highlight_numbers = 1 | |
12 " | |
13 " For highlighted builtin functions: | |
14 " | |
15 " let python_highlight_builtins = 1 | |
16 " | |
17 " For highlighted standard exceptions: | |
18 " | |
19 " let python_highlight_exceptions = 1 | |
20 " | |
21 " Highlight erroneous whitespace: | |
22 " | |
23 " let python_highlight_space_errors = 1 | |
24 " | |
25 " If you want all possible Python highlighting (the same as setting the | |
26 " preceding options): | |
27 " | |
28 " let python_highlight_all = 1 | |
29 " | |
30 | |
31 " For version 5.x: Clear all syntax items | |
32 " For version 6.x: Quit when a syntax file was already loaded | |
33 if version < 600 | |
34 syntax clear | |
35 elseif exists("b:current_syntax") | |
36 finish | |
37 endif | |
38 | |
39 | |
40 syn keyword pythonStatement break continue del | |
41 syn keyword pythonStatement except exec finally | |
42 syn keyword pythonStatement pass print raise | |
43 syn keyword pythonStatement return try with | |
44 syn keyword pythonStatement global assert | |
45 syn keyword pythonStatement lambda yield | |
46 syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite | |
47 syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" contained | |
48 syn keyword pythonRepeat for while | |
49 syn keyword pythonConditional if elif else | |
50 syn keyword pythonOperator and in is not or | |
51 " AS will be a keyword in Python 3 | |
52 syn keyword pythonPreCondit import from as | |
53 syn match pythonComment "#.*$" contains=pythonTodo,@Spell | |
54 syn keyword pythonTodo TODO FIXME XXX contained | |
55 | |
56 " Decorators (new in Python 2.4) | |
57 syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite | |
58 | |
59 " strings | |
60 syn region pythonString matchgroup=Normal start=+[uU]\='+ end=+'+ skip=+\\\\\|\\'+ contains=pythonEscape,@Spell | |
61 syn region pythonString matchgroup=Normal start=+[uU]\="+ end=+"+ skip=+\\\\\|\\"+ contains=pythonEscape,@Spell | |
62 syn region pythonString matchgroup=Normal start=+[uU]\="""+ end=+"""+ contains=pythonEscape,@Spell | |
63 syn region pythonString matchgroup=Normal start=+[uU]\='''+ end=+'''+ contains=pythonEscape,@Spell | |
64 syn region pythonRawString matchgroup=Normal start=+[uU]\=[rR]'+ end=+'+ skip=+\\\\\|\\'+ contains=@Spell | |
65 syn region pythonRawString matchgroup=Normal start=+[uU]\=[rR]"+ end=+"+ skip=+\\\\\|\\"+ contains=@Spell | |
66 syn region pythonRawString matchgroup=Normal start=+[uU]\=[rR]"""+ end=+"""+ contains=@Spell | |
67 syn region pythonRawString matchgroup=Normal start=+[uU]\=[rR]'''+ end=+'''+ contains=@Spell | |
68 syn match pythonEscape +\\[abfnrtv'"\\]+ contained | |
69 syn match pythonEscape "\\\o\{1,3}" contained | |
70 syn match pythonEscape "\\x\x\{2}" contained | |
71 syn match pythonEscape "\(\\u\x\{4}\|\\U\x\{8}\)" contained | |
72 syn match pythonEscape "\\$" | |
73 | |
74 if exists("python_highlight_all") | |
75 let python_highlight_numbers = 1 | |
76 let python_highlight_builtins = 1 | |
77 let python_highlight_exceptions = 1 | |
78 let python_highlight_space_errors = 1 | |
79 endif | |
80 | |
81 if exists("python_highlight_numbers") | |
82 " numbers (including longs and complex) | |
83 syn match pythonNumber "\<0x\x\+[Ll]\=\>" | |
84 syn match pythonNumber "\<\d\+[LljJ]\=\>" | |
85 syn match pythonNumber "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" | |
86 syn match pythonNumber "\<\d\+\.\([eE][+-]\=\d\+\)\=[jJ]\=\>" | |
87 syn match pythonNumber "\<\d\+\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" | |
88 endif | |
89 | |
90 if exists("python_highlight_builtins") | |
91 " builtin functions, types and objects, not really part of the syntax | |
92 syn keyword pythonBuiltin True False bool enumerate set frozenset help | |
93 syn keyword pythonBuiltin reversed sorted sum | |
94 syn keyword pythonBuiltin Ellipsis None NotImplemented __import__ abs | |
95 syn keyword pythonBuiltin apply buffer callable chr classmethod cmp | |
96 syn keyword pythonBuiltin coerce compile complex delattr dict dir divmod | |
97 syn keyword pythonBuiltin eval execfile file filter float getattr globals | |
98 syn keyword pythonBuiltin hasattr hash hex id input int intern isinstance | |
99 syn keyword pythonBuiltin issubclass iter len list locals long map max | |
100 syn keyword pythonBuiltin min object oct open ord pow property range | |
101 syn keyword pythonBuiltin raw_input reduce reload repr round setattr | |
102 syn keyword pythonBuiltin slice staticmethod str super tuple type unichr | |
103 syn keyword pythonBuiltin unicode vars xrange zip | |
104 endif | |
105 | |
106 if exists("python_highlight_exceptions") | |
107 " builtin exceptions and warnings | |
108 syn keyword pythonException ArithmeticError AssertionError AttributeError | |
109 syn keyword pythonException DeprecationWarning EOFError EnvironmentError | |
110 syn keyword pythonException Exception FloatingPointError IOError | |
111 syn keyword pythonException ImportError IndentationError IndexError | |
112 syn keyword pythonException KeyError KeyboardInterrupt LookupError | |
113 syn keyword pythonException MemoryError NameError NotImplementedError | |
114 syn keyword pythonException OSError OverflowError OverflowWarning | |
115 syn keyword pythonException ReferenceError RuntimeError RuntimeWarning | |
116 syn keyword pythonException StandardError StopIteration SyntaxError | |
117 syn keyword pythonException SyntaxWarning SystemError SystemExit TabError | |
118 syn keyword pythonException TypeError UnboundLocalError UnicodeError | |
119 syn keyword pythonException UnicodeEncodeError UnicodeDecodeError | |
120 syn keyword pythonException UnicodeTranslateError | |
121 syn keyword pythonException UserWarning ValueError Warning WindowsError | |
122 syn keyword pythonException ZeroDivisionError | |
123 endif | |
124 | |
125 if exists("python_highlight_space_errors") | |
126 " trailing whitespace | |
127 syn match pythonSpaceError display excludenl "\S\s\+$"ms=s+1 | |
128 " mixed tabs and spaces | |
129 syn match pythonSpaceError display " \+\t" | |
130 syn match pythonSpaceError display "\t\+ " | |
131 endif | |
132 | |
133 " This is fast but code inside triple quoted strings screws it up. It | |
134 " is impossible to fix because the only way to know if you are inside a | |
135 " triple quoted string is to start from the beginning of the file. If | |
136 " you have a fast machine you can try uncommenting the "sync minlines" | |
137 " and commenting out the rest. | |
138 syn sync match pythonSync grouphere NONE "):$" | |
139 syn sync maxlines=200 | |
140 "syn sync minlines=2000 | |
141 | |
142 if version >= 508 || !exists("did_python_syn_inits") | |
143 if version <= 508 | |
144 let did_python_syn_inits = 1 | |
145 command -nargs=+ HiLink hi link <args> | |
146 else | |
147 command -nargs=+ HiLink hi def link <args> | |
148 endif | |
149 | |
150 " The default methods for highlighting. Can be overridden later | |
151 HiLink pythonStatement Statement | |
152 HiLink pythonFunction Function | |
153 HiLink pythonConditional Conditional | |
154 HiLink pythonRepeat Repeat | |
155 HiLink pythonString String | |
156 HiLink pythonRawString String | |
157 HiLink pythonEscape Special | |
158 HiLink pythonOperator Operator | |
159 HiLink pythonPreCondit PreCondit | |
160 HiLink pythonComment Comment | |
161 HiLink pythonTodo Todo | |
162 HiLink pythonDecorator Define | |
163 if exists("python_highlight_numbers") | |
164 HiLink pythonNumber Number | |
165 endif | |
166 if exists("python_highlight_builtins") | |
167 HiLink pythonBuiltin Function | |
168 endif | |
169 if exists("python_highlight_exceptions") | |
170 HiLink pythonException Exception | |
171 endif | |
172 if exists("python_highlight_space_errors") | |
173 HiLink pythonSpaceError Error | |
174 endif | |
175 | |
176 delcommand HiLink | |
177 endif | |
178 | |
179 let b:current_syntax = "python" | |
180 | |
181 " vim: ts=8 |