@@ -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
@@ -247,6 +247,16 @@ def get_doc_msg(msg_id):
247
247
if not content ['found' ]:
248
248
return b
249
249
250
+ # IPython 3.0+ the documentation message is encoding by the kernel
251
+ if 'data' in content :
252
+ try :
253
+ text = content ['data' ]['text/plain' ]
254
+ for line in text .split ('\n ' ):
255
+ b .append (strip_color_escapes (line ).rstrip ())
256
+ return b
257
+ except KeyError : # no text/plain key
258
+ return b
259
+
250
260
for field in ['type_name' ,'base_class' ,'string_form' ,'namespace' ,
251
261
'file' ,'length' ,'definition' ,'source' ,'docstring' ]:
252
262
c = content .get (field ,None )
@@ -300,7 +310,10 @@ def get_doc_buffer(level=0):
300
310
vim .command ('setlocal syntax=python' )
301
311
302
312
def ipy_complete (base , current_line , pos ):
303
- msg_id = kc .shell_channel .complete (base , current_line , pos )
313
+ # pos is the location of the start of base, add the length
314
+ # to get the completion position
315
+ msg_id = kc .shell_channel .complete (base , current_line ,
316
+ int (pos ) + len (base ) - 1 )
304
317
try :
305
318
m = get_child_msg (msg_id )
306
319
matches = m ['content' ]['matches' ]
@@ -399,14 +412,17 @@ def update_subchannel_msgs(debug=False, force=False):
399
412
# TODO: alllow for distinguishing between stdout and stderr (using
400
413
# custom syntax markers in the vim-ipython buffer perhaps), or by
401
414
# also echoing the message to the status bar
402
- s = strip_color_escapes (m ['content' ]['data' ])
403
- elif header == 'pyout' :
415
+ try :
416
+ s = strip_color_escapes (m ['content' ]['data' ])
417
+ except KeyError : # changed in IPython 3.0.0
418
+ s = strip_color_escapes (m ['content' ]['text' ])
419
+ elif header == 'pyout' or header == 'execute_result' :
404
420
s = status_prompt_out % {'line' : m ['content' ]['execution_count' ]}
405
421
s += m ['content' ]['data' ]['text/plain' ]
406
422
elif header == 'display_data' :
407
423
# TODO: handle other display data types (HMTL? images?)
408
424
s += m ['content' ]['data' ]['text/plain' ]
409
- elif header == 'pyin' :
425
+ elif header == 'pyin' or header == 'execute_input' :
410
426
# TODO: the next line allows us to resend a line to ipython if
411
427
# %doctest_mode is on. In the future, IPython will send the
412
428
# execution_count on subchannel, so this will need to be updated
@@ -418,13 +434,13 @@ def update_subchannel_msgs(debug=False, force=False):
418
434
dots = '.' * len (prompt .rstrip ())
419
435
dots += prompt [len (prompt .rstrip ()):]
420
436
s += m ['content' ]['code' ].rstrip ().replace ('\n ' , '\n ' + dots )
421
- elif header == 'pyerr' :
437
+ elif header == 'pyerr' or header == 'error' :
422
438
c = m ['content' ]
423
439
s = "\n " .join (map (strip_color_escapes ,c ['traceback' ]))
424
440
s += c ['ename' ] + ":" + c ['evalue' ]
425
441
426
442
if s .find ('\n ' ) == - 1 :
427
- # somewhat ugly unicode workaround from
443
+ # somewhat ugly unicode workaround from
428
444
# http://vim.1045645.n5.nabble.com/Limitations-of-vim-python-interface-with-respect-to-character-encodings-td1223881.html
429
445
if isinstance (s ,unicode ):
430
446
s = s .encode (vim_encoding )
@@ -444,7 +460,7 @@ def update_subchannel_msgs(debug=False, force=False):
444
460
if not startedin_vimipython :
445
461
vim .command ('normal! p' ) # go back to where you were
446
462
return update_occured
447
-
463
+
448
464
def get_child_msg (msg_id ):
449
465
# XXX: message handling should be split into its own process in the future
450
466
while True :
@@ -456,7 +472,7 @@ def get_child_msg(msg_id):
456
472
#got a message, but not the one we were looking for
457
473
echo ('skipping a message on shell_channel' ,'WarningMsg' )
458
474
return m
459
-
475
+
460
476
def print_prompt (prompt ,msg_id = None ):
461
477
"""Print In[] or In[42] style messages"""
462
478
global show_execution_count
@@ -554,7 +570,6 @@ def set_pid():
554
570
global pid
555
571
lines = '\n ' .join (['import os' , '_pid = os.getpid()' ])
556
572
msg_id = send (lines , silent = True , user_variables = ['_pid' ])
557
-
558
573
# wait to get message back from kernel
559
574
try :
560
575
child = get_child_msg (msg_id )
@@ -565,6 +580,9 @@ def set_pid():
565
580
pid = int (child ['content' ]['user_variables' ]['_pid' ])
566
581
except TypeError : # change in IPython 1.0.dev moved this out
567
582
pid = int (child ['content' ]['user_variables' ]['_pid' ]['data' ]['text/plain' ])
583
+ except KeyError : # change in IPython 3.0+
584
+ pid = int (
585
+ child ['content' ]['user_expressions' ]['_pid' ]['data' ]['text/plain' ])
568
586
except KeyError : # change in IPython 1.0.dev moved this out
569
587
echo ("Could not get PID information, kernel not running Python?" )
570
588
return pid
@@ -608,7 +626,7 @@ def dedent_run_this_line():
608
626
609
627
def dedent_run_these_lines ():
610
628
run_these_lines (True )
611
-
629
+
612
630
#def set_this_line():
613
631
# # not sure if there's a way to do this, since we have multiple clients
614
632
# send("get_ipython().shell.set_next_input(\'%s\')" % vim.current.line.replace("\'","\\\'"))
@@ -625,9 +643,9 @@ def toggle_reselect():
625
643
#def set_breakpoint():
626
644
# send("__IP.InteractiveTB.pdb.set_break('%s',%d)" % (vim.current.buffer.name,
627
645
# vim.current.window.cursor[0]))
628
- # print("set breakpoint in %s:%d"% (vim.current.buffer.name,
646
+ # print("set breakpoint in %s:%d"% (vim.current.buffer.name,
629
647
# vim.current.window.cursor[0]))
630
- #
648
+ #
631
649
#def clear_breakpoint():
632
650
# send("__IP.InteractiveTB.pdb.clear_break('%s',%d)" % (vim.current.buffer.name,
633
651
# vim.current.window.cursor[0]))
0 commit comments