IDLE history, Python IDE, and Interactive Python with Vim

A

Ashot

Hi,
This is sort of both Python and Vim related (which is why I've posted to
both newsgroups).

[...]

I know you've been using ipython recently (the readline color bugs), so perhaps
my reply is a bit redundant. Forgive me if that's the case, I just want to
give you some useful info.

Just in case you haven't come across these features (the manual is kind of long
and dry), I should note that ipython has pretty much everything you've asked
for here. %hist -n dumps your history without line numbers (for copy/paste),
%logstart gives you an incremental log (valid python code) of your current
session, %save allows you to save a selected group of lines to a file, and
%edit will open up $EDITOR (or vi in Unix by default) at the source of any
accessible object. With %pdb, you can even trigger automatically pdb at any
uncaught exception (in Emacs, you'll even get the source simultaneously opened,
I'm sure something similar could be done for vi).

yup, this is why I've been using it, its (almost exactly :) what I was looking for. I had tried it before, but was reluctant to use it because the windows terminal is not very appealing.
Some things I've noticed so far that I think could be improved, some of which are minor but annoying:

edit doesn't work with classes even though it says it should, you have to point it to a function in the class (perhaps only in windows)

under windows vim/gvim doesn't jump to the line of the function.. you said that this should work in vi, but I'm guessing its a Windows thing

**the biggest problem for me is edit forgets code in which there were errors. for example:"ed" type some nonsense, and ed -p doesn't remember. Thats putting an awful lot of pressure on getting the syntax right everytime =] Perhaps I am missing something here?

it would be really great if the code executed on save rather than exit, but I'm not sure if this is possible. This would be very useful for people using an editor not in the console.. that way you wouldn't have to keep opening/closing new editor windows.

this isn't a big deal, but it would be nice if there was an easy way to refer to the entire history (for edit/save/etc)

would be nice if you could send stuff to the clipboard.

Sorry, a few more things I forgot to mention having to do with editing multiline entries in the console:

Autotab setting doesn't seem to have any effect, I have to type "ctrl-o" manually

Is there a setting that treats multiline entries as a single command, as IDLE does? In otherwords, allowing you to edit the entire entry, going up to previous lines, and treating as one when cycling through the history? It seems like ipython recognizes these through the hist command, but not when editing or cycling.

Is it possible to use the "set editing-mode vi" option in ipython since it uses readline? From reading online, it seems like this should be possible, however it doesn't work for me. It works in bash, but once I enter either ipython or just regular python the keybindings don't work anymore.

Again, thanks for your help.

..a
 
F

Fernando Perez

Ashot said:
yup, this is why I've been using it, its (almost exactly :) what I was looking
for. I had tried it before, but was reluctant to use it because the windows
terminal is not very appealing. Some things I've noticed so far that I think
could be improved, some of which are minor but annoying:

I should note that I hardly use %edit myself, it's something that was added at
the request of users, and is an OK facility for quick and dirty work. But
getting such a system to work reliably in all cases, with the
import/execfile/reload issues at play, is really not easy. Especially because
it's not even completely clear what the 'right' behaviour should be. %edit
makes a few educated guesses, but that's it.

My personal coding environment consists of a permanently open editor with
multiple files open (XEmacs in my case), and an ipython session open. In
ipython, I use %run to run test code, and when said top-level test code relies
on modules which are also being changed, I simply put into the top-level
scripts reload() statements. This gives me the ipython tracebacks,
experimentation, tab-exploration of objects, etc, while I have the full power
of Xemacs for the real editing work.

IPython is NOT an IDE, so I think it's important to understand its limitations
to make the best possible use of it. Perhaps I haven't done a very good job of
outlining this to users, I don't know.
edit doesn't work with classes even though it says it should, you have to
point it to a function in the class (perhaps only in windows)

under windows vim/gvim doesn't jump to the line of the function.. you said
that this should work in vi, but I'm guessing its a Windows thing

Works for jed/vim under linux, that's about as much as I know. Probably a win32
thing, as you say.
**the biggest problem for me is edit forgets code in which there were errors.
for example:"ed" type some nonsense, and ed -p doesn't remember. Thats
putting an awful lot of pressure on getting the syntax right everytime =]
Perhaps I am missing something here?

Fixed. Will be in the next release, which will probably come out soon (I found
an unrelated crash case, and I consider crashes release-triggering bugfixes).
it would be really great if the code executed on save rather than exit, but
I'm not sure if this is possible. This would be very useful for people using
an editor not in the console.. that way you wouldn't have to keep
opening/closing new editor windows.

not possible in a cross-platform, cross-editor way.
this isn't a big deal, but it would be nice if there was an easy way to refer
to the entire history (for edit/save/etc)

%hist has options to print as many lines as you want. And the %log* commands
will dump all of your history straight to a file, and continue recording from
then on.
would be nice if you could send stuff to the clipboard.

Do you have a linux/OSX/win32 way to do it? If so, I'll gladly include it.
Under *nix, mouse-highlighting copies to the X11 primary selection, which I can
then paste anywhere with the middle button.
There are a few other things I'm probably forgetting, but having said all
that, I've come off a little negative here. I really like IPython so far, its
got all the things I was looking for, thank you very much for your work. If I
have the time in the future I would definately contribute to this project.

No problem, I appreciate the comments. Fair, honest criticism can only make a
project better. Note, however, that I _strongly_ suggest you post this kind of
stuff on the ipython list. While I monitor c.l.py via gmane, I'm not
subscribed and sometimes I'm too busy to read it for weeks at a time, so
there's a very good chance I'll simply miss ipython-related posts here. The
ipython lists, on the other hand, I keep a close eye on :)

Best,

f
 
F

Fernando Perez

Ashot said:
Sorry, a few more things I forgot to mention having to do with editing
multiline entries in the console:

Autotab setting doesn't seem to have any effect, I have to type "ctrl-o"
manually

I've noticed it doesn't work under win32. It's fine under *nix. There's only
so much Gary can do with his readline supplement in a win32 environment, I'm
not sure if this is something which he could add, you'd have to contact him
directly. This would require support for insertions into the current line,
which may not even be possible in a windows terminal, I just don't know.
Is there a setting that treats multiline entries as a single command, as IDLE
does? In otherwords, allowing you to edit the entire entry, going up to
previous lines, and treating as one when cycling through the history? It
seems like ipython recognizes these through the hist command, but not when
editing or cycling.

This is impossible in a line-oriented terminal program. What you are asking for
requires 2-d cursor control, which can only be provided in a gui environment,
or with curses in a terminal (or with custom terminal handling code).
Basically, it means writing a complete screen-handling program, which is far
more than ipython can do.

I keep trying to start an internal ipython cleanup, so it could be embedded into
a gui environment. Once that happens, it may be possible to use idle or
pycrust but with the ipython engine.

Within the design constraints of not taking over the terminal with a curses (or
similar) environment, restricted to onlw raw_input() communication with the
user, what you are asking is a technical impossibility.
Is it possible to use the "set editing-mode vi" option in ipython since it
uses readline? From reading online, it seems like this should be possible,
however it doesn't work for me. It works in bash, but once I enter either
ipython or just regular python the keybindings don't work anymore.

I don't know if this works even under *nix, since I don't know if the python
readline library wraps this part of GNU readline. I _do_ know that python only
wraps a subset of GNU readline, so I wouldn't be surprised if this wasn't
included. It is not something specific to ipython, you'd have to ask the
readline developers directly.

Best,

f
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top