##// END OF EJS Templates
Use magic alias api to register magic aliases.
Bradley M. Froehle -
Show More
@@ -2045,6 +2045,12 b' class InteractiveShell(SingletonConfigurable):'
2045 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 2054 # FIXME: Move the color initialization to the DisplayHook, which
2049 2055 # should be split into a prompt manager and displayhook. We probably
2050 2056 # even need a centralize colors management object.
@@ -333,11 +333,6 b' class CodeMagics(Magics):'
333 333 mfile.close()
334 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 336 @skip_doctest
342 337 @line_magic
343 338 def edit(self, parameter_s='',last_call=['','']):
@@ -431,7 +426,7 b' class CodeMagics(Magics):'
431 426 This is an example of creating a simple function inside the editor and
432 427 then modifying it. First, start up the editor::
433 428
434 In [1]: ed
429 In [1]: edit
435 430 Editing... done. Executing edited code...
436 431 Out[1]: 'def foo():\\n print "foo() was defined in an editing
437 432 session"\\n'
@@ -444,7 +439,7 b' class CodeMagics(Magics):'
444 439 Now we edit foo. IPython automatically loads the editor with the
445 440 (temporary) file where foo() was previously defined::
446 441
447 In [3]: ed foo
442 In [3]: edit foo
448 443 Editing... done. Executing edited code...
449 444
450 445 And if we call foo() again we get the modified version::
@@ -455,21 +450,21 b' class CodeMagics(Magics):'
455 450 Here is an example of how to edit a code snippet successive
456 451 times. First we call the editor::
457 452
458 In [5]: ed
453 In [5]: edit
459 454 Editing... done. Executing edited code...
460 455 hello
461 456 Out[5]: "print 'hello'\\n"
462 457
463 458 Now we call it again with the previous output (stored in _)::
464 459
465 In [6]: ed _
460 In [6]: edit _
466 461 Editing... done. Executing edited code...
467 462 hello world
468 463 Out[6]: "print 'hello world'\\n"
469 464
470 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 468 Editing... done. Executing edited code...
474 469 hello again
475 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 95 4:a = 12
96 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 187 if close_at_end:
188 188 outfile.close()
189 189
190 # For a long time we've had %hist as well as %history
191 190 @line_magic
192 def hist(self, arg):
193 return self.history(arg)
194
195 hist.__doc__ = history.__doc__
196
197 @line_magic
198 def rep(self, arg):
191 def recall(self, arg):
199 192 r"""Repeat a command, or get command to input line for editing.
200 193
201 194 %recall and %rep are equivalent.
@@ -209,7 +202,7 b' class HistoryMagics(Magics):'
209 202 In[1]: l = ["hei", "vaan"]
210 203 In[2]: "".join(l)
211 204 Out[2]: heivaan
212 In[3]: %rep
205 In[3]: %recall
213 206 In[4]: heivaan_ <== cursor blinking
214 207
215 208 %recall 45
@@ -244,7 +237,7 b' class HistoryMagics(Magics):'
244 237 except Exception: # Search for term in history
245 238 histlines = self.shell.history_manager.search("*"+arg+"*")
246 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 241 continue
249 242 self.shell.set_next_input(h.rstrip())
250 243 return
@@ -292,10 +285,3 b' class HistoryMagics(Magics):'
292 285 print(histlines)
293 286 print("=== Output: ===")
294 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 575 def init_magics(self):
576 576 super(ZMQInteractiveShell, self).init_magics()
577 577 self.register_magics(KernelMagics)
578 self.run_line_magic('alias_magic', 'ed edit')
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