diff --git a/IPython/Magic.py b/IPython/Magic.py index ea28923..0c8ddf1 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 1071 2006-01-23 21:30:41Z vivainio $""" +$Id: Magic.py 1076 2006-01-24 17:27:05Z vivainio $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -2760,7 +2760,7 @@ Defaulting color scheme to 'NoColor'""" page(self.shell.pycolorize(file_read(filename)), screen_lines=self.shell.rc.screen_length) - def magic_paste(self, parameter_s=''): + def magic_cpaste(self, parameter_s=''): """Allows you to paste & execute a pre-formatted code block from clipboard. @@ -2772,7 +2772,7 @@ Defaulting color scheme to 'NoColor'""" method definitions. The executed block is also assigned to variable named 'pasted_block' for later editing with '%edit pasted_block'. - You can also pass a variable name as an argument, e.g. '%paste foo'. + You can also pass a variable name as an argument, e.g. '%cpaste foo'. This assigns the pasted block to variable 'foo' as string, without dedenting or executing it. diff --git a/IPython/Prompts.py b/IPython/Prompts.py index dca990f..127d8d0 100644 --- a/IPython/Prompts.py +++ b/IPython/Prompts.py @@ -2,7 +2,7 @@ """ Classes for handling input/output prompts. -$Id: Prompts.py 1020 2006-01-14 13:22:58Z vivainio $""" +$Id: Prompts.py 1076 2006-01-24 17:27:05Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez @@ -497,9 +497,7 @@ class CachedOutput: if arg is not None: cout_write = Term.cout.write # fast lookup # first handle the cache and counters - # but avoid recursive reference when displaying _oh/Out - if arg is not self.user_ns['_oh']: - self.update(arg) + # do not print output if input ends in ';' if self.input_hist[self.prompt_count].endswith(';\n'): return @@ -516,7 +514,18 @@ class CachedOutput: return None # and now call a possibly user-defined print mechanism - self.display(arg) + manipulated_val = self.display(arg) + + # user display hooks can change the variable to be stored in + # output history + + if manipulated_val is not None: + arg = manipulated_val + + # avoid recursive reference when displaying _oh/Out + if arg is not self.user_ns['_oh']: + self.update(arg) + if self.logger.log_output: self.logger.log_write(repr(arg),'output') cout_write(self.output_sep2) @@ -529,7 +538,7 @@ class CachedOutput: display, e.g. when your own objects need special formatting. """ - self.shell.hooks.result_display(arg) + return self.shell.hooks.result_display(arg) # Assign the default display method: display = _display diff --git a/IPython/hooks.py b/IPython/hooks.py index ad863e4..761a771 100644 --- a/IPython/hooks.py +++ b/IPython/hooks.py @@ -32,7 +32,7 @@ ip_set_hook('editor',myiphooks.calljed) The ip_set_hook function is put by IPython into the builtin namespace, so it is always available from all running code. -$Id: hooks.py 1020 2006-01-14 13:22:58Z vivainio $""" +$Id: hooks.py 1076 2006-01-24 17:27:05Z vivainio $""" #***************************************************************************** # Copyright (C) 2005 Fernando Perez. @@ -42,6 +42,7 @@ $Id: hooks.py 1020 2006-01-14 13:22:58Z vivainio $""" #***************************************************************************** from IPython import Release +from IPython import ipapi __author__ = '%s <%s>' % Release.authors['Fernando'] __license__ = Release.license __version__ = Release.version @@ -96,8 +97,6 @@ def fix_error_editor(self,filename,linenum,column,msg): finally: t.close() -class TryNext(Exception): - pass class CommandChainDispatcher: """ Dispatch calls to a chain of commands until some func can handle it @@ -125,7 +124,7 @@ class CommandChainDispatcher: try: ret = cmd(*args, **kw) return ret - except TryNext: + except ipapi.TryNext: pass def __str__(self): @@ -146,4 +145,6 @@ def result_display(self,arg): print >>Term.cout, out else: print >>Term.cout, arg + # the default display hook doesn't manipulate the value to put in history + return None \ No newline at end of file diff --git a/IPython/ipapi.py b/IPython/ipapi.py index 20d8960..8355ee7 100644 --- a/IPython/ipapi.py +++ b/IPython/ipapi.py @@ -60,6 +60,18 @@ print "done!" ''' + +class TryNext(Exception): + """ Try next hook exception. + + Raise this in your hook function to indicate that the next + hook handler should be used to handle the operation. + """ + + + +__IP = None + def _init_with_shell(ip): global magic magic = ip.ipmagic @@ -151,7 +163,12 @@ def launch_new_instance(): import IPython IPython.Shell.start().mainloop() + +def is_ipython_session(): + """ Return a true value if running inside IPython. + """ - - \ No newline at end of file + # Yes, this is the shell object or None - however, it's an implementation + # detail and should not be relied on, only truth value matters. + return __IP diff --git a/doc/ChangeLog b/doc/ChangeLog index e0d8b99..151c39f 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,15 @@ +2006-01-24 Ville Vainio + + * iplib.py, hooks.py: 'result_display' hook can return a non-None + value to manipulate resulting history entry. + + * ipapi.py: Moved TryNext here from hooks.py, added + is_ipython_session() to determine whether we are running + inside an ipython session. + 2006-01-23 Ville Vainio - * Added %paste magic for pasting python code + * Added %cpaste magic for pasting python code 2006-01-22 Ville Vainio