[IPython-user] A useful couple of scripts
Erich Heine
sophacles@gmail....
Sun Mar 2 18:43:49 CST 2008
Hi all,
Ive recently been playing with ipython, and like it quite a bit. I did
however discover a bit of frustration, namely with editor interaction. I am
a gvim user, and using the command edit on a new file causes ipython to try
and run that file as soon as the text editor opens up. The -x command of
course fixes this, but its still a bit annoying, switching windows to do a
run file, then back to the text editor. Being a heavy tab user in gvim,
another annoyance is not being able to specify weather a new tab is how I
choose to open the file.
Not being one to shirk my open source duties (and seeing this as a good
excuse to poke around ipython internals), Ive created a script for having
gvim and ipython work very nicely together. Ive attached both to this email
(hoping of course that the mailing list allows such things).
There are 2 files:
ipserver.py -- this file contains the ipython stuff
ipy.vim -- this file contains the gvim stuff
In combination they allow for a few functionalities:
1. the vim magic command. This is a fancy wrapper around the edit magic,
that allows for a new option, -t, which opens the text in a new gvim tab.
Otherwise it works the same as edit -x. (it internally calls edit -x). This
magic command also juggles vim server management, so when it is called when
there is not a gvim running, it creates a new gvim instance, named after the
ipython session name. Once such a gvim instance is running, it will be used
for subsequent uses of the vim command.
2. ipython - gvim interaction. Once a file has been opened with the vim
magic (and a session set up, see below), pressing the F5 key in vim will
cause the calling ipython instance to execute run filename.py. (if you typo
like I do, this is very useful)
3. ipython server - this is a thread wich listens on a unix domain socket,
and runs commands sent to that socket.
Note, this only works on POSIX systems, that allow for AF_UNIX type sockets.
It has only been tested on linux (a fairly recent debian testing distro).
To install it put, the ipserver.py in your favorite locaion for sourcing
ipython scripts. I put the ipy.vim in ~/.vim/after/ftplugin/python/.
To use (this can be scripted im sure, but i usually have 2 or 3 ipythons and
corresponding gvims open):
import ipserver
ipserver.setup('sessionname')
Then use ipython as you normally would, until you need to edit something.
Instead of edit, use the vim magic.
Thats it!
If anyone sees ways to improve this, please let me know. Also, if anyone can
think of a good way of allowing debugging interaction via this method, I'm
hoping for a way to do that with 0.8.x. Ipython1, from what I've seen of it
so far, appears to allow the debugging integration pretty easy (and the
above python integration...).
Regards and have fun
Erich
PS this code is public domain, in case anyone cares about licensing stuff.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ipython.scipy.org/pipermail/ipython-user/attachments/20080302/22dddbe7/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipserver.py
Type: text/x-python
Size: 4959 bytes
Desc: not available
Url : http://lists.ipython.scipy.org/pipermail/ipython-user/attachments/20080302/22dddbe7/attachment.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipy.vim
Type: application/octet-stream
Size: 1529 bytes
Desc: not available
Url : http://lists.ipython.scipy.org/pipermail/ipython-user/attachments/20080302/22dddbe7/attachment.obj
More information about the IPython-user
mailing list