Show More
@@ -300,6 +300,46 b' class IPApi:' | |||
|
300 | 300 | |
|
301 | 301 | pre,fn,rest = self.IP.split_user_input(line) |
|
302 | 302 | res = pre + self.IP.expand_aliases(fn,rest) |
|
303 | ||
|
304 | def defalias(self, name, cmd): | |
|
305 | """ Define a new alias | |
|
306 | ||
|
307 | _ip.defalias('bb','bldmake bldfiles') | |
|
308 | ||
|
309 | Creates a new alias named 'bb' in ipython user namespace | |
|
310 | """ | |
|
311 | ||
|
312 | ||
|
313 | nargs = cmd.count('%s') | |
|
314 | if nargs>0 and cmd.find('%l')>=0: | |
|
315 | raise Exception('The %s and %l specifiers are mutually exclusive ' | |
|
316 | 'in alias definitions.') | |
|
317 | ||
|
318 | else: # all looks OK | |
|
319 | self.IP.alias_table[name] = (nargs,cmd) | |
|
320 | ||
|
321 | def defmacro(self, *args): | |
|
322 | """ Define a new macro | |
|
323 | ||
|
324 | 2 forms of calling: | |
|
325 | ||
|
326 | mac = _ip.defmacro('print "hello"\nprint "world"') | |
|
327 | ||
|
328 | (doesn't put the created macro on user namespace) | |
|
329 | ||
|
330 | _ip.defmacro('build', 'bldmake bldfiles\nabld build winscw udeb') | |
|
331 | ||
|
332 | (creates a macro named 'build' in user namespace) | |
|
333 | """ | |
|
334 | ||
|
335 | import IPython.macro | |
|
336 | print args | |
|
337 | if len(args) == 1: | |
|
338 | return IPython.macro.Macro(args[0]) | |
|
339 | elif len(args) == 2: | |
|
340 | self.user_ns[args[0]] = IPython.macro.Macro(args[1]) | |
|
341 | else: | |
|
342 | return Exception("_ip.defmacro must be called with 1 or 2 arguments") | |
|
303 | 343 | |
|
304 | 344 | |
|
305 | 345 | |
@@ -362,3 +402,4 b' def make_session(user_ns = None):' | |||
|
362 | 402 | |
|
363 | 403 | import IPython |
|
364 | 404 | return IPython.Shell.start(user_ns) |
|
405 |
@@ -7,6 +7,9 b'' | |||
|
7 | 7 | * Extensions/ipy_completers.py: introduced Olivier Lauzanne's |
|
8 | 8 | safer & faster 'import' completer. |
|
9 | 9 | |
|
10 | * Introduced new ipapi methods, _ip.defmacro(name, value) | |
|
11 | and _ip.defalias(name, command). | |
|
12 | ||
|
10 | 13 | 2007-04-19 Ville Vainio <vivainio@gmail.com> |
|
11 | 14 | |
|
12 | 15 | * upgrade_dir.py: skip junk files like *.pyc |
General Comments 0
You need to be logged in to leave comments.
Login now