Show More
@@ -54,7 +54,7 b" def magic_history(self, parameter_s = ''):" | |||||
54 | confirmation first if it already exists. |
|
54 | confirmation first if it already exists. | |
55 | """ |
|
55 | """ | |
56 |
|
56 | |||
57 | if not self.displayhook.do_full_cache: |
|
57 | if not self.shell.displayhook.do_full_cache: | |
58 | print 'This feature is only available if numbered prompts are in use.' |
|
58 | print 'This feature is only available if numbered prompts are in use.' | |
59 | return |
|
59 | return | |
60 | opts,args = self.parse_options(parameter_s,'gnoptsrf:',mode='list') |
|
60 | opts,args = self.parse_options(parameter_s,'gnoptsrf:',mode='list') | |
@@ -76,12 +76,12 b" def magic_history(self, parameter_s = ''):" | |||||
76 | close_at_end = True |
|
76 | close_at_end = True | |
77 |
|
77 | |||
78 | if 't' in opts: |
|
78 | if 't' in opts: | |
79 | input_hist = self.input_hist |
|
79 | input_hist = self.shell.input_hist | |
80 | elif 'r' in opts: |
|
80 | elif 'r' in opts: | |
81 | input_hist = self.input_hist_raw |
|
81 | input_hist = self.shell.input_hist_raw | |
82 | else: |
|
82 | else: | |
83 | # Raw history is the default |
|
83 | # Raw history is the default | |
84 | input_hist = self.input_hist_raw |
|
84 | input_hist = self.shell.input_hist_raw | |
85 |
|
85 | |||
86 | default_length = 40 |
|
86 | default_length = 40 | |
87 | pattern = None |
|
87 | pattern = None | |
@@ -114,7 +114,7 b" def magic_history(self, parameter_s = ''):" | |||||
114 |
|
114 | |||
115 | found = False |
|
115 | found = False | |
116 | if pattern is not None: |
|
116 | if pattern is not None: | |
117 | sh = self.shadowhist.all() |
|
117 | sh = self.shell.shadowhist.all() | |
118 | for idx, s in sh: |
|
118 | for idx, s in sh: | |
119 | if fnmatch.fnmatch(s, pattern): |
|
119 | if fnmatch.fnmatch(s, pattern): | |
120 | print >> outfile, "0%d: %s" %(idx, s.expandtabs(4)) |
|
120 | print >> outfile, "0%d: %s" %(idx, s.expandtabs(4)) | |
@@ -126,11 +126,12 b" def magic_history(self, parameter_s = ''):" | |||||
126 | "shadow history ends, fetch by %rep <number> (must start with 0)" |
|
126 | "shadow history ends, fetch by %rep <number> (must start with 0)" | |
127 | print >> outfile, "=== start of normal history ===" |
|
127 | print >> outfile, "=== start of normal history ===" | |
128 |
|
128 | |||
129 | for in_num in range(init,final): |
|
129 | for in_num in range(init, final): | |
130 | # Print user history with tabs expanded to 4 spaces. The GUI clients |
|
130 | # Print user history with tabs expanded to 4 spaces. The GUI clients | |
131 | # use hard tabs for easier usability in auto-indented code, but we want |
|
131 | # use hard tabs for easier usability in auto-indented code, but we want | |
132 | # to produce PEP-8 compliant history for safe pasting into an editor. |
|
132 | # to produce PEP-8 compliant history for safe pasting into an editor. | |
133 | inline = input_hist[in_num].expandtabs(4) |
|
133 | inline = input_hist[in_num].expandtabs(4) | |
|
134 | ||||
134 | if pattern is not None and not fnmatch.fnmatch(inline, pattern): |
|
135 | if pattern is not None and not fnmatch.fnmatch(inline, pattern): | |
135 | continue |
|
136 | continue | |
136 |
|
137 | |||
@@ -149,7 +150,7 b" def magic_history(self, parameter_s = ''):" | |||||
149 | else: |
|
150 | else: | |
150 | print >> outfile, inline, |
|
151 | print >> outfile, inline, | |
151 | if print_outputs: |
|
152 | if print_outputs: | |
152 |
output = self.shell. |
|
153 | output = self.shell.output_hist.get(in_num) | |
153 | if output is not None: |
|
154 | if output is not None: | |
154 | print >> outfile, repr(output) |
|
155 | print >> outfile, repr(output) | |
155 |
|
156 | |||
@@ -195,7 +196,7 b' def rep_f(self, arg):' | |||||
195 |
|
196 | |||
196 | opts,args = self.parse_options(arg,'',mode='list') |
|
197 | opts,args = self.parse_options(arg,'',mode='list') | |
197 | if not args: |
|
198 | if not args: | |
198 | self.set_next_input(str(self.user_ns["_"])) |
|
199 | self.set_next_input(str(self.shell.user_ns["_"])) | |
199 | return |
|
200 | return | |
200 |
|
201 | |||
201 | if len(args) == 1 and not '-' in args[0]: |
|
202 | if len(args) == 1 and not '-' in args[0]: | |
@@ -203,17 +204,17 b' def rep_f(self, arg):' | |||||
203 | if len(arg) > 1 and arg.startswith('0'): |
|
204 | if len(arg) > 1 and arg.startswith('0'): | |
204 | # get from shadow hist |
|
205 | # get from shadow hist | |
205 | num = int(arg[1:]) |
|
206 | num = int(arg[1:]) | |
206 | line = self.shadowhist.get(num) |
|
207 | line = self.shell.shadowhist.get(num) | |
207 | self.set_next_input(str(line)) |
|
208 | self.set_next_input(str(line)) | |
208 | return |
|
209 | return | |
209 | try: |
|
210 | try: | |
210 | num = int(args[0]) |
|
211 | num = int(args[0]) | |
211 | self.set_next_input(str(self.input_hist_raw[num]).rstrip()) |
|
212 | self.set_next_input(str(self.shell.input_hist_raw[num]).rstrip()) | |
212 | return |
|
213 | return | |
213 | except ValueError: |
|
214 | except ValueError: | |
214 | pass |
|
215 | pass | |
215 |
|
216 | |||
216 | for h in reversed(self.input_hist_raw): |
|
217 | for h in reversed(self.shell.input_hist_raw): | |
217 | if 'rep' in h: |
|
218 | if 'rep' in h: | |
218 | continue |
|
219 | continue | |
219 | if fnmatch.fnmatch(h,'*' + arg + '*'): |
|
220 | if fnmatch.fnmatch(h,'*' + arg + '*'): | |
@@ -231,7 +232,7 b' def rep_f(self, arg):' | |||||
231 | _sentinel = object() |
|
232 | _sentinel = object() | |
232 |
|
233 | |||
233 | class ShadowHist(object): |
|
234 | class ShadowHist(object): | |
234 | def __init__(self,db): |
|
235 | def __init__(self, db): | |
235 | # cmd => idx mapping |
|
236 | # cmd => idx mapping | |
236 | self.curidx = 0 |
|
237 | self.curidx = 0 | |
237 | self.db = db |
|
238 | self.db = db |
@@ -2121,10 +2121,21 b' class InteractiveShell(Configurable, Magic):' | |||||
2121 | # just feed the whole thing to runcode. |
|
2121 | # just feed the whole thing to runcode. | |
2122 | # This seems like a reasonable usability design. |
|
2122 | # This seems like a reasonable usability design. | |
2123 | last = blocks[-1] |
|
2123 | last = blocks[-1] | |
|
2124 | ||||
|
2125 | # Note: below, whenever we call runcode, we must sync history | |||
|
2126 | # ourselves, because runcode is NOT meant to manage history at all. | |||
2124 | if len(last.splitlines()) < 2: |
|
2127 | if len(last.splitlines()) < 2: | |
2125 | self.runcode(''.join(blocks[:-1]), post_execute=False) |
|
2128 | # Get the main body to run as a cell | |
|
2129 | body = ''.join(blocks[:-1]) | |||
|
2130 | self.input_hist.append(body) | |||
|
2131 | self.input_hist_raw.append(body) | |||
|
2132 | self.runcode(body, post_execute=False) | |||
|
2133 | # And the last expression via runlines so it produces output | |||
2126 | self.runlines(last) |
|
2134 | self.runlines(last) | |
2127 | else: |
|
2135 | else: | |
|
2136 | # Run the whole cell as one entity | |||
|
2137 | self.input_hist.append(cell) | |||
|
2138 | self.input_hist_raw.append(cell) | |||
2128 | self.runcode(cell) |
|
2139 | self.runcode(cell) | |
2129 |
|
2140 | |||
2130 | def runlines(self, lines, clean=False): |
|
2141 | def runlines(self, lines, clean=False): | |
@@ -2245,11 +2256,6 b' class InteractiveShell(Configurable, Magic):' | |||||
2245 | - 1: an error occurred. |
|
2256 | - 1: an error occurred. | |
2246 | """ |
|
2257 | """ | |
2247 |
|
2258 | |||
2248 | # It's also possible that we've been fed a plain string. In that case, |
|
|||
2249 | # we must store it in the input history. |
|
|||
2250 | if isinstance(code_obj, basestring): |
|
|||
2251 | self.input_hist_raw.append(code_obj) |
|
|||
2252 |
|
||||
2253 | # Set our own excepthook in case the user code tries to call it |
|
2259 | # Set our own excepthook in case the user code tries to call it | |
2254 | # directly, so that the IPython crash handler doesn't get triggered |
|
2260 | # directly, so that the IPython crash handler doesn't get triggered | |
2255 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
|
2261 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
General Comments 0
You need to be logged in to leave comments.
Login now