Ticket #406: sage-406.patch

File sage-406.patch, 7.0 KB (added by was, 15 years ago)
  • sage/server/notebook/js.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1210457586 25200
    # Node ID efd67c0fc8f8a907697eb7e4d9bc5015254970ee
    # Parent  d70d9c5e2db1cfd10f98bae8032555277efb6dbd
    Trac #406:
    
        1. Fix the problem where hitting tab when switched into another worksheet
           mode sticks system. at the front of each completion.  Similar fixes
           for help via foo([tab key}] and source code via foo??[tab].
    
        2. When switching systems, get rid of the very annoying
           confirmation dialog.   (Just commented it out for now.)
    
        3. Fix *very serious* bug that prevented loading a worksheet that was set
           to an optional mode.   In sage-3.0.1 loading a worksheet that is in
           an optional mode (e.g., mathematica or maple or Magma, say) was
           completely broken.  This patch fixes that problem.
    
    NOTE: This patch has no new tests illustrating that ift fixes
    anything, since we have no automated way of testing any of the
    above right now.
    
    diff -r d70d9c5e2db1 -r efd67c0fc8f8 sage/server/notebook/js.py
    a b function go_system_select(theform, origi 
    14151415    */
    14161416    with(theform) {
    14171417        var system = options[selectedIndex].value;
    1418         if (confirm("All cells will be evaluated using " + system + " until you change the system back.")) {
     1418        system_select(system);
     1419/*        if (confirm("All cells will be evaluated using " + system + " until you change the system back.")) {
    14191420            system_select(system);
    14201421        } else {
    14211422            options[original_system].selected = 1;
    14221423        }
     1424*/
    14231425    }
    14241426}
    14251427
  • sage/server/notebook/notebook.py

    diff -r d70d9c5e2db1 -r efd67c0fc8f8 sage/server/notebook/notebook.py
    a b import user # users 
    3434
    3535
    3636SYSTEMS = ['sage', 'gap', 'gp', 'jsmath', 'html', 'latex', 'maxima', 'python', 'r', 'sage', 'sh', 'singular', 'axiom (optional)', 'kash (optional)', 'macaulay2 (optional)', 'magma (optional)', 'maple (optional)', 'mathematica (optional)', 'matlab (optional)', 'mupad (optional)', 'octave (optional)']
     37
     38# We also record the system names without (optional) since they are
     39# used in some of the html menus, etc.
     40SYSTEM_NAMES = [v.split()[0] for v in SYSTEMS]
    3741
    3842JSMATH = True
    3943
    function save_worksheet_and_close() { 
    20382042    def html_system_select_form_element(self, ws):
    20392043        system = ws.system()
    20402044        options = ''
    2041         i = SYSTEMS.index(system)
    2042         for S in SYSTEMS:
    2043             if S == system:
     2045        i = SYSTEM_NAMES.index(system)
     2046        for j, S in enumerate(SYSTEMS):
     2047            if i == j:
    20442048                selected = "selected"
    20452049            else:
    20462050                selected = ''
    2047             T = S.split()[0]
     2051            T = SYSTEM_NAMES[j]
    20482052            options += '<option title="Evaluate all input cells using %s" %s value="%s">%s</option>\n'%(T, selected, T,S)
    20492053        s = """<select  onchange="go_system_select(this, %s);" class="worksheet">
    20502054            %s
  • sage/server/notebook/worksheet.py

    diff -r d70d9c5e2db1 -r efd67c0fc8f8 sage/server/notebook/worksheet.py
    a b class Worksheet: 
    18551855            i += 1
    18561856        if before_prompt.endswith('??'):
    18571857            input = self._get_last_identifier(before_prompt[:-2])
    1858             input = 'print _support_.source_code("%s", globals())'%input
     1858            input = 'print _support_.source_code("%s", globals(), system="%s")'%(input, self.system())
    18591859        elif before_prompt.endswith('?'):
    18601860            input = self._get_last_identifier(before_prompt[:-1])
    1861             input = 'print _support_.docstring("%s", globals())'%input
     1861            input = 'print _support_.docstring("%s", globals(), system="%s")'%(input, self.system())
    18621862        else:
    18631863            input = self._get_last_identifier(before_prompt)
    18641864            C._word_being_completed = input
    1865             input = 'print "\\n".join(_support_.completions("%s", globals()))'%(input)
     1865            input = 'print "\\n".join(_support_.completions("%s", globals(), system="%s"))'%(input, self.system())
    18661866        return input
    18671867       
    18681868    def preparse_nonswitched_input(self, input):
    class Worksheet: 
    19541954        return out
    19551955
    19561956    def _get_last_identifier(self, s):
    1957         t = support.get_rightmost_identifier(s)
    1958         S = self.system()
    1959         # If we are tab completing in a worksheet for another
    1960         # system, e.g., mathematica, this is like typing mathematica.[tab].
    1961         # However, for Sage and Python, we want regular tab completion.
    1962         if S and not (S in ['sage', 'python']):
    1963             t = S + '.' + t
    1964         return t
     1957        return support.get_rightmost_identifier(s)
    19651958
    19661959    def preparse(self, s):
    19671960        if sage.misc.interpreter.do_preparse:
  • sage/server/support.py

    diff -r d70d9c5e2db1 -r efd67c0fc8f8 sage/server/support.py
    a b def completions(s, globs, format=False,  
    7676    """
    7777    Return a list of completions in the context of globs.
    7878    """
     79    if system not in ['sage', 'python']:
     80        prepend = system + '.'
     81        s = prepend + s
     82    else:
     83        prepend = ''
    7984    n = len(s)
    8085    if n == 0:
    8186        return '(empty string)'
    def completions(s, globs, format=False,  
    109114        v.sort()
    110115    except Exception, msg:
    111116        v = []
     117
     118    if prepend:
     119        i = len(prepend)
     120        v = [x[i:] for x in v]
     121       
    112122    if format:
    113123        if len(v) == 0:
    114124            return "No completions of '%s' currently defined"%s
    def completions(s, globs, format=False,  
    116126            return tabulate(v, width)
    117127    return v   
    118128
    119 def docstring(obj_name, globs):
     129def docstring(obj_name, globs, system='sage'):
    120130    r"""
    121131    Format \var{obj_name}'s docstring for printing in \sage notebook.
    122132   
    def docstring(obj_name, globs): 
    124134        -- William Stein (but partly taken from IPython for use in \sage).
    125135        -- Extensions by Nick Alexander
    126136    """
     137    if system not in ['sage', 'python']:
     138        obj_name = system + '.' + obj_name
    127139    try:
    128140        obj = eval(obj_name, globs)
    129141    except (AttributeError, NameError, SyntaxError):
    def docstring(obj_name, globs): 
    144156    s += 'Docstring: \n%s\n'%sageinspect.sage_getdoc(obj, obj_name)
    145157    return s.rstrip()
    146158
    147 def source_code(s, globs):
     159def source_code(s, globs, system='sage'):
    148160    r"""
    149161    Format obj's source code for printing in \sage notebook.
    150162   
    def source_code(s, globs): 
    152164        -- William Stein (but partly taken from IPython for use in \sage).
    153165        -- Extensions by Nick Alexander
    154166    """
     167    if system not in ['sage', 'python']:
     168        s = system + '.' + s
     169
    155170    try:
    156171        obj = eval(s, globs)
    157172    except NameError: