Show More
@@ -32,7 +32,7 b" ip_set_hook('editor',myiphooks.calljed)" | |||||
32 | The ip_set_hook function is put by IPython into the builtin namespace, so it |
|
32 | The ip_set_hook function is put by IPython into the builtin namespace, so it | |
33 | is always available from all running code. |
|
33 | is always available from all running code. | |
34 |
|
34 | |||
35 |
$Id: hooks.py 107 |
|
35 | $Id: hooks.py 1087 2006-01-27 17:02:42Z vivainio $""" | |
36 |
|
36 | |||
37 | #***************************************************************************** |
|
37 | #***************************************************************************** | |
38 | # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu> |
|
38 | # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu> | |
@@ -53,7 +53,8 b' from pprint import pformat' | |||||
53 |
|
53 | |||
54 | # List here all the default hooks. For now it's just the editor functions |
|
54 | # List here all the default hooks. For now it's just the editor functions | |
55 | # but over time we'll move here all the public API for user-accessible things. |
|
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 | def editor(self,filename, linenum=None): |
|
59 | def editor(self,filename, linenum=None): | |
59 | """Open the default editor at the given filename and linenumber. |
|
60 | """Open the default editor at the given filename and linenumber. | |
@@ -135,6 +136,11 b' class CommandChainDispatcher:' | |||||
135 | bisect.insort(self.chain,(priority,func)) |
|
136 | bisect.insort(self.chain,(priority,func)) | |
136 |
|
137 | |||
137 | def result_display(self,arg): |
|
138 | def result_display(self,arg): | |
|
139 | """ Default display hook. | |||
|
140 | ||||
|
141 | Called for displaying the result to the user. | |||
|
142 | """ | |||
|
143 | ||||
138 | if self.rc.pprint: |
|
144 | if self.rc.pprint: | |
139 | out = pformat(arg) |
|
145 | out = pformat(arg) | |
140 | if '\n' in out: |
|
146 | if '\n' in out: | |
@@ -148,3 +154,16 b' def result_display(self,arg):' | |||||
148 | # the default display hook doesn't manipulate the value to put in history |
|
154 | # the default display hook doesn't manipulate the value to put in history | |
149 | return None |
|
155 | return None | |
150 |
|
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 | This file contains all the classes and helper functions specific to IPython. |
|
7 | This file contains all the classes and helper functions specific to IPython. | |
8 |
|
8 | |||
9 |
$Id: iplib.py 107 |
|
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 | self.api = IPython.ipapi.IPApi(self) |
|
199 | self.api = IPython.ipapi.IPApi(self) | |
200 |
|
200 | |||
201 |
|
||||
202 | # some minimal strict typechecks. For some core data structures, I |
|
201 | # some minimal strict typechecks. For some core data structures, I | |
203 | # want actual basic python types, not just anything that looks like |
|
202 | # want actual basic python types, not just anything that looks like | |
204 | # one. This is especially true for namespaces. |
|
203 | # one. This is especially true for namespaces. | |
@@ -411,6 +410,7 b' class InteractiveShell(object,Magic):' | |||||
411 | for hook_name in hooks.__all__: |
|
410 | for hook_name in hooks.__all__: | |
412 | # default hooks have priority 100, i.e. low; user hooks should have 0-100 priority |
|
411 | # default hooks have priority 100, i.e. low; user hooks should have 0-100 priority | |
413 | self.set_hook(hook_name,getattr(hooks,hook_name), 100) |
|
412 | self.set_hook(hook_name,getattr(hooks,hook_name), 100) | |
|
413 | print "bound hook",hook_name | |||
414 |
|
414 | |||
415 | # Flag to mark unconditional exit |
|
415 | # Flag to mark unconditional exit | |
416 | self.exit_now = False |
|
416 | self.exit_now = False | |
@@ -1824,7 +1824,9 b' want to merge them back into the new files.""" % locals()' | |||||
1824 | #print '***line: <%s>' % line # dbg |
|
1824 | #print '***line: <%s>' % line # dbg | |
1825 |
|
1825 | |||
1826 | # the input history needs to track even empty lines |
|
1826 | # the input history needs to track even empty lines | |
1827 |
|
|
1827 | stripped = line.strip() | |
|
1828 | ||||
|
1829 | if not stripped: | |||
1828 | if not continue_prompt: |
|
1830 | if not continue_prompt: | |
1829 | self.outputcache.prompt_count -= 1 |
|
1831 | self.outputcache.prompt_count -= 1 | |
1830 | return self.handle_normal(line,continue_prompt) |
|
1832 | return self.handle_normal(line,continue_prompt) | |
@@ -1835,8 +1837,20 b' want to merge them back into the new files.""" % locals()' | |||||
1835 | if continue_prompt and not self.rc.multi_line_specials: |
|
1837 | if continue_prompt and not self.rc.multi_line_specials: | |
1836 | return self.handle_normal(line,continue_prompt) |
|
1838 | return self.handle_normal(line,continue_prompt) | |
1837 |
|
1839 | |||
|
1840 | ||||
1838 | # For the rest, we need the structure of the input |
|
1841 | # For the rest, we need the structure of the input | |
1839 | pre,iFun,theRest = self.split_user_input(line) |
|
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 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1854 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg | |
1841 |
|
1855 | |||
1842 | # First check for explicit escapes in the last/first character |
|
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