# HG changeset patch # User William Stein # Date 1210484656 25200 # Node ID bf1d49c9c7de5bcb0f4908dd626020b4869d5553 # Parent 491affdce3fafbad8129208b2a5665497aaca464 trac #2992 -- help(foo) in the notebook should not word wrap 1. Wrote new version of help command for the notebook. 2. Slightly modified how truncation is done to account for 1. While I was at it, I fixed another but where reloading a page would put multiple "output truncated" messages at the top of the page. diff -r 491affdce3fa -r bf1d49c9c7de sage/all_notebook.py --- a/sage/all_notebook.py Sat May 10 22:02:38 2008 -0700 +++ b/sage/all_notebook.py Sat May 10 22:44:16 2008 -0700 @@ -23,10 +23,10 @@ from sage.misc.python import python from sage.misc.html import html +from sage.server.support import help - diff -r 491affdce3fa -r bf1d49c9c7de sage/server/notebook/cell.py --- a/sage/server/notebook/cell.py Sat May 10 22:02:38 2008 -0700 +++ b/sage/server/notebook/cell.py Sat May 10 22:44:16 2008 -0700 @@ -496,7 +496,11 @@ class Cell(Cell_generic): del self._html_cache output = output.replace('\r','') - if len(output) > MAX_OUTPUT or output.count('\n') > MAX_OUTPUT_LINES: + # We do not truncate if "notruncate" or "Output truncated!" already + # appears in the output. This notruncate tag is used right now + # in sage.server.support.help. + if 'notruncate' not in output and 'Output truncated!' not in output and \ + (len(output) > MAX_OUTPUT or output.count('\n') > MAX_OUTPUT_LINES): url = "" if not self.computing(): file = "%s/full_output.txt"%self.directory() diff -r 491affdce3fa -r bf1d49c9c7de sage/server/support.py --- a/sage/server/support.py Sat May 10 22:02:38 2008 -0700 +++ b/sage/server/support.py Sat May 10 22:44:16 2008 -0700 @@ -18,6 +18,8 @@ import sage.misc.sageinspect as sageinsp import sage.misc.sageinspect as sageinspect from sage.misc.preparser import preparse + +import pydoc ###################################################################### # Initialization @@ -64,7 +66,34 @@ def setup_systems(globs): ###################################################################### # Introspection ###################################################################### +def help(obj): + """ + Display help on s. + NOTE: This a wrapper around the builtin help. If formats the + output as HTML without word wrap, which looks better in the + notebook. + + INPUT: + s -- Python object, module, etc. + + OUTPUT: + prints out help about s; it's often more more extensive than foo? + + TESTS: + sage: import numpy.linalg + sage: sage.server.support.help(numpy.linalg.norm) +
+ Help on function norm in module numpy.linalg.linalg: + ... + For values ord < 0, the result is, strictly speaking, not a + mathematical 'norm', but it may still be useful for numerical purposes. +
+ """ + print '
' + pydoc.help(obj) + print '
' + def get_rightmost_identifier(s): X = string.ascii_letters + string.digits + '._' i = len(s)-1