diff --git a/IPython/hooks.py b/IPython/hooks.py index 761a771..0e7098e 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 1076 2006-01-24 17:27:05Z vivainio $""" +$Id: hooks.py 1087 2006-01-27 17:02:42Z vivainio $""" #***************************************************************************** # Copyright (C) 2005 Fernando Perez. @@ -53,7 +53,8 @@ from pprint import pformat # List here all the default hooks. For now it's just the editor functions # but over time we'll move here all the public API for user-accessible things. -__all__ = ['editor', 'fix_error_editor', 'result_display'] +__all__ = ['editor', 'fix_error_editor', 'result_display', + 'input_prefilter'] def editor(self,filename, linenum=None): """Open the default editor at the given filename and linenumber. @@ -135,6 +136,11 @@ class CommandChainDispatcher: bisect.insort(self.chain,(priority,func)) def result_display(self,arg): + """ Default display hook. + + Called for displaying the result to the user. + """ + if self.rc.pprint: out = pformat(arg) if '\n' in out: @@ -147,4 +153,17 @@ def result_display(self,arg): 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 + +def input_prefilter(self,line): + """ Default input prefilter + + This returns the line as unchanged, so that the interpreter + knows that nothing was done and proceeds with "classic" prefiltering + (%magics, !shell commands etc.). + + Note that leading whitespace is not passed to this hook. Prefilter + can't alter indentation. + + """ + #print "attempt to rewrite",line #dbg + return line \ No newline at end of file diff --git a/IPython/iplib.py b/IPython/iplib.py index d02cd12..61a63f1 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.3 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 1079 2006-01-24 21:52:31Z vivainio $ +$Id: iplib.py 1087 2006-01-27 17:02:42Z vivainio $ """ #***************************************************************************** @@ -198,7 +198,6 @@ class InteractiveShell(object,Magic): self.api = IPython.ipapi.IPApi(self) - # some minimal strict typechecks. For some core data structures, I # want actual basic python types, not just anything that looks like # one. This is especially true for namespaces. @@ -411,6 +410,7 @@ class InteractiveShell(object,Magic): for hook_name in hooks.__all__: # default hooks have priority 100, i.e. low; user hooks should have 0-100 priority self.set_hook(hook_name,getattr(hooks,hook_name), 100) + print "bound hook",hook_name # Flag to mark unconditional exit self.exit_now = False @@ -1824,7 +1824,9 @@ want to merge them back into the new files.""" % locals() #print '***line: <%s>' % line # dbg # the input history needs to track even empty lines - if not line.strip(): + stripped = line.strip() + + if not stripped: if not continue_prompt: self.outputcache.prompt_count -= 1 return self.handle_normal(line,continue_prompt) @@ -1835,8 +1837,20 @@ want to merge them back into the new files.""" % locals() if continue_prompt and not self.rc.multi_line_specials: return self.handle_normal(line,continue_prompt) + # For the rest, we need the structure of the input pre,iFun,theRest = self.split_user_input(line) + + # See whether any pre-existing handler can take care of it + + rewritten = self.hooks.input_prefilter(stripped) + if rewritten != stripped: # ok, some prefilter did something + rewritten = pre + rewritten # add indentation + return self.handle_normal(rewritten) + + + + #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg # First check for explicit escapes in the last/first character