##// END OF EJS Templates
Fix input transformer bug when pasting ipython promts....
Fix input transformer bug when pasting ipython promts. Fixes a SyntaxError that arose when pasting code containing the IPython continuation prompt without preceding spaces, eg.: In [1]: if True: ...: print "No spaces before the '...:' prompt." This issue was brought up in "http://stackoverflow.com/questions/26297356/how-can-i-paste-the-ipython-output-in-ipython#comment41270724_26297356" This commit adds a test for the bug, and fixes the regular expression that strips continuation prompts.

File last commit:

r15613:1b3e35d2
r19036:4f186a3a
Show More
callbacks.rst
42 lines | 1.4 KiB | text/x-rst | RstLexer

Registering callbacks

Extension code can register callbacks functions which will be called on specific events within the IPython code. You can see the current list of available callbacks, and the parameters that will be passed with each, in the callback prototype functions defined in :mod:`IPython.core.callbacks`.

To register callbacks, use :meth:`IPython.core.events.EventManager.register`. For example:

class VarWatcher(object):
    def __init__(self, ip):
        self.shell = ip
        self.last_x = None

    def pre_execute(self):
        self.last_x = self.shell.user_ns.get('x', None)

    def post_execute(self):
        if self.shell.user_ns.get('x', None) != self.last_x:
            print("x changed!")

def load_ipython_extension(ip):
    vw = VarWatcher(ip)
    ip.events.register('pre_execute', vw.pre_execute)
    ip.events.register('post_execute', vw.post_execute)

Note

This API is experimental in IPython 2.0, and may be revised in future versions.