Skip to content

Commit d9105f0

Browse files
committed
Py3K support. Three at last, three at last!
1 parent 0903296 commit d9105f0

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

TODO.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ This is a list of things I'm planning to work on with vim-ipython
66
[ ] opening docs while shell buffer is open somehow scroll-locks things, and
77
does not compute the proper length
88

9-
[ ] split up vim-specific things from python-specific things
9+
[x] split up vim-specific things from python-specific things
1010
(make it easier to become py3k compliant)
1111

12-
[ ] py3k support
12+
[x] py3k support
1313

1414
[ ] vim ipython magic has no documentation that gets installed (fix this)
1515

@@ -26,7 +26,7 @@ This is a list of things I'm planning to work on with vim-ipython
2626
ping about this once it lands:
2727
http://spaceli.wordpress.com/2013/10/04/add-vim-key-bindings-for-ipython-1-0-0/
2828

29-
[ ] make it possible to run :IPython command multiple times
29+
[x] make it possible to run :IPython command multiple times
3030
Traceback (most recent call last):
3131
File "<string>", line 1, in <module>
3232
File "<string>", line 116, in km_from_string
@@ -35,4 +35,8 @@ This is a list of things I'm planning to work on with vim-ipython
3535
File "/home/pi/code/ipython/IPython/config/configurable.py", line 367, in instance
3636
'%s are being created.' % cls.__name__
3737
IPython.config.configurable.MultipleInstanceError: Multiple incompatible subclass instances of BaseIPythonApplication are being created.
38+
39+
- This was actually an IPython limitation. Works fine in IPython rel-2.1.0
3840

41+
42+
[ ] support profiledir

ftplugin/python/vim_ipython.py

+18-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
run_flags= "-i" # flags to for IPython's run magic when using <F5>
55
current_line = ''
66

7-
from Queue import Empty
7+
try:
8+
from queue import Empty # python3 convention
9+
except ImportError:
10+
from Queue import Empty
811

912
try:
1013
import vim
@@ -13,7 +16,7 @@ class NoOp(object):
1316
def __getattribute__(self, key):
1417
return lambda *args: '0'
1518
vim = NoOp()
16-
print "uh oh, not running inside vim"
19+
print("uh oh, not running inside vim")
1720

1821
import sys
1922

@@ -87,7 +90,6 @@ def km_from_string(s=''):
8790
except ImportError:
8891
raise ImportError("Could not find IPython. " + _install_instructions)
8992
from IPython.config.loader import KeyValueConfigLoader
90-
from Queue import Empty
9193
try:
9294
from IPython.kernel import (
9395
KernelManager,
@@ -103,7 +105,7 @@ def km_from_string(s=''):
103105
# < 0.12, no find_connection_file
104106
pass
105107

106-
global km, kc, send, Empty
108+
global km, kc, send
107109

108110
s = s.replace('--existing', '')
109111
if 'connection_file' in KernelManager.class_trait_names():
@@ -123,7 +125,7 @@ def km_from_string(s=''):
123125
fullpath = find_connection_file(k,p)
124126
else:
125127
fullpath = find_connection_file(s.lstrip().rstrip())
126-
except IOError,e:
128+
except IOError as e:
127129
echo(":IPython " + s + " failed", "Info")
128130
echo("^-- failed '" + s + "' not found", "Error")
129131
return
@@ -141,7 +143,7 @@ def km_from_string(s=''):
141143
sub_address=(ip, cfg['iopub_port']),
142144
stdin_address=(ip, cfg['stdin_port']),
143145
hb_address=(ip, cfg['hb_port']))
144-
except KeyError,e:
146+
except KeyError as e:
145147
echo(":IPython " +s + " failed", "Info")
146148
echo("^-- failed --"+e.message.replace('_port','')+" not specified", "Error")
147149
return
@@ -194,7 +196,7 @@ def echo(arg,style="Question"):
194196
vim.command("echom \"%s\"" % arg.replace('\"','\\\"'))
195197
vim.command("echohl None")
196198
except vim.error:
197-
print "-- %s" % arg
199+
print("-- %s" % arg)
198200

199201
def disconnect():
200202
"disconnect kernel manager"
@@ -532,7 +534,7 @@ def run_these_lines(dedent=False):
532534
vim.command("normal! ")
533535

534536
#vim lines start with 1
535-
#print "lines %d-%d sent to ipython"% (r.start+1,r.end+1)
537+
#print("lines %d-%d sent to ipython"% (r.start+1,r.end+1))
536538
prompt = "lines %d-%d "% (r.start+1,r.end+1)
537539
print_prompt(prompt,msg_id)
538540

@@ -602,30 +604,31 @@ def dedent_run_these_lines():
602604
#def set_this_line():
603605
# # not sure if there's a way to do this, since we have multiple clients
604606
# send("get_ipython().shell.set_next_input(\'%s\')" % vim.current.line.replace("\'","\\\'"))
605-
# #print "line \'%s\' set at ipython prompt"% vim.current.line
607+
# #print("line \'%s\' set at ipython prompt"% vim.current.line)
606608
# echo("line \'%s\' set at ipython prompt"% vim.current.line,'Statement')
607609

608610

609611
def toggle_reselect():
610612
global reselect
611613
reselect=not reselect
612-
print "F9 will%sreselect lines after sending to ipython"% (reselect and " " or " not ")
614+
print("F9 will%sreselect lines after sending to ipython" %
615+
(reselect and " " or " not "))
613616

614617
#def set_breakpoint():
615618
# send("__IP.InteractiveTB.pdb.set_break('%s',%d)" % (vim.current.buffer.name,
616619
# vim.current.window.cursor[0]))
617-
# print "set breakpoint in %s:%d"% (vim.current.buffer.name,
618-
# vim.current.window.cursor[0])
620+
# print("set breakpoint in %s:%d"% (vim.current.buffer.name,
621+
# vim.current.window.cursor[0]))
619622
#
620623
#def clear_breakpoint():
621624
# send("__IP.InteractiveTB.pdb.clear_break('%s',%d)" % (vim.current.buffer.name,
622625
# vim.current.window.cursor[0]))
623-
# print "clearing breakpoint in %s:%d" % (vim.current.buffer.name,
624-
# vim.current.window.cursor[0])
626+
# print("clearing breakpoint in %s:%d" % (vim.current.buffer.name,
627+
# vim.current.window.cursor[0]))
625628
#
626629
#def clear_all_breakpoints():
627630
# send("__IP.InteractiveTB.pdb.clear_all_breaks()");
628-
# print "clearing all breakpoints"
631+
# print("clearing all breakpoints")
629632
#
630633
#def run_this_file_pdb():
631634
# send(' __IP.InteractiveTB.pdb.run(\'execfile("%s")\')' % (vim.current.buffer.name,))

0 commit comments

Comments
 (0)