##// END OF EJS Templates
Changing input filtering to require whitespace separation between the initial command (alias, magic, autocall) and rest of line. ...
Changing input filtering to require whitespace separation between the initial command (alias, magic, autocall) and rest of line. This fixes some subtle but nasty bugs with lines that start with, e.g. r'a_string'. They had been getting parsed as the magic %r followed by the string literal 'a_string' -- now that's been fixed.

File last commit:

r284:9c6bbd29
r707:8de6d199
Show More
ext_rescapture.py
66 lines | 1.5 KiB | text/x-python | PythonLexer
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151 # -*- coding: utf-8 -*-
""" IPython extension: new prefilters for output grabbing
Provides
var = %magic blah blah
var = !ls
$Id: genutils.py 1077 2006-01-24 18:15:27Z vivainio $
"""
import IPython.ipapi
from IPython.genutils import *
ip = IPython.ipapi.get()
import re
def hnd_magic(line,mo):
""" Handle a = %mymagic blah blah """
#cmd = genutils.make_quoted_expr(mo.group('syscmd'))
#mag = 'ipmagic
#return "%s = %s"
var = mo.group('varname')
cmd = mo.group('cmd')
expr = make_quoted_expr(cmd)
vivainio
-Expose IPApi is _ip in user namespace....
r158 return itpl('$var = _ip.magic($expr)')
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
def hnd_syscmd(line,mo):
""" Handle a = !ls """
#cmd = genutils.make_quoted_expr(mo.group('syscmd'))
#mag = 'ipmagic
#return "%s = %s"
var = mo.group('varname')
cmd = mo.group('cmd')
vivainio
alias completing only made for first item...
r186 expr = make_quoted_expr(itpl("sc -lv =$cmd"))
vivainio
-Expose IPApi is _ip in user namespace....
r158 return itpl('$var = _ip.magic($expr)')
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
def install_re_handler(pat, hnd):
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 ip.meta.re_prefilters.append((re.compile(pat), hnd))
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
def init_handlers():
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 ip.meta.re_prefilters = []
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
install_re_handler('(?P<varname>[\w\.]+)\s*=\s*%(?P<cmd>.*)',
hnd_magic
)
install_re_handler('(?P<varname>[\w\.]+)\s*=\s*!(?P<cmd>.*)',
hnd_syscmd
)
init_handlers()
def regex_prefilter_f(self,line):
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 for pat, handler in ip.meta.re_prefilters:
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151 mo = pat.match(line)
if mo:
return handler(line,mo)
raise IPython.ipapi.TryNext
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 ip.set_hook('input_prefilter', regex_prefilter_f)