# 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 |
1415 | 1415 | */ |
1416 | 1416 | with(theform) { |
1417 | 1417 | 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.")) { |
1419 | 1420 | system_select(system); |
1420 | 1421 | } else { |
1421 | 1422 | options[original_system].selected = 1; |
1422 | 1423 | } |
| 1424 | */ |
1423 | 1425 | } |
1424 | 1426 | } |
1425 | 1427 | |
diff -r d70d9c5e2db1 -r efd67c0fc8f8 sage/server/notebook/notebook.py
a
|
b
|
import user # users |
34 | 34 | |
35 | 35 | |
36 | 36 | SYSTEMS = ['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. |
| 40 | SYSTEM_NAMES = [v.split()[0] for v in SYSTEMS] |
37 | 41 | |
38 | 42 | JSMATH = True |
39 | 43 | |
… |
… |
function save_worksheet_and_close() { |
2038 | 2042 | def html_system_select_form_element(self, ws): |
2039 | 2043 | system = ws.system() |
2040 | 2044 | 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: |
2044 | 2048 | selected = "selected" |
2045 | 2049 | else: |
2046 | 2050 | selected = '' |
2047 | | T = S.split()[0] |
| 2051 | T = SYSTEM_NAMES[j] |
2048 | 2052 | options += '<option title="Evaluate all input cells using %s" %s value="%s">%s</option>\n'%(T, selected, T,S) |
2049 | 2053 | s = """<select onchange="go_system_select(this, %s);" class="worksheet"> |
2050 | 2054 | %s |
diff -r d70d9c5e2db1 -r efd67c0fc8f8 sage/server/notebook/worksheet.py
a
|
b
|
class Worksheet: |
1855 | 1855 | i += 1 |
1856 | 1856 | if before_prompt.endswith('??'): |
1857 | 1857 | 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()) |
1859 | 1859 | elif before_prompt.endswith('?'): |
1860 | 1860 | 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()) |
1862 | 1862 | else: |
1863 | 1863 | input = self._get_last_identifier(before_prompt) |
1864 | 1864 | 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()) |
1866 | 1866 | return input |
1867 | 1867 | |
1868 | 1868 | def preparse_nonswitched_input(self, input): |
… |
… |
class Worksheet: |
1954 | 1954 | return out |
1955 | 1955 | |
1956 | 1956 | 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) |
1965 | 1958 | |
1966 | 1959 | def preparse(self, s): |
1967 | 1960 | if sage.misc.interpreter.do_preparse: |
diff -r d70d9c5e2db1 -r efd67c0fc8f8 sage/server/support.py
a
|
b
|
def completions(s, globs, format=False, |
76 | 76 | """ |
77 | 77 | Return a list of completions in the context of globs. |
78 | 78 | """ |
| 79 | if system not in ['sage', 'python']: |
| 80 | prepend = system + '.' |
| 81 | s = prepend + s |
| 82 | else: |
| 83 | prepend = '' |
79 | 84 | n = len(s) |
80 | 85 | if n == 0: |
81 | 86 | return '(empty string)' |
… |
… |
def completions(s, globs, format=False, |
109 | 114 | v.sort() |
110 | 115 | except Exception, msg: |
111 | 116 | v = [] |
| 117 | |
| 118 | if prepend: |
| 119 | i = len(prepend) |
| 120 | v = [x[i:] for x in v] |
| 121 | |
112 | 122 | if format: |
113 | 123 | if len(v) == 0: |
114 | 124 | return "No completions of '%s' currently defined"%s |
… |
… |
def completions(s, globs, format=False, |
116 | 126 | return tabulate(v, width) |
117 | 127 | return v |
118 | 128 | |
119 | | def docstring(obj_name, globs): |
| 129 | def docstring(obj_name, globs, system='sage'): |
120 | 130 | r""" |
121 | 131 | Format \var{obj_name}'s docstring for printing in \sage notebook. |
122 | 132 | |
… |
… |
def docstring(obj_name, globs): |
124 | 134 | -- William Stein (but partly taken from IPython for use in \sage). |
125 | 135 | -- Extensions by Nick Alexander |
126 | 136 | """ |
| 137 | if system not in ['sage', 'python']: |
| 138 | obj_name = system + '.' + obj_name |
127 | 139 | try: |
128 | 140 | obj = eval(obj_name, globs) |
129 | 141 | except (AttributeError, NameError, SyntaxError): |
… |
… |
def docstring(obj_name, globs): |
144 | 156 | s += 'Docstring: \n%s\n'%sageinspect.sage_getdoc(obj, obj_name) |
145 | 157 | return s.rstrip() |
146 | 158 | |
147 | | def source_code(s, globs): |
| 159 | def source_code(s, globs, system='sage'): |
148 | 160 | r""" |
149 | 161 | Format obj's source code for printing in \sage notebook. |
150 | 162 | |
… |
… |
def source_code(s, globs): |
152 | 164 | -- William Stein (but partly taken from IPython for use in \sage). |
153 | 165 | -- Extensions by Nick Alexander |
154 | 166 | """ |
| 167 | if system not in ['sage', 'python']: |
| 168 | s = system + '.' + s |
| 169 | |
155 | 170 | try: |
156 | 171 | obj = eval(s, globs) |
157 | 172 | except NameError: |