##// END OF EJS Templates
Allow new style aliases to be stored
Thomas Kluyver -
Show More
@@ -210,6 +210,14 b' class AliasManager(Configurable):'
210 210 raise InvalidAliasError("An alias command must be a string, "
211 211 "got: %r" % cmd)
212 212 return True
213
214 def retrieve_alias(self, name):
215 """Retrieve the command to which an alias expands."""
216 caller = self.shell.magics_manager.magics['line'].get(name, None)
217 if isinstance(caller, AliasCaller):
218 return caller.cmd
219 else:
220 raise ValueError('%s is not an alias' % name)
213 221
214 222 def call_alias(self, alias, rest=''):
215 223 """Call an alias given its name and the rest of the line."""
@@ -211,16 +211,17 b' class StoreMagics(Magics, Configurable):'
211 211 except KeyError:
212 212 # it might be an alias
213 213 # This needs to be refactored to use the new AliasManager stuff.
214 if args[0] in ip.alias_manager:
215 name = args[0]
216 nargs, cmd = ip.alias_manager.alias_table[ name ]
217 staliases = db.get('stored_aliases',{})
218 staliases[ name ] = cmd
219 db['stored_aliases'] = staliases
220 print "Alias stored: %s (%s)" % (name, cmd)
221 return
222 else:
223 raise UsageError("Unknown variable '%s'" % args[0])
214 name = args[0]
215 try:
216 cmd = ip.alias_manager.retrieve_alias(name)
217 except ValueError:
218 raise UsageError("Unknown variable '%s'" % name)
219
220 staliases = db.get('stored_aliases',{})
221 staliases[name] = cmd
222 db['stored_aliases'] = staliases
223 print "Alias stored: %s (%s)" % (name, cmd)
224 return
224 225
225 226 else:
226 227 modname = getattr(inspect.getmodule(obj), '__name__', '')
General Comments 0
You need to be logged in to leave comments. Login now