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

Skip to content
This repository was archived by the owner on Dec 9, 2018. It is now read-only.

Commit 8c1c0ad

Browse files
committed
WIP: Support for IPython 3.0
1 parent a47d92b commit 8c1c0ad

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

ftplugin/python/vim_ipython.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def flush(self):pass
3939
def vim_variable(name, default=None):
4040
exists = int(vim.eval("exists('%s')" % name))
4141
return vim.eval(name) if exists else default
42-
42+
4343
def vim_regex_escape(x):
4444
for old, new in (("[", "\\["), ("]", "\\]"), (":", "\\:"), (".", "\."), ("*", "\\*")):
4545
x = x.replace(old, new)
@@ -122,7 +122,7 @@ def km_from_string(s=''):
122122
except ImportError:
123123
# < 0.12, no find_connection_file
124124
pass
125-
125+
126126
global km, kc, send
127127

128128
s = s.replace('--existing', '')
@@ -183,7 +183,7 @@ def km_from_string(s=''):
183183
klass = sc.__class__
184184
klass._oinfo_orig = klass.object_info
185185
klass.object_info = lambda s,x,y: s._oinfo_orig(x)
186-
186+
187187
#XXX: backwards compatibility for IPython < 1.0
188188
if not hasattr(kc, 'iopub_channel'):
189189
kc.iopub_channel = kc.sub_channel
@@ -399,14 +399,17 @@ def update_subchannel_msgs(debug=False, force=False):
399399
# TODO: alllow for distinguishing between stdout and stderr (using
400400
# custom syntax markers in the vim-ipython buffer perhaps), or by
401401
# also echoing the message to the status bar
402-
s = strip_color_escapes(m['content']['data'])
403-
elif header == 'pyout':
402+
try:
403+
s = strip_color_escapes(m['content']['data'])
404+
except KeyError: # changed in IPython 3.0.0
405+
s = strip_color_escapes(m['content']['text'])
406+
elif header == 'pyout' or header == 'execute_result':
404407
s = status_prompt_out % {'line': m['content']['execution_count']}
405408
s += m['content']['data']['text/plain']
406409
elif header == 'display_data':
407410
# TODO: handle other display data types (HMTL? images?)
408411
s += m['content']['data']['text/plain']
409-
elif header == 'pyin':
412+
elif header == 'pyin' or header == 'execute_input':
410413
# TODO: the next line allows us to resend a line to ipython if
411414
# %doctest_mode is on. In the future, IPython will send the
412415
# execution_count on subchannel, so this will need to be updated
@@ -424,7 +427,7 @@ def update_subchannel_msgs(debug=False, force=False):
424427
s += c['ename'] + ":" + c['evalue']
425428

426429
if s.find('\n') == -1:
427-
# somewhat ugly unicode workaround from
430+
# somewhat ugly unicode workaround from
428431
# http://vim.1045645.n5.nabble.com/Limitations-of-vim-python-interface-with-respect-to-character-encodings-td1223881.html
429432
if isinstance(s,unicode):
430433
s=s.encode(vim_encoding)
@@ -444,7 +447,7 @@ def update_subchannel_msgs(debug=False, force=False):
444447
if not startedin_vimipython:
445448
vim.command('normal! p') # go back to where you were
446449
return update_occured
447-
450+
448451
def get_child_msg(msg_id):
449452
# XXX: message handling should be split into its own process in the future
450453
while True:
@@ -456,7 +459,7 @@ def get_child_msg(msg_id):
456459
#got a message, but not the one we were looking for
457460
echo('skipping a message on shell_channel','WarningMsg')
458461
return m
459-
462+
460463
def print_prompt(prompt,msg_id=None):
461464
"""Print In[] or In[42] style messages"""
462465
global show_execution_count
@@ -554,7 +557,6 @@ def set_pid():
554557
global pid
555558
lines = '\n'.join(['import os', '_pid = os.getpid()'])
556559
msg_id = send(lines, silent=True, user_variables=['_pid'])
557-
558560
# wait to get message back from kernel
559561
try:
560562
child = get_child_msg(msg_id)
@@ -565,6 +567,9 @@ def set_pid():
565567
pid = int(child['content']['user_variables']['_pid'])
566568
except TypeError: # change in IPython 1.0.dev moved this out
567569
pid = int(child['content']['user_variables']['_pid']['data']['text/plain'])
570+
except KeyError: # change in IPython 3.0+
571+
pid = int(
572+
child['content']['user_expressions']['_pid']['data']['text/plain'])
568573
except KeyError: # change in IPython 1.0.dev moved this out
569574
echo("Could not get PID information, kernel not running Python?")
570575
return pid
@@ -608,7 +613,7 @@ def dedent_run_this_line():
608613

609614
def dedent_run_these_lines():
610615
run_these_lines(True)
611-
616+
612617
#def set_this_line():
613618
# # not sure if there's a way to do this, since we have multiple clients
614619
# send("get_ipython().shell.set_next_input(\'%s\')" % vim.current.line.replace("\'","\\\'"))
@@ -625,9 +630,9 @@ def toggle_reselect():
625630
#def set_breakpoint():
626631
# send("__IP.InteractiveTB.pdb.set_break('%s',%d)" % (vim.current.buffer.name,
627632
# vim.current.window.cursor[0]))
628-
# print("set breakpoint in %s:%d"% (vim.current.buffer.name,
633+
# print("set breakpoint in %s:%d"% (vim.current.buffer.name,
629634
# vim.current.window.cursor[0]))
630-
#
635+
#
631636
#def clear_breakpoint():
632637
# send("__IP.InteractiveTB.pdb.clear_break('%s',%d)" % (vim.current.buffer.name,
633638
# vim.current.window.cursor[0]))

0 commit comments

Comments
 (0)