Mercurial > vim
comparison runtime/syntax/python.vim @ 10319:169a62d5bcb9
commit https://github.com/vim/vim/commit/b4ada79aa7d0d1e5da3a659b1a203d7cae9f7f59
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 30 21:55:26 2016 +0100
Runtime file updates.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 30 Oct 2016 22:00:04 +0100 |
parents | b7da8d4c594c |
children | ef454a7f485d |
comparison
equal
deleted
inserted
replaced
10318:a0279bd5d079 | 10319:169a62d5bcb9 |
---|---|
1 " Vim syntax file | 1 " Vim syntax file |
2 " Language: Python | 2 " Language: Python |
3 " Maintainer: Zvezdan Petkovic <zpetkovic@acm.org> | 3 " Maintainer: Zvezdan Petkovic <zpetkovic@acm.org> |
4 " Last Change: 2016 Sep 14 | 4 " Last Change: 2016 Oct 29 |
5 " Credits: Neil Schemenauer <nas@python.ca> | 5 " Credits: Neil Schemenauer <nas@python.ca> |
6 " Dmitry Vasiliev | 6 " Dmitry Vasiliev |
7 " | 7 " |
8 " This version is a major rewrite by Zvezdan Petkovic. | 8 " This version is a major rewrite by Zvezdan Petkovic. |
9 " | 9 " |
43 | 43 |
44 " We need nocompatible mode in order to continue lines with backslashes. | 44 " We need nocompatible mode in order to continue lines with backslashes. |
45 " Original setting will be restored. | 45 " Original setting will be restored. |
46 let s:cpo_save = &cpo | 46 let s:cpo_save = &cpo |
47 set cpo&vim | 47 set cpo&vim |
48 | |
49 if exists("python_no_doctest_highlight") | |
50 let python_no_doctest_code_highlight = 1 | |
51 endif | |
52 | |
53 if exists("python_highlight_all") | |
54 if exists("python_no_builtin_highlight") | |
55 unlet python_no_builtin_highlight | |
56 endif | |
57 if exists("python_no_doctest_code_highlight") | |
58 unlet python_no_doctest_code_highlight | |
59 endif | |
60 if exists("python_no_doctest_highlight") | |
61 unlet python_no_doctest_highlight | |
62 endif | |
63 if exists("python_no_exception_highlight") | |
64 unlet python_no_exception_highlight | |
65 endif | |
66 if exists("python_no_number_highlight") | |
67 unlet python_no_number_highlight | |
68 endif | |
69 let python_space_error_highlight = 1 | |
70 endif | |
48 | 71 |
49 " Keep Python keywords in alphabetical order inside groups for easy | 72 " Keep Python keywords in alphabetical order inside groups for easy |
50 " comparison with the table in the 'Python Language Reference' | 73 " comparison with the table in the 'Python Language Reference' |
51 " https://docs.python.org/2/reference/lexical_analysis.html#keywords, | 74 " https://docs.python.org/2/reference/lexical_analysis.html#keywords, |
52 " https://docs.python.org/3/reference/lexical_analysis.html#keywords. | 75 " https://docs.python.org/3/reference/lexical_analysis.html#keywords. |
79 syn keyword pythonException except finally raise try | 102 syn keyword pythonException except finally raise try |
80 syn keyword pythonInclude from import | 103 syn keyword pythonInclude from import |
81 syn keyword pythonAsync async await | 104 syn keyword pythonAsync async await |
82 | 105 |
83 " Decorators (new in Python 2.4) | 106 " Decorators (new in Python 2.4) |
84 " Python 3.5 introduced the use of the same symbol for matrix | |
85 " multiplication. We now have to exclude the symbol from being | |
86 " highlighted when used in that context. Hence, the check that it's | |
87 " preceded by empty space only (possibly in a docstring/doctest) and | |
88 " followed by decorator name, optional parenthesized list of arguments, | |
89 " and the next line with either def, class, or another decorator. | |
90 syn match pythonDecorator | |
91 \ "\%(\%(^\s*\)\%(\%(>>>\|\.\.\.\)\s\+\)\=\)\zs@\%(\s*\h\%(\w\|\.\)*\s*\%((\_\s\{-}[^)]\_.\{-})\s*\)\=\%(#.*\)\=\n\s*\%(\.\.\.\s\+\)\=\%(@\s*\h\|\%(def\|class\)\s\+\)\)\@=" | |
92 \ display nextgroup=pythonDecoratorName skipwhite | |
93 | |
94 " A dot must be allowed because of @MyClass.myfunc decorators. | 107 " A dot must be allowed because of @MyClass.myfunc decorators. |
95 " It must be preceded by a decorator symbol and on a separate line from | 108 syn match pythonDecorator "@" display contained |
96 " a function/class it decorates. | 109 syn match pythonDecoratorName "@\s*\h\%(\w\|\.\)*" display contains=pythonDecorator |
97 syn match pythonDecoratorName | 110 |
98 \ "\%(@\s*\)\@<=\h\%(\w\|\.\)*\%(\s*\%((\_\s\{-}[^)]\_.\{-})\s*\)\=\%(#.*\)\=\n\)\@=" | 111 " Python 3.5 introduced the use of the same symbol for matrix multiplication: |
99 \ contained display nextgroup=pythonFunction skipnl | 112 " https://www.python.org/dev/peps/pep-0465/. We now have to exclude the |
100 | 113 " symbol from highlighting when used in that context. |
101 " The zero-length non-grouping match of def or class before the function | 114 " Single line multiplication. |
102 " name is extremely important in pythonFunction. Without it, everything | 115 syn match pythonMatrixMultiply |
103 " is interpreted as a function inside the contained environment of | 116 \ "\%(\w\|[])]\)\s*@" |
104 " doctests. | 117 \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue |
105 syn match pythonFunction | 118 \ transparent |
106 \ "\%(\%(^\s*\)\%(\%(>>>\|\.\.\.\)\s\+\)\=\%(def\|class\)\s\+\)\@<=\h\w*" | 119 " Multiplication continued on the next line after backslash. |
107 \ contained | 120 syn match pythonMatrixMultiply |
121 \ "[^\\]\\\s*\n\%(\s*\.\.\.\s\)\=\s\+@" | |
122 \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue | |
123 \ transparent | |
124 " Multiplication in a parenthesized expression over multiple lines with @ at | |
125 " the start of each continued line; very similar to decorators and complex. | |
126 syn match pythonMatrixMultiply | |
127 \ "^\s*\%(\%(>>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*" | |
128 \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue | |
129 \ transparent | |
130 | |
131 syn match pythonFunction "\h\w*" display contained | |
108 | 132 |
109 syn match pythonComment "#.*$" contains=pythonTodo,@Spell | 133 syn match pythonComment "#.*$" contains=pythonTodo,@Spell |
110 syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained | 134 syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained |
111 | 135 |
112 " Triple-quoted strings can contain doctests. | 136 " Triple-quoted strings can contain doctests. |
128 syn match pythonEscape "\\x\x\{2}" contained | 152 syn match pythonEscape "\\x\x\{2}" contained |
129 syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained | 153 syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained |
130 " Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/ | 154 " Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/ |
131 syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained | 155 syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained |
132 syn match pythonEscape "\\$" | 156 syn match pythonEscape "\\$" |
133 | |
134 if exists("python_highlight_all") | |
135 if exists("python_no_builtin_highlight") | |
136 unlet python_no_builtin_highlight | |
137 endif | |
138 if exists("python_no_doctest_code_highlight") | |
139 unlet python_no_doctest_code_highlight | |
140 endif | |
141 if exists("python_no_doctest_highlight") | |
142 unlet python_no_doctest_highlight | |
143 endif | |
144 if exists("python_no_exception_highlight") | |
145 unlet python_no_exception_highlight | |
146 endif | |
147 if exists("python_no_number_highlight") | |
148 unlet python_no_number_highlight | |
149 endif | |
150 let python_space_error_highlight = 1 | |
151 endif | |
152 | 157 |
153 " It is very important to understand all details before changing the | 158 " It is very important to understand all details before changing the |
154 " regular expressions below or their order. | 159 " regular expressions below or their order. |
155 " The word boundaries are *not* the floating-point number boundaries | 160 " The word boundaries are *not* the floating-point number boundaries |
156 " because of a possible leading or trailing decimal point. | 161 " because of a possible leading or trailing decimal point. |
211 " Python 3 only | 216 " Python 3 only |
212 syn keyword pythonBuiltin ascii bytes exec | 217 syn keyword pythonBuiltin ascii bytes exec |
213 " non-essential built-in functions; Python 2 only | 218 " non-essential built-in functions; Python 2 only |
214 syn keyword pythonBuiltin apply buffer coerce intern | 219 syn keyword pythonBuiltin apply buffer coerce intern |
215 " avoid highlighting attributes as builtins | 220 " avoid highlighting attributes as builtins |
216 syn match pythonAttribute /\.\h\w*/hs=s+1 contains=ALLBUT,pythonBuiltin transparent | 221 syn match pythonAttribute /\.\h\w*/hs=s+1 |
222 \ contains=ALLBUT,pythonBuiltin,pythonFunction,pythonAsync | |
223 \ transparent | |
217 endif | 224 endif |
218 | 225 |
219 " From the 'Python Library Reference' class hierarchy at the bottom. | 226 " From the 'Python Library Reference' class hierarchy at the bottom. |
220 " http://docs.python.org/2/library/exceptions.html | 227 " http://docs.python.org/2/library/exceptions.html |
221 " http://docs.python.org/3/library/exceptions.html | 228 " http://docs.python.org/3/library/exceptions.html |
273 " doctest too. Thus, we do *not* need to have it as an end pattern. | 280 " doctest too. Thus, we do *not* need to have it as an end pattern. |
274 if !exists("python_no_doctest_highlight") | 281 if !exists("python_no_doctest_highlight") |
275 if !exists("python_no_doctest_code_highlight") | 282 if !exists("python_no_doctest_code_highlight") |
276 syn region pythonDoctest | 283 syn region pythonDoctest |
277 \ start="^\s*>>>\s" end="^\s*$" | 284 \ start="^\s*>>>\s" end="^\s*$" |
278 \ contained contains=ALLBUT,pythonDoctest,@Spell | 285 \ contained contains=ALLBUT,pythonDoctest,pythonFunction,@Spell |
279 syn region pythonDoctestValue | 286 syn region pythonDoctestValue |
280 \ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$" | 287 \ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$" |
281 \ contained | 288 \ contained |
282 else | 289 else |
283 syn region pythonDoctest | 290 syn region pythonDoctest |
285 \ contained contains=@NoSpell | 292 \ contained contains=@NoSpell |
286 endif | 293 endif |
287 endif | 294 endif |
288 | 295 |
289 " Sync at the beginning of class, function, or method definition. | 296 " Sync at the beginning of class, function, or method definition. |
290 syn sync match pythonSync grouphere NONE "^\s*\%(def\|class\)\s\+\h\w*\s*(" | 297 syn sync match pythonSync grouphere NONE "^\%(def\|class\)\s\+\h\w*\s*[(:]" |
291 | 298 |
292 " The default highlight links. Can be overridden later. | 299 " The default highlight links. Can be overridden later. |
293 hi def link pythonStatement Statement | 300 hi def link pythonStatement Statement |
294 hi def link pythonConditional Conditional | 301 hi def link pythonConditional Conditional |
295 hi def link pythonRepeat Repeat | 302 hi def link pythonRepeat Repeat |