Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 20e192b

Browse files
committed
Update for 'with' statement.
1 parent a9f0687 commit 20e192b

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

Misc/Vim/python.vim

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ if exists("python_highlight_all")
1414
let python_highlight_space_errors = 1
1515
endif
1616

17-
syn keyword pythonStatement assert break continue del except exec finally
18-
syn keyword pythonStatement global lambda pass print raise return try yield
17+
syn keyword pythonStatement as assert break continue del except exec finally
18+
syn keyword pythonStatement global lambda pass print raise return try with
19+
syn keyword pythonStatement yield
1920

2021
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
2122

@@ -82,8 +83,9 @@ if exists("python_highlight_exceptions")
8283
syn keyword pythonException UnicodeTranslateError MemoryError StopIteration
8384
syn keyword pythonException PendingDeprecationWarning EnvironmentError
8485
syn keyword pythonException LookupError OSError DeprecationWarning
85-
syn keyword pythonException UnicodeError FloatingPointError ReferenceError
86-
syn keyword pythonException NameError OverflowWarning IOError SyntaxError
86+
syn keyword pythonException UnicodeError UnicodeEncodeError
87+
syn keyword pythonException FloatingPointError ReferenceError NameError
88+
syn keyword pythonException OverflowWarning IOError SyntaxError
8789
syn keyword pythonException FutureWarning SystemExit Exception EOFError
8890
syn keyword pythonException StandardError ValueError TabError KeyError
8991
syn keyword pythonException ZeroDivisionError SystemError
@@ -92,7 +94,7 @@ if exists("python_highlight_exceptions")
9294
syn keyword pythonException RuntimeWarning KeyboardInterrupt UserWarning
9395
syn keyword pythonException SyntaxWarning UnboundLocalError ArithmeticError
9496
syn keyword pythonException Warning NotImplementedError AttributeError
95-
syn keyword pythonException OverflowError UnicodeEncodeError
97+
syn keyword pythonException OverflowError BaseException
9698

9799
endif
98100

Misc/Vim/syntax_test.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,28 @@
1313
# OPTIONAL: XXX catch your attention
1414

1515
# Statements
16+
from __future__ import with_statement # Import
17+
from sys import path as thing
1618
assert True # keyword
1719
def foo(): # function definition
1820
return []
1921
class Bar(object): # Class definition
20-
pass
22+
def __context__(self):
23+
return self
24+
def __enter__(self):
25+
pass
26+
def __exit__(self, *args):
27+
pass
2128
foo() # UNCOLOURED: function call
2229
while False: # 'while'
2330
continue
2431
for x in foo(): # 'for'
2532
break
33+
with Bar() as stuff:
34+
pass
2635
if False: pass # 'if'
2736
elif False: pass
28-
else False: pass
29-
from sys import path as thing # Import
37+
else: pass
3038

3139
# Constants
3240
'single-quote', u'unicode' # Strings of all kinds; prefixes not highlighted

Misc/Vim/vim_syntax.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import with_statement
2+
13
import keyword
24
import exceptions
35
import __builtin__
@@ -143,11 +145,9 @@ def fill_stmt(iterable, fill_len):
143145
except StopIteration:
144146
if buffer_:
145147
break
146-
if not buffer_ and overflow:
147-
yield buffer_
148-
return
149-
else:
150-
return
148+
if overflow:
149+
yield overflow
150+
return
151151
if total_len > fill_len:
152152
overflow = buffer_.pop()
153153
total_len -= len(overflow) - 1
@@ -158,8 +158,7 @@ def fill_stmt(iterable, fill_len):
158158
FILL = 80
159159

160160
def main(file_path):
161-
FILE = open(file_path, 'w')
162-
try:
161+
with open(file_path, 'w') as FILE:
163162
# Comment for file
164163
print>>FILE, comment_header
165164
print>>FILE, ''
@@ -222,8 +221,6 @@ def main(file_path):
222221
print>>FILE, ''
223222
# Statements at the end of the file
224223
print>>FILE, statement_footer
225-
finally:
226-
FILE.close()
227224

228225
if __name__ == '__main__':
229226
main("python.vim")

0 commit comments

Comments
 (0)