Opened 8 years ago

Closed 7 years ago

#12503 closed enhancement (fixed)

Convenient history fetch commands

Reported by: klee Owned by: was
Priority: minor Milestone: sage-5.3
Component: user interface Keywords:
Cc: Merged in: sage-5.3.beta0
Authors: Kwankyu Lee Reviewers: Dmitrii Pasechnik
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by jdemeyer)

Using Sage, you are missing a feature of the Magma command line interface. In Magma, if you 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 you to fetch as many successive lines in history as you like. However, Sage does not have a similar feature. The IPython command prompt uses the readline library (via pyreadline), which evidently does not 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!)

This ticket addresses the above implementation.

apply trac_12503_v4.patch

Attachments (7)

trac_10289.patch (10.3 KB) - added by klee 8 years ago.
the same
trac#12503.patch (10.3 KB) - added by klee 8 years ago.
changed the commit message
trac_12503.patch (10.1 KB) - added by klee 8 years ago.
rebased on 5.0.beta12
trac_12503_v1.patch (10.1 KB) - added by klee 8 years ago.
removed trailing spaces
trac_12503_v2.patch (10.1 KB) - added by klee 8 years ago.
rebased on 5.0.beta12
trac_12503_v3.patch (10.4 KB) - added by klee 7 years ago.
rebased on 5.1.rc0
trac_12503_v4.patch (10.8 KB) - added by klee 7 years ago.
modified to respond to the reviews

Download all attachments as: .zip

Change History (37)

comment:1 follow-up: Changed 8 years ago by jhpalmieri

Is this a duplicate of #10289?

comment:2 in reply to: ↑ 1 ; follow-up: Changed 8 years ago by klee

Replying to jhpalmieri:

Is this a duplicate of #10289?

Yes. I created this because I found no way to trigger the patchbot for the patch in #10289. I hope the patchbot works for this duplicate ticket.

I will add a comment on #10289 right now.

comment:3 Changed 8 years ago by klee

  • Status changed from new to needs_review

comment:4 in reply to: ↑ 2 Changed 8 years ago by kcrisman

Replying to klee:

Replying to jhpalmieri:

Is this a duplicate of #10289?

Yes. I created this because I found no way to trigger the patchbot for the patch in #10289. I hope the patchbot works for this duplicate ticket.

Just FYI, we can still give patches positive review even if the patchbot is screwing up. Maybe you should give #10289 positive review with milestone sage-duplicate? (Or maybe this one should be the duplicate, since it's a later-opened ticket.)

Also, you might want to rename the patch and change the commit message :-)

comment:5 Changed 8 years ago by klee

I think I am paranoic with the patchbot! Anyway the last patch would pass the patchbot. How can I remove the first patch, and trigger the patchbot with the new patch? :-)

Please someone review this patch.

Changed 8 years ago by klee

the same

comment:6 Changed 8 years ago by klee

The three patches are the same with different names. Sorry.

Changed 8 years ago by klee

changed the commit message

comment:7 Changed 8 years ago by klee

apply trac_12503.patch

Last edited 8 years ago by klee (previous) (diff)

comment:8 Changed 8 years ago by klee

Apply trac_12503.patch

Changed 8 years ago by klee

rebased on 5.0.beta12

Changed 8 years ago by klee

removed trailing spaces

comment:9 Changed 8 years ago by klee

Last edited 8 years ago by klee (previous) (diff)

comment:10 Changed 8 years ago by klee

Apply trac_12503_v2.patch

Last edited 8 years ago by klee (previous) (diff)

Changed 8 years ago by klee

rebased on 5.0.beta12

comment:11 Changed 7 years ago by klee

apply trac_12503_v3.patch

comment:12 Changed 7 years ago by kini

abra cadabra!

apply trac_12503_v3.patch

voila!

comment:13 Changed 7 years ago by kini

  • Milestone changed from sage-5.1 to sage-5.2

Changed 7 years ago by klee

rebased on 5.1.rc0

comment:14 Changed 7 years ago by klee

apply trac_12503_v3.patch

comment:15 follow-up: Changed 7 years ago by iandrus

I tried using this a few times before but could never bind it to Control-o so I gave up. I have an inputrc file and several other customizations that I thought might be interfering, but could never figure it out. Today I finally took the time and so I'm putting it here in case others have the same problem. Below is what happens as best I understand it. I'm on OS X 10.6.

Before readline gets a character sequence it's interpreted by the terminal emulator and can be used to do things like turn flow control on and off. These are generally bound to Control-s and Control-q and is, I think, fairly well known (at least I knew it). However, there are other actions as well which can be determined by running stty -a and reading the cchars section. In my case control-o was bound to discard. These extra bindings can be turned of by running

# Enable Ctrl-o
stty -iexten
# Enable Ctrl-s and Ctrl-q
stty -ixon

or by unbinding them individually like

stty discard undef
...

comment:16 follow-ups: Changed 7 years ago by kcrisman

I just have to ask whether this would change current behavior in the command line. That is, would anything change for someone who didn't bind any metakeys, or didn't even really know what it was all about and was afraid of things like Emacs?

comment:17 in reply to: ↑ 16 Changed 7 years ago by iandrus

Replying to kcrisman:

I just have to ask whether this would change current behavior in the command line. That is, would anything change for someone who didn't bind any metakeys, or didn't even really know what it was all about and was afraid of things like Emacs?

The current patch doesn't bind them, though I think it should. If they were bound by default (to whatever Magma uses) then they would be more discoverable, and I think the only difference (beyond perhaps a minuscule performance penalty) would be Ctl-o, which I think isn't used for anything right now. It would be good to have it confirmed that Ctl-n and Ctl-p are backwards compatible and Ctl-o is unused.

I skimmed the code and documentation and I noticed that on line 245 unbounded should be unbound. Sadly, I don't know Cython well enough to feel comfortable reviewing it, though I can say it has been working fine for me (after I got my issues sorted out). I think it would be nice to add a sentence to the documentation about stty -iexten etc.

comment:18 in reply to: ↑ 15 ; follow-ups: Changed 7 years ago by klee

Replying to iandrus:

I tried using this a few times before but could never bind it to Control-o so I gave up. I have an inputrc file and several other customizations that I thought might be interfering, but could never figure it out. Today I finally took the time and so I'm putting it here in case others have the same problem. Below is what happens as best I understand it. I'm on OS X 10.6.

Did you add the relevant lines into the "ipythonrc" as indicated in the documentation? You don't modify inputrc file in your home folder.

To bind these commands with keys, insert the relevant lines into the ``$DOT_SAGE/ipython/ipythonrc``
file. Note that ``$DOT_SAGE`` is ``$HOME/.sage`` by default. For example,

::

    readline_parse_and_bind "\C-o": operate-and-get-next
    readline_parse_and_bind "\e[A": history-search-backward-and-save
    readline_parse_and_bind "\e[B": history-search-forward-and-save

binds the three commands with the control-o key, the up arrow key, and the down arrow key,
respectively.           

comment:19 in reply to: ↑ 16 ; follow-up: Changed 7 years ago by klee

Replying to kcrisman:

I just have to ask whether this would change current behavior in the command line. That is, would anything change for someone who didn't bind any metakeys, or didn't even really know what it was all about and was afraid of things like Emacs?

This patch does not chanage anything before you put some relevant lines to the "ipythonrc" file in your dot_sage folder.

comment:20 in reply to: ↑ 18 ; follow-up: Changed 7 years ago by dimpase

Replying to klee:

I can confirm that this (GAP history settings) works on OSX 10.6. Shouldn't this go into documentation?

comment:21 in reply to: ↑ 20 Changed 7 years ago by dimpase

  • Status changed from needs_review to positive_review

Replying to dimpase:

Replying to klee:

I can confirm that this (GAP history settings) works on OSX 10.6. Shouldn't this go into documentation?

OK, it is there already! Positive review :)

Changed 7 years ago by klee

modified to respond to the reviews

comment:22 Changed 7 years ago by klee

Apply trac_12503_v4.patch

Thank you for all reviews!

comment:23 Changed 7 years ago by dimpase

  • Description modified (diff)

comment:24 in reply to: ↑ 18 Changed 7 years ago by iandrus

Replying to klee:

Replying to iandrus:

I tried using this a few times before but could never bind it to Control-o so I gave up. I have an inputrc file and several other customizations that I thought might be interfering, but could never figure it out. Today I finally took the time and so I'm putting it here in case others have the same problem. Below is what happens as best I understand it. I'm on OS X 10.6.

Did you add the relevant lines into the "ipythonrc" as indicated in the documentation? You don't modify inputrc file in your home folder.

Yes. I tried both and several other variations as well. My problem was due entirely to the fact that somewhere stty iexten (or the equivalent) was being called and so it was impossible to get the C-o binding to work in any terminal application.

comment:25 Changed 7 years ago by jdemeyer

  • Milestone changed from sage-5.2 to sage-5.3
  • Reviewers set to Dmitrii Pasechnik

comment:26 in reply to: ↑ 19 Changed 7 years ago by kcrisman

I just have to ask whether this would change current behavior in the command line. That is, would anything change for someone who didn't bind any metakeys, or didn't even really know what it was all about and was afraid of things like Emacs?

This patch does not chanage anything before you put some relevant lines to the "ipythonrc" file in your dot_sage folder.

Sweet, thanks for confirming. Of course, now I might be tempted to do so...

comment:27 Changed 7 years ago by jdemeyer

  • Description modified (diff)

comment:28 Changed 7 years ago by jdemeyer

  • Description modified (diff)

comment:29 Changed 7 years ago by jdemeyer

  • Description modified (diff)

comment:30 Changed 7 years ago by jdemeyer

  • Merged in set to sage-5.3.beta0
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.