Ask Your Question
1

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

asked 2010-08-27 22:03:51 +0100

ccanonc gravatar image

updated 2011-04-28 17:05:23 +0100

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

Comments

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 16:13:45 +0100 )edit

Do you like Mike's solution?

ccanonc gravatar imageccanonc ( 2010-08-28 22:43:21 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2010-08-28 16:51:47 +0100

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
IPython.OInspect.page = specialize(screen_lines=0.5r)(IPython.OInspect.page)

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

Stats

Asked: 2010-08-27 22:03:51 +0100

Seen: 744 times

Last updated: Aug 28 '10