Quantcast

A useful couple of scripts

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

A useful couple of scripts

Erich-17
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.

_______________________________________________
IPython-user mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-user

ipserver.py (6K) Download Attachment
ipy.vim (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: A useful couple of scripts

Ville M. Vainio
On Mon, Mar 3, 2008 at 2:43 AM, Erich Heine <[hidden email]> wrote:

> There are 2 files:
> ipserver.py -- this file contains the ipython stuff
> ipy.vim -- this file contains the gvim stuff

Did you check out Extensions/ipy_server.py in the ipython development
version? Does it do what you want?

--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
_______________________________________________
IPython-user mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: A useful couple of scripts

Erich-17


On Mon, Mar 3, 2008 at 2:31 AM, Ville M. Vainio <[hidden email]> wrote:
On Mon, Mar 3, 2008 at 2:43 AM, Erich Heine <[hidden email]> wrote:

> There are 2 files:
> ipserver.py -- this file contains the ipython stuff
> ipy.vim -- this file contains the gvim stuff

Did you check out Extensions/ipy_server.py in the ipython development
version? Does it do what you want?
 
I hadn't checked that out. What i wrote is like that, but more in depth.  Im wondering it there isnt a misunderstandint here, as i wrote scripts and am sharing them. Im not making a request. Did the files i attached to my email make it to the list? If not I can see the source of confusion.

Regards,
Erich



_______________________________________________
IPython-user mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: A useful couple of scripts

Ville M. Vainio
On Mon, Mar 3, 2008 at 4:34 PM, Erich Heine <[hidden email]> wrote:

> I hadn't checked that out. What i wrote is like that, but more in depth.  Im
> wondering it there isnt a misunderstandint here, as i wrote scripts and am
> sharing them. Im not making a request. Did the files i attached to my email
> make it to the list? If not I can see the source of confusion.

No, I am merely asking whether you checked them out and saw them
lacking. ipy_server is just a quick hack I wrote to kill a trac
ticket, and if you took a look at it and think yours is better, I
would be very happy to replace ipy_server.py with your implementation
(even if you didn't request it), ipy_server.py is not even released
yout.

What I'm saying here is, I suppose there is a sizable portion of
people who would like to see vim and ipython integrated the way you
did, and I could add your contribution to IPython/Extensions (and the
vim side to doc/examples), even if you didn't specifically request it.

--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
_______________________________________________
IPython-user mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-user
dpo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: A useful couple of scripts

dpo
On Mon, Mar 3, 2008 at 11:23 AM, Ville M. Vainio <[hidden email]> wrote:

> On Mon, Mar 3, 2008 at 4:34 PM, Erich Heine <[hidden email]> wrote:
>
>  > I hadn't checked that out. What i wrote is like that, but more in depth.  Im
>  > wondering it there isnt a misunderstandint here, as i wrote scripts and am
>  > sharing them. Im not making a request. Did the files i attached to my email
>  > make it to the list? If not I can see the source of confusion.
>
>  No, I am merely asking whether you checked them out and saw them
>  lacking. ipy_server is just a quick hack I wrote to kill a trac
>  ticket, and if you took a look at it and think yours is better, I
>  would be very happy to replace ipy_server.py with your implementation
>  (even if you didn't request it), ipy_server.py is not even released
>  yout.
>
>  What I'm saying here is, I suppose there is a sizable portion of
>  people who would like to see vim and ipython integrated the way you
>  did, and I could add your contribution to IPython/Extensions (and the
>  vim side to doc/examples), even if you didn't specifically request it.

Here's my vote for Vim/IPython integration!

Dominique
_______________________________________________
IPython-user mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: A useful couple of scripts

Erich-17
In reply to this post by Ville M. Vainio
First off, I think maybe my last email came off more confrontational than I intended. This is my fault, sorry about that. I broke Erich's rule of Internet Usage #1: Don't try to communicate before coffee.

On Mon, Mar 3, 2008 at 10:23 AM, Ville M. Vainio <[hidden email]> wrote:
On Mon, Mar 3, 2008 at 4:34 PM, Erich Heine <[hidden email]> wrote:

> I hadn't checked that out. What i wrote is like that, but more in depth.  Im
> wondering it there isnt a misunderstandint here, as i wrote scripts and am
> sharing them. Im not making a request. Did the files i attached to my email
> make it to the list? If not I can see the source of confusion.

No, I am merely asking whether you checked them out and saw them
lacking. ipy_server is just a quick hack I wrote to kill a trac
ticket, and if you took a look at it and think yours is better, I
would be very happy to replace ipy_server.py with your implementation
(even if you didn't request it), ipy_server.py is not even released
yout.
 
I did check it out after you mentioned it. The ipy_server.py implemenation is different from mine. Yours is ip, mine is unix_domain socket, so perhaps they can co-exist :).  I looked at the SocketServer stuff, but I couldn't find an easy way to have it shut down the server, and with a unix domain socket, I needed the ability to shut it down manually and remove the socket file.


What I'm saying here is, I suppose there is a sizable portion of
people who would like to see vim and ipython integrated the way you
did, and I could add your contribution to IPython/Extensions (and the
vim side to doc/examples), even if you didn't specifically request it.

If you want to add it, please do. I was just posting it to the group for feedback, and if people like it, for their use. Addition to the Extension  repo certainly helps that goal :).

_______________________________________________
IPython-user mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: A useful couple of scripts

Ville M. Vainio
In reply to this post by Ville M. Vainio
On Mon, Mar 3, 2008 at 6:23 PM, Ville M. Vainio <[hidden email]> wrote:

>  No, I am merely asking whether you checked them out and saw them
>  lacking. ipy_server is just a quick hack I wrote to kill a trac
>  ticket, and if you took a look at it and think yours is better, I
>  would be very happy to replace ipy_server.py with your implementation
>  (even if you didn't request it), ipy_server.py is not even released
>  yout.

This is now in bzr, though I renamed it to ipy_simserver.py. ipy.vim
is in doc/examples.

--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
_______________________________________________
IPython-user mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: A useful couple of scripts

Ville M. Vainio
On Sun, Mar 16, 2008 at 5:29 PM, Ville M. Vainio <[hidden email]> wrote:

>  This is now in bzr, though I renamed it to ipy_simserver.py. ipy.vim

ipy_vimserver.py, of course.

--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
_______________________________________________
IPython-user mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-user
Loading...