Ask Your Question

Can I configure Sage's Terminal Mode to always call the pager for docstring queries?

asked 2010-08-27 15:03:51 -0500

ccanonc gravatar image

updated 2011-04-28 10:05:23 -0500

Kelvin Li gravatar image

I just noticed when inspecting some common global variables, that the pager ("/usr/bin/less" usually) is only called for docstrings longer than a page. Sensible, but sometimes I don't want that.

sage: filter(lambda a:len(a)==2, dir())

['AA', 'CC', 'Ei', 'GF', 'GL', 'GO', 'GU', 'Gp', 'In', 'J0', 'J1', 'JH', 'Li', 'NN', 'QQ', 'Qp', 'Qq', 'RR', 'SL', 'SO', 'SR', 'SU', 'Sp', 'Sq', 'UP', 'ZZ', 'Zp', 'Zq', '_2', '_3', '_4', '_5', '_6', '_7', '_8', '_9', '__', '_i', 'db', 'gp', 'ln', 'mq', 'oo', 'os', 'pg', 'pi', 'sh']

sage: GU? (starts pager)

sage: GO? (just prints the docstring...same as "sage: print GO.__doc__")

Long docstrings really clutter the terminal. :~(

edit retag flag offensive close merge delete


Fernando Perez (author of Ipython) would know - ypu should email him and post the result here. Or tell him about this site.

William Stein gravatar imageWilliam Stein ( 2010-08-28 09:13:45 -0500 )edit

Do you like Mike's solution?

ccanonc gravatar imageccanonc ( 2010-08-28 15:43:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2010-08-28 09:51:47 -0500

Mike Hansen gravatar image

IPython (at least the version we use) isn't really designed for this sort of customization, but there is a hack to make it behave this way. If you run the following commands (or put them in your ~/.sage/init.sage file), it should behave exactly how you want.

import IPython.OInspect = specialize(screen_lines=0.5r)(

specialize is a decorator which causes a default value of screen_lines=0.5 to be passed on to the real page function. Basically what this does is tell IPython that the number of lines in your screen is greater than 0 (so it doesn't try to autodetect it, the default case) and less than any number of lines that would be displayed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2010-08-27 15:03:51 -0500

Seen: 393 times

Last updated: Aug 28 '10