@@ -39,7 +39,7 @@ def flush(self):pass
39
39
def vim_variable (name , default = None ):
40
40
exists = int (vim .eval ("exists('%s')" % name ))
41
41
return vim .eval (name ) if exists else default
42
-
42
+
43
43
def vim_regex_escape (x ):
44
44
for old , new in (("[" , "\\ [" ), ("]" , "\\ ]" ), (":" , "\\ :" ), ("." , "\." ), ("*" , "\\ *" )):
45
45
x = x .replace (old , new )
@@ -122,7 +122,7 @@ def km_from_string(s=''):
122
122
except ImportError :
123
123
# < 0.12, no find_connection_file
124
124
pass
125
-
125
+
126
126
global km , kc , send
127
127
128
128
s = s .replace ('--existing' , '' )
@@ -183,7 +183,7 @@ def km_from_string(s=''):
183
183
klass = sc .__class__
184
184
klass ._oinfo_orig = klass .object_info
185
185
klass .object_info = lambda s ,x ,y : s ._oinfo_orig (x )
186
-
186
+
187
187
#XXX: backwards compatibility for IPython < 1.0
188
188
if not hasattr (kc , 'iopub_channel' ):
189
189
kc .iopub_channel = kc .sub_channel
@@ -399,14 +399,17 @@ def update_subchannel_msgs(debug=False, force=False):
399
399
# TODO: alllow for distinguishing between stdout and stderr (using
400
400
# custom syntax markers in the vim-ipython buffer perhaps), or by
401
401
# 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' :
404
407
s = status_prompt_out % {'line' : m ['content' ]['execution_count' ]}
405
408
s += m ['content' ]['data' ]['text/plain' ]
406
409
elif header == 'display_data' :
407
410
# TODO: handle other display data types (HMTL? images?)
408
411
s += m ['content' ]['data' ]['text/plain' ]
409
- elif header == 'pyin' :
412
+ elif header == 'pyin' or header == 'execute_input' :
410
413
# TODO: the next line allows us to resend a line to ipython if
411
414
# %doctest_mode is on. In the future, IPython will send the
412
415
# execution_count on subchannel, so this will need to be updated
@@ -424,7 +427,7 @@ def update_subchannel_msgs(debug=False, force=False):
424
427
s += c ['ename' ] + ":" + c ['evalue' ]
425
428
426
429
if s .find ('\n ' ) == - 1 :
427
- # somewhat ugly unicode workaround from
430
+ # somewhat ugly unicode workaround from
428
431
# http://vim.1045645.n5.nabble.com/Limitations-of-vim-python-interface-with-respect-to-character-encodings-td1223881.html
429
432
if isinstance (s ,unicode ):
430
433
s = s .encode (vim_encoding )
@@ -444,7 +447,7 @@ def update_subchannel_msgs(debug=False, force=False):
444
447
if not startedin_vimipython :
445
448
vim .command ('normal! p' ) # go back to where you were
446
449
return update_occured
447
-
450
+
448
451
def get_child_msg (msg_id ):
449
452
# XXX: message handling should be split into its own process in the future
450
453
while True :
@@ -456,7 +459,7 @@ def get_child_msg(msg_id):
456
459
#got a message, but not the one we were looking for
457
460
echo ('skipping a message on shell_channel' ,'WarningMsg' )
458
461
return m
459
-
462
+
460
463
def print_prompt (prompt ,msg_id = None ):
461
464
"""Print In[] or In[42] style messages"""
462
465
global show_execution_count
@@ -554,7 +557,6 @@ def set_pid():
554
557
global pid
555
558
lines = '\n ' .join (['import os' , '_pid = os.getpid()' ])
556
559
msg_id = send (lines , silent = True , user_variables = ['_pid' ])
557
-
558
560
# wait to get message back from kernel
559
561
try :
560
562
child = get_child_msg (msg_id )
@@ -565,6 +567,9 @@ def set_pid():
565
567
pid = int (child ['content' ]['user_variables' ]['_pid' ])
566
568
except TypeError : # change in IPython 1.0.dev moved this out
567
569
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' ])
568
573
except KeyError : # change in IPython 1.0.dev moved this out
569
574
echo ("Could not get PID information, kernel not running Python?" )
570
575
return pid
@@ -608,7 +613,7 @@ def dedent_run_this_line():
608
613
609
614
def dedent_run_these_lines ():
610
615
run_these_lines (True )
611
-
616
+
612
617
#def set_this_line():
613
618
# # not sure if there's a way to do this, since we have multiple clients
614
619
# send("get_ipython().shell.set_next_input(\'%s\')" % vim.current.line.replace("\'","\\\'"))
@@ -625,9 +630,9 @@ def toggle_reselect():
625
630
#def set_breakpoint():
626
631
# send("__IP.InteractiveTB.pdb.set_break('%s',%d)" % (vim.current.buffer.name,
627
632
# 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,
629
634
# vim.current.window.cursor[0]))
630
- #
635
+ #
631
636
#def clear_breakpoint():
632
637
# send("__IP.InteractiveTB.pdb.clear_break('%s',%d)" % (vim.current.buffer.name,
633
638
# vim.current.window.cursor[0]))
0 commit comments