From 86681682297e65c5640f8986ccb67d760640ab74 2013-09-19 17:56:11 From: Thomas Kluyver Date: 2013-09-19 17:56:11 Subject: [PATCH] Allow new style aliases to be stored --- diff --git a/IPython/core/alias.py b/IPython/core/alias.py index cceab0f..9b6dbae 100644 --- a/IPython/core/alias.py +++ b/IPython/core/alias.py @@ -210,6 +210,14 @@ class AliasManager(Configurable): raise InvalidAliasError("An alias command must be a string, " "got: %r" % cmd) return True + + def retrieve_alias(self, name): + """Retrieve the command to which an alias expands.""" + caller = self.shell.magics_manager.magics['line'].get(name, None) + if isinstance(caller, AliasCaller): + return caller.cmd + else: + raise ValueError('%s is not an alias' % name) def call_alias(self, alias, rest=''): """Call an alias given its name and the rest of the line.""" diff --git a/IPython/extensions/storemagic.py b/IPython/extensions/storemagic.py index b4c698f..a507226 100644 --- a/IPython/extensions/storemagic.py +++ b/IPython/extensions/storemagic.py @@ -211,16 +211,17 @@ class StoreMagics(Magics, Configurable): except KeyError: # it might be an alias # This needs to be refactored to use the new AliasManager stuff. - if args[0] in ip.alias_manager: - name = args[0] - nargs, cmd = ip.alias_manager.alias_table[ name ] - staliases = db.get('stored_aliases',{}) - staliases[ name ] = cmd - db['stored_aliases'] = staliases - print "Alias stored: %s (%s)" % (name, cmd) - return - else: - raise UsageError("Unknown variable '%s'" % args[0]) + name = args[0] + try: + cmd = ip.alias_manager.retrieve_alias(name) + except ValueError: + raise UsageError("Unknown variable '%s'" % name) + + staliases = db.get('stored_aliases',{}) + staliases[name] = cmd + db['stored_aliases'] = staliases + print "Alias stored: %s (%s)" % (name, cmd) + return else: modname = getattr(inspect.getmodule(obj), '__name__', '')