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