Show More
@@ -2045,6 +2045,12 b' class InteractiveShell(SingletonConfigurable):' | |||||
2045 | m.NamespaceMagics, m.OSMagics, m.PylabMagics, m.ScriptMagics, |
|
2045 | m.NamespaceMagics, m.OSMagics, m.PylabMagics, m.ScriptMagics, | |
2046 | ) |
|
2046 | ) | |
2047 |
|
2047 | |||
|
2048 | # Register Magic Aliases | |||
|
2049 | mman = self.magics_manager | |||
|
2050 | mman.register_alias('ed', 'edit') | |||
|
2051 | mman.register_alias('hist', 'history') | |||
|
2052 | mman.register_alias('rep', 'recall') | |||
|
2053 | ||||
2048 | # FIXME: Move the color initialization to the DisplayHook, which |
|
2054 | # FIXME: Move the color initialization to the DisplayHook, which | |
2049 | # should be split into a prompt manager and displayhook. We probably |
|
2055 | # should be split into a prompt manager and displayhook. We probably | |
2050 | # even need a centralize colors management object. |
|
2056 | # even need a centralize colors management object. |
@@ -333,11 +333,6 b' class CodeMagics(Magics):' | |||||
333 | mfile.close() |
|
333 | mfile.close() | |
334 | self.shell.user_ns[mname] = Macro(mvalue) |
|
334 | self.shell.user_ns[mname] = Macro(mvalue) | |
335 |
|
335 | |||
336 | @line_magic |
|
|||
337 | def ed(self, parameter_s=''): |
|
|||
338 | """Alias to %edit.""" |
|
|||
339 | return self.edit(parameter_s) |
|
|||
340 |
|
||||
341 | @skip_doctest |
|
336 | @skip_doctest | |
342 | @line_magic |
|
337 | @line_magic | |
343 | def edit(self, parameter_s='',last_call=['','']): |
|
338 | def edit(self, parameter_s='',last_call=['','']): | |
@@ -431,7 +426,7 b' class CodeMagics(Magics):' | |||||
431 | This is an example of creating a simple function inside the editor and |
|
426 | This is an example of creating a simple function inside the editor and | |
432 | then modifying it. First, start up the editor:: |
|
427 | then modifying it. First, start up the editor:: | |
433 |
|
428 | |||
434 | In [1]: ed |
|
429 | In [1]: edit | |
435 | Editing... done. Executing edited code... |
|
430 | Editing... done. Executing edited code... | |
436 | Out[1]: 'def foo():\\n print "foo() was defined in an editing |
|
431 | Out[1]: 'def foo():\\n print "foo() was defined in an editing | |
437 | session"\\n' |
|
432 | session"\\n' | |
@@ -444,7 +439,7 b' class CodeMagics(Magics):' | |||||
444 | Now we edit foo. IPython automatically loads the editor with the |
|
439 | Now we edit foo. IPython automatically loads the editor with the | |
445 | (temporary) file where foo() was previously defined:: |
|
440 | (temporary) file where foo() was previously defined:: | |
446 |
|
441 | |||
447 | In [3]: ed foo |
|
442 | In [3]: edit foo | |
448 | Editing... done. Executing edited code... |
|
443 | Editing... done. Executing edited code... | |
449 |
|
444 | |||
450 | And if we call foo() again we get the modified version:: |
|
445 | And if we call foo() again we get the modified version:: | |
@@ -455,21 +450,21 b' class CodeMagics(Magics):' | |||||
455 | Here is an example of how to edit a code snippet successive |
|
450 | Here is an example of how to edit a code snippet successive | |
456 | times. First we call the editor:: |
|
451 | times. First we call the editor:: | |
457 |
|
452 | |||
458 | In [5]: ed |
|
453 | In [5]: edit | |
459 | Editing... done. Executing edited code... |
|
454 | Editing... done. Executing edited code... | |
460 | hello |
|
455 | hello | |
461 | Out[5]: "print 'hello'\\n" |
|
456 | Out[5]: "print 'hello'\\n" | |
462 |
|
457 | |||
463 | Now we call it again with the previous output (stored in _):: |
|
458 | Now we call it again with the previous output (stored in _):: | |
464 |
|
459 | |||
465 | In [6]: ed _ |
|
460 | In [6]: edit _ | |
466 | Editing... done. Executing edited code... |
|
461 | Editing... done. Executing edited code... | |
467 | hello world |
|
462 | hello world | |
468 | Out[6]: "print 'hello world'\\n" |
|
463 | Out[6]: "print 'hello world'\\n" | |
469 |
|
464 | |||
470 | Now we call it with the output #8 (stored in _8, also as Out[8]):: |
|
465 | Now we call it with the output #8 (stored in _8, also as Out[8]):: | |
471 |
|
466 | |||
472 | In [7]: ed _8 |
|
467 | In [7]: edit _8 | |
473 | Editing... done. Executing edited code... |
|
468 | Editing... done. Executing edited code... | |
474 | hello again |
|
469 | hello again | |
475 | Out[7]: "print 'hello again'\\n" |
|
470 | Out[7]: "print 'hello again'\\n" |
@@ -91,10 +91,10 b' class HistoryMagics(Magics):' | |||||
91 | -------- |
|
91 | -------- | |
92 | :: |
|
92 | :: | |
93 |
|
93 | |||
94 | In [6]: %hist -n 4-6 |
|
94 | In [6]: %history -n 4-6 | |
95 | 4:a = 12 |
|
95 | 4:a = 12 | |
96 | 5:print a**2 |
|
96 | 5:print a**2 | |
97 | 6:%hist -n 4-6 |
|
97 | 6:%history -n 4-6 | |
98 |
|
98 | |||
99 | """ |
|
99 | """ | |
100 |
|
100 | |||
@@ -187,15 +187,8 b' class HistoryMagics(Magics):' | |||||
187 | if close_at_end: |
|
187 | if close_at_end: | |
188 | outfile.close() |
|
188 | outfile.close() | |
189 |
|
189 | |||
190 | # For a long time we've had %hist as well as %history |
|
|||
191 | @line_magic |
|
190 | @line_magic | |
192 |
def |
|
191 | def recall(self, arg): | |
193 | return self.history(arg) |
|
|||
194 |
|
||||
195 | hist.__doc__ = history.__doc__ |
|
|||
196 |
|
||||
197 | @line_magic |
|
|||
198 | def rep(self, arg): |
|
|||
199 | r"""Repeat a command, or get command to input line for editing. |
|
192 | r"""Repeat a command, or get command to input line for editing. | |
200 |
|
193 | |||
201 | %recall and %rep are equivalent. |
|
194 | %recall and %rep are equivalent. | |
@@ -209,7 +202,7 b' class HistoryMagics(Magics):' | |||||
209 | In[1]: l = ["hei", "vaan"] |
|
202 | In[1]: l = ["hei", "vaan"] | |
210 | In[2]: "".join(l) |
|
203 | In[2]: "".join(l) | |
211 | Out[2]: heivaan |
|
204 | Out[2]: heivaan | |
212 |
In[3]: %re |
|
205 | In[3]: %recall | |
213 | In[4]: heivaan_ <== cursor blinking |
|
206 | In[4]: heivaan_ <== cursor blinking | |
214 |
|
207 | |||
215 | %recall 45 |
|
208 | %recall 45 | |
@@ -244,7 +237,7 b' class HistoryMagics(Magics):' | |||||
244 | except Exception: # Search for term in history |
|
237 | except Exception: # Search for term in history | |
245 | histlines = self.shell.history_manager.search("*"+arg+"*") |
|
238 | histlines = self.shell.history_manager.search("*"+arg+"*") | |
246 | for h in reversed([x[2] for x in histlines]): |
|
239 | for h in reversed([x[2] for x in histlines]): | |
247 | if 'rep' in h: |
|
240 | if 'recall' in h or 'rep' in h: | |
248 | continue |
|
241 | continue | |
249 | self.shell.set_next_input(h.rstrip()) |
|
242 | self.shell.set_next_input(h.rstrip()) | |
250 | return |
|
243 | return | |
@@ -292,10 +285,3 b' class HistoryMagics(Magics):' | |||||
292 | print(histlines) |
|
285 | print(histlines) | |
293 | print("=== Output: ===") |
|
286 | print("=== Output: ===") | |
294 | self.shell.run_cell("\n".join(hist), store_history=False) |
|
287 | self.shell.run_cell("\n".join(hist), store_history=False) | |
295 |
|
||||
296 | @line_magic |
|
|||
297 | def recall(self,arg): |
|
|||
298 | self.rep(arg) |
|
|||
299 |
|
||||
300 | recall.__doc__ = rep.__doc__ |
|
|||
301 |
|
@@ -575,7 +575,7 b' class ZMQInteractiveShell(InteractiveShell):' | |||||
575 | def init_magics(self): |
|
575 | def init_magics(self): | |
576 | super(ZMQInteractiveShell, self).init_magics() |
|
576 | super(ZMQInteractiveShell, self).init_magics() | |
577 | self.register_magics(KernelMagics) |
|
577 | self.register_magics(KernelMagics) | |
578 |
self. |
|
578 | self.magics_manager.register_alias('ed', 'edit') | |
579 |
|
579 | |||
580 |
|
580 | |||
581 |
|
581 |
General Comments 0
You need to be logged in to leave comments.
Login now