diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 906ffe3..c747915 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1849,6 +1849,28 @@ class InteractiveShell(Configurable, Magic): # code out there that may rely on this). self.prefilter = self.prefilter_manager.prefilter_lines + + def auto_rewrite_input(self, cmd): + """Print to the screen the rewritten form of the user's command. + + This shows visual feedback for things like:: + + In [1]: /f x + ------> f(x) + + Which helps the user understand that the input line was transformed + automatically. + """ + rw = self.displayhook.prompt1.auto_rewrite() + cmd + + try: + # plain ascii works better w/ pyreadline, on some machines, so + # we use it and only print uncolored rewrite if we have unicode + rw = str(rw) + print >> IPython.utils.io.Term.cout, rw + except UnicodeEncodeError: + print "------> " + cmd + #------------------------------------------------------------------------- # Things related to extracting values/expressions from kernel and user_ns #------------------------------------------------------------------------- diff --git a/IPython/core/prefilter.py b/IPython/core/prefilter.py index d2e86ac..d56008f 100755 --- a/IPython/core/prefilter.py +++ b/IPython/core/prefilter.py @@ -916,15 +916,7 @@ class AutoHandler(PrefilterHandler): newcmd = '%s(%s)' % (ifun.rstrip(), the_rest) if auto_rewrite: - rw = self.shell.displayhook.prompt1.auto_rewrite() + newcmd - - try: - # plain ascii works better w/ pyreadline, on some machines, so - # we use it and only print uncolored rewrite if we have unicode - rw = str(rw) - print >>IPython.utils.io.Term.cout, rw - except UnicodeEncodeError: - print "-------------->" + newcmd + self.shell.auto_rewrite_input(newcmd) # log what is now valid Python, not the actual user input (without the # final newline) diff --git a/IPython/core/prompts.py b/IPython/core/prompts.py index 753659c..10761cc 100644 --- a/IPython/core/prompts.py +++ b/IPython/core/prompts.py @@ -385,7 +385,7 @@ class Prompt1(BasePrompt): return str_safe(self.p_str) def auto_rewrite(self): - """Print a string of the form '--->' which lines up with the previous + """Return a string of the form '--->' which lines up with the previous input string. Useful for systems which re-write the user input when handling automatically special syntaxes.""" diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index dce0644..1d13680 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -377,7 +377,19 @@ class ZMQInteractiveShell(InteractiveShell): def magic_pylab(self, *args, **kwargs): raise NotImplementedError('pylab support must be enabled in commandl in options.') + def auto_rewrite_input(self, cmd): + """Called to show the auto-rewritten input for autocall and friends. + FIXME: this payload is currently not correctly processed by the + frontend. + """ + new = self.displayhook.prompt1.auto_rewrite() + cmd + payload = dict( + source='IPython.zmq.zmqshell.ZMQInteractiveShell.auto_rewrite_input', + transformed_input=new, + ) + self.payload_manager.write_payload(payload) + def ask_exit(self): """Engage the exit actions.""" payload = dict(