##// END OF EJS Templates
mods
vivainio -
Show More
@@ -32,7 +32,7 b" ip_set_hook('editor',myiphooks.calljed)"
32 32 The ip_set_hook function is put by IPython into the builtin namespace, so it
33 33 is always available from all running code.
34 34
35 $Id: hooks.py 1076 2006-01-24 17:27:05Z vivainio $"""
35 $Id: hooks.py 1087 2006-01-27 17:02:42Z vivainio $"""
36 36
37 37 #*****************************************************************************
38 38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
@@ -53,7 +53,8 b' from pprint import pformat'
53 53
54 54 # List here all the default hooks. For now it's just the editor functions
55 55 # but over time we'll move here all the public API for user-accessible things.
56 __all__ = ['editor', 'fix_error_editor', 'result_display']
56 __all__ = ['editor', 'fix_error_editor', 'result_display',
57 'input_prefilter']
57 58
58 59 def editor(self,filename, linenum=None):
59 60 """Open the default editor at the given filename and linenumber.
@@ -135,6 +136,11 b' class CommandChainDispatcher:'
135 136 bisect.insort(self.chain,(priority,func))
136 137
137 138 def result_display(self,arg):
139 """ Default display hook.
140
141 Called for displaying the result to the user.
142 """
143
138 144 if self.rc.pprint:
139 145 out = pformat(arg)
140 146 if '\n' in out:
@@ -147,4 +153,17 b' def result_display(self,arg):'
147 153 print >>Term.cout, arg
148 154 # the default display hook doesn't manipulate the value to put in history
149 155 return None
150 No newline at end of file
156
157 def input_prefilter(self,line):
158 """ Default input prefilter
159
160 This returns the line as unchanged, so that the interpreter
161 knows that nothing was done and proceeds with "classic" prefiltering
162 (%magics, !shell commands etc.).
163
164 Note that leading whitespace is not passed to this hook. Prefilter
165 can't alter indentation.
166
167 """
168 #print "attempt to rewrite",line #dbg
169 return line No newline at end of file
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 1079 2006-01-24 21:52:31Z vivainio $
9 $Id: iplib.py 1087 2006-01-27 17:02:42Z vivainio $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -198,7 +198,6 b' class InteractiveShell(object,Magic):'
198 198
199 199 self.api = IPython.ipapi.IPApi(self)
200 200
201
202 201 # some minimal strict typechecks. For some core data structures, I
203 202 # want actual basic python types, not just anything that looks like
204 203 # one. This is especially true for namespaces.
@@ -411,6 +410,7 b' class InteractiveShell(object,Magic):'
411 410 for hook_name in hooks.__all__:
412 411 # default hooks have priority 100, i.e. low; user hooks should have 0-100 priority
413 412 self.set_hook(hook_name,getattr(hooks,hook_name), 100)
413 print "bound hook",hook_name
414 414
415 415 # Flag to mark unconditional exit
416 416 self.exit_now = False
@@ -1824,7 +1824,9 b' want to merge them back into the new files.""" % locals()'
1824 1824 #print '***line: <%s>' % line # dbg
1825 1825
1826 1826 # the input history needs to track even empty lines
1827 if not line.strip():
1827 stripped = line.strip()
1828
1829 if not stripped:
1828 1830 if not continue_prompt:
1829 1831 self.outputcache.prompt_count -= 1
1830 1832 return self.handle_normal(line,continue_prompt)
@@ -1835,8 +1837,20 b' want to merge them back into the new files.""" % locals()'
1835 1837 if continue_prompt and not self.rc.multi_line_specials:
1836 1838 return self.handle_normal(line,continue_prompt)
1837 1839
1840
1838 1841 # For the rest, we need the structure of the input
1839 1842 pre,iFun,theRest = self.split_user_input(line)
1843
1844 # See whether any pre-existing handler can take care of it
1845
1846 rewritten = self.hooks.input_prefilter(stripped)
1847 if rewritten != stripped: # ok, some prefilter did something
1848 rewritten = pre + rewritten # add indentation
1849 return self.handle_normal(rewritten)
1850
1851
1852
1853
1840 1854 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1841 1855
1842 1856 # First check for explicit escapes in the last/first character
General Comments 0
You need to be logged in to leave comments. Login now