Re: Turning off readline

94 views
Skip to first unread message

Dima Pasechnik

unread,
Dec 11, 2012, 7:45:10 AM12/11/12
to sage-s...@googlegroups.com
On 2012-12-09, Jim Hefferon <jim.he...@gmail.com> wrote:
> ------=_Part_14_17388356.1355069188311
> Content-Type: text/plain; charset=ISO-8859-1
>
> I am trying to turn off the command line readline action.* If that were
> possible, it would be a big help to me. Does anyone know?
>
> I am running Sage on a recent Ubuntu, using a recent install. I believe
> the readline behavior arises from pyreadline that comes in as part of
> ipython. I can find no documentation in ipython on how to stop readline
> while the repl is running (which would be ideal for me) and I tried putting
> in a configuration file pyreadlineconfig.ini and uncommenting its second
> line, but that had no effect that I could see.
>
> $ head -n2 $HOME/pyreadlineconfig.ini
> #Bind keys for exit (keys only work on empty lines
> disable_readline(True) #Disable pyreadline completely.
>
> I also had a look in the source but came away unenlightened. Thanks for
> any help.
is pyreadline really used by Sage?
It seems to be only needed on Windows, where Sage does not run.


Jim Hefferon

unread,
Dec 11, 2012, 9:07:06 AM12/11/12
to sage-s...@googlegroups.com


On Tuesday, December 11, 2012 7:45:10 AM UTC-5, Dima Pasechnik wrote:
is pyreadline really used by Sage?
It seems to be only needed on Windows, where Sage does not run.

Thanks for your comment.  Probably I have it wrong.  I based my opinion on this from the Sage FAQ:
  http://wiki.sagemath.org/faq#Why_is_Sage.27s_command_history_different_than_Magma.27s
buttressed by the fact that if you type garbage into the repl then Sage gives an error message that refers to the "ipython console".  But evidence that I am wrong is that I also see readline-6.2.p3.spkg in my /usr/local/sage/spkg/standard directory, so I could be convinced either way. 

Assuming that Sage uses GNU readline, I spelunked the readline manual looking for a way to disable either dynamically or at startup and did not see anything.  I also have spent some time trying to influence the behavior of readline via INPUTRC, as here
  bash$ INPUTRC=./inputrc sage
but I observed no effect (in ./inputrc I tried setting horizontal-scroll-mode=off).  Could easily be my cluelessness that caused it to not work, though.

Obviously I'm thrashing here, so I'm glad for any insight.

Jason Grout

unread,
Dec 11, 2012, 9:15:20 AM12/11/12
to sage-s...@googlegroups.com
Sage has an expect interface for Sage:
http://hg.sagemath.org/sage-main/file/33242a07d2ab/sage/interfaces/sage0.py

There's another expect interface used in the notebook:
https://github.com/sagemath/sagenb/blob/master/sagenb/interfaces/expect.py#L204

I'm not sure the exact answer to your original question about disabling
readline, but I hope the above helps.

Thanks,

Jason


Jim Hefferon

unread,
Dec 11, 2012, 9:38:56 AM12/11/12
to sage-s...@googlegroups.com


On Tuesday, December 11, 2012 9:15:20 AM UTC-5, Jason Grout wrote:

Sage has an expect interface for Sage:
http://hg.sagemath.org/sage-main/file/33242a07d2ab/sage/interfaces/sage0.py


Thanks, Jason.  I did not know that.  I'll have a look.  (As you know, I'm trying to pick up the sage: prompt, the ... sub prompts, etc., that a student would see if they typed it in letter for letter.)

Regards,
Jim

Dima Pasechnik

unread,
Dec 11, 2012, 10:09:39 AM12/11/12
to sage-s...@googlegroups.com
On 2012-12-11, Jim Hefferon <jim.he...@gmail.com> wrote:
> ------=_Part_251_9537975.1355234826734
> Content-Type: text/plain; charset=ISO-8859-1
>
>
>
> On Tuesday, December 11, 2012 7:45:10 AM UTC-5, Dima Pasechnik wrote:
>
>> is pyreadline really used by Sage?
>> It seems to be only needed on Windows, where Sage does not run.
>>
>> Thanks for your comment. Probably I have it wrong. I based my opinion on
> this from the Sage FAQ:
>
> http://wiki.sagemath.org/faq#Why_is_Sage.27s_command_history_different_than_Magma.27s
> buttressed by the fact that if you type garbage into the repl then Sage
> gives an error message that refers to the "ipython console". But evidence
> that I am wrong is that I also see readline-6.2.p3.spkg in my
> /usr/local/sage/spkg/standard directory, so I could be convinced either
> way.

if you look at sage/misc/readline_extra_commands.pyx

you'll see that it is basically an interface to GNU readline.
Looking into it, one gathers that changing the line

readline 1

to

readline 0

in the file $HOME/.sage/ipython/ipythonrc
(a.k.a. $DOTSAGE/ipython/ipythonrc)
disables readline.
I tried this for me, it worked. YMMV.

HTH,
Dmitrii

Jim Hefferon

unread,
Dec 11, 2012, 3:54:51 PM12/11/12
to sage-s...@googlegroups.com
On Tuesday, December 11, 2012 10:09:39 AM UTC-5, Dima Pasechnik wrote:
if you look at sage/misc/readline_extra_commands.pyx

you'll see that it is basically an interface to GNU readline.
Looking into it, one gathers that changing the line

readline 1

to

readline 0
 
in the file $HOME/.sage/ipython/ipythonrc
(a.k.a. $DOTSAGE/ipython/ipythonrc)
disables readline.

Very helpful; I owe you one.
 
YMMV.

Indeed, it often does.  :-)

Thank you, Jim
 
Reply all
Reply to author
Forward
0 new messages