IPython - Enhanced Interactive Python

Support in readline bash's operate-and-get-next behavior

Reported by Fernando Perez on 2009-06-02
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
IPython
Confirmed
Wishlist
Unassigned

Bug Description

This was reported as a wishlist item from the Sage developers, below is the full conversation.

It is a wishlist item for a type of history behavior that GNU readline doesn't offer by default but that is very appreciated by users of Magma (which behaves in this form). From communications by the readline maintainer, apparently this can be implemented client-side, so in principle ipython could offer it, though at this point I don't know how to (haven't looked into it in any detail).

Python's readline does offer the necessary hook:

In [2]: readline.*hook*?
readline.__subclasshook__
readline.set_completion_display_matches_hook
readline.set_pre_input_hook
readline.set_startup_hook # this one

Original email from sage-dev follows:

---------- Forwarded message ----------
From: Kwankyu <email address hidden>
Date: Thu, May 28, 2009 at 5:03 PM
Subject: [sage-devel] A command line feature - operate and get next history line
To: sage-devel <email address hidden>

Hi,

I got a reply from GNU readline maintainer Chet Ramey to the following
wish letter.
---------------
Dear Readline Maintainer,

I am a user of Sage, a computer algebra system relying on GNU readline
library. In Sage FAQ, you can find the following article. (Magma is
another computer algebra system relying on "readline" via IPython)
1. Why is Sage's command history different than Magma's

   * QUESTION: Using Sage, I am missing a feature of Magma command
line interface. In Magma, if I enter a line found in history using up
arrow key, and then press down arrow key, then the next line in
history is fetched. This feature allows me to fetch as many successive
lines in history as like. Does Sage(or readline) have a similar
feature?

   * ANSWER: No, Sage does not have a similar feature. The IPython
command prompt uses the readline library (via pyreadline), which
evidently doesn't support this feature. Magma has its own custom
"readline-like" library, which does support this feature. (Since so
many people have requested this feature, if anybody can figure out how
to implement it, then such an implementation would certainly be
welcome!)

It seems that the only way Sage can have the convenient feature is
that GNU readline library have such a feature in its history facility.
I wish this happens in the new version of the GNU readline library.
Thank you for your attention. Have a nice day.
----------

From Chet Ramey:
----------
The answer is that this is very similar to the operate-and-get-next
feature bash adds to the readline interface. I am not inclined to add this to
readline in its current form because it manipulates state managed by
the calling application (rl_startup_hook) and requires that state to be
kept between calls to readline(). It's a feature that should be provided
by the calling application -- it's implementation is not complicated.
----------

Fernando Perez (fdo.perez) wrote :

Patches welcome.

Changed in ipython:
importance: Undecided → Wishlist
status: New → Confirmed
sandro dentella (sandro-e-den) wrote :

It's a pity I'm not able to submit a patch for this, but surely this would be a *great* feature to have in ipython. While 'ed 1:3' & similar are great when you are in the same session, if you restart ipython you cannot do that and being able to cherry pick the lines to run would be a real time saving feature!

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers