diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 4770c95..9a176c3 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2045,6 +2045,12 @@ class InteractiveShell(SingletonConfigurable): m.NamespaceMagics, m.OSMagics, m.PylabMagics, m.ScriptMagics, ) + # Register Magic Aliases + mman = self.magics_manager + mman.register_alias('ed', 'edit') + mman.register_alias('hist', 'history') + mman.register_alias('rep', 'recall') + # FIXME: Move the color initialization to the DisplayHook, which # should be split into a prompt manager and displayhook. We probably # even need a centralize colors management object. diff --git a/IPython/core/magics/code.py b/IPython/core/magics/code.py index 5414f4f..47df10f 100644 --- a/IPython/core/magics/code.py +++ b/IPython/core/magics/code.py @@ -333,11 +333,6 @@ class CodeMagics(Magics): mfile.close() self.shell.user_ns[mname] = Macro(mvalue) - @line_magic - def ed(self, parameter_s=''): - """Alias to %edit.""" - return self.edit(parameter_s) - @skip_doctest @line_magic def edit(self, parameter_s='',last_call=['','']): @@ -431,7 +426,7 @@ class CodeMagics(Magics): This is an example of creating a simple function inside the editor and then modifying it. First, start up the editor:: - In [1]: ed + In [1]: edit Editing... done. Executing edited code... Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n' @@ -444,7 +439,7 @@ class CodeMagics(Magics): Now we edit foo. IPython automatically loads the editor with the (temporary) file where foo() was previously defined:: - In [3]: ed foo + In [3]: edit foo Editing... done. Executing edited code... And if we call foo() again we get the modified version:: @@ -455,21 +450,21 @@ class CodeMagics(Magics): Here is an example of how to edit a code snippet successive times. First we call the editor:: - In [5]: ed + In [5]: edit Editing... done. Executing edited code... hello Out[5]: "print 'hello'\\n" Now we call it again with the previous output (stored in _):: - In [6]: ed _ + In [6]: edit _ Editing... done. Executing edited code... hello world Out[6]: "print 'hello world'\\n" Now we call it with the output #8 (stored in _8, also as Out[8]):: - In [7]: ed _8 + In [7]: edit _8 Editing... done. Executing edited code... hello again Out[7]: "print 'hello again'\\n" diff --git a/IPython/core/magics/history.py b/IPython/core/magics/history.py index f5076b6..501ba62 100644 --- a/IPython/core/magics/history.py +++ b/IPython/core/magics/history.py @@ -91,10 +91,10 @@ class HistoryMagics(Magics): -------- :: - In [6]: %hist -n 4-6 + In [6]: %history -n 4-6 4:a = 12 5:print a**2 - 6:%hist -n 4-6 + 6:%history -n 4-6 """ @@ -187,15 +187,8 @@ class HistoryMagics(Magics): if close_at_end: outfile.close() - # For a long time we've had %hist as well as %history @line_magic - def hist(self, arg): - return self.history(arg) - - hist.__doc__ = history.__doc__ - - @line_magic - def rep(self, arg): + def recall(self, arg): r"""Repeat a command, or get command to input line for editing. %recall and %rep are equivalent. @@ -209,7 +202,7 @@ class HistoryMagics(Magics): In[1]: l = ["hei", "vaan"] In[2]: "".join(l) Out[2]: heivaan - In[3]: %rep + In[3]: %recall In[4]: heivaan_ <== cursor blinking %recall 45 @@ -244,7 +237,7 @@ class HistoryMagics(Magics): except Exception: # Search for term in history histlines = self.shell.history_manager.search("*"+arg+"*") for h in reversed([x[2] for x in histlines]): - if 'rep' in h: + if 'recall' in h or 'rep' in h: continue self.shell.set_next_input(h.rstrip()) return @@ -292,10 +285,3 @@ class HistoryMagics(Magics): print(histlines) print("=== Output: ===") self.shell.run_cell("\n".join(hist), store_history=False) - - @line_magic - def recall(self,arg): - self.rep(arg) - - recall.__doc__ = rep.__doc__ - diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index 60fa06d..0691ef6 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -575,7 +575,7 @@ class ZMQInteractiveShell(InteractiveShell): def init_magics(self): super(ZMQInteractiveShell, self).init_magics() self.register_magics(KernelMagics) - self.run_line_magic('alias_magic', 'ed edit') + self.magics_manager.register_alias('ed', 'edit')