Show More
@@ -80,6 +80,22 b' class TryNext(Exception):' | |||
|
80 | 80 | self.args = args |
|
81 | 81 | self.kwargs = kwargs |
|
82 | 82 | |
|
83 | class IPyAutocall: | |
|
84 | """ Instances of this class are always autocalled | |
|
85 | ||
|
86 | This happens regardless of 'autocall' variable state. Use this to | |
|
87 | develop macro-like mechanisms. | |
|
88 | """ | |
|
89 | ||
|
90 | def set_ip(self,ip): | |
|
91 | """ Will be used to set _ip point to current ipython instance b/f call | |
|
92 | ||
|
93 | Override this method if you don't want this to happen. | |
|
94 | ||
|
95 | """ | |
|
96 | self._ip = ip | |
|
97 | ||
|
98 | ||
|
83 | 99 | # contains the most recently instantiated IPApi |
|
84 | 100 | |
|
85 | 101 | class IPythonNotRunning: |
@@ -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 23 |
|
|
9 | $Id: iplib.py 2350 2007-05-15 16:56:44Z vivainio $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
@@ -2182,6 +2182,13 b' want to merge them back into the new files.""" % locals()' | |||
|
2182 | 2182 | if line.endswith('# PYTHON-MODE'): |
|
2183 | 2183 | return self.handle_emacs(line,continue_prompt) |
|
2184 | 2184 | |
|
2185 | # instances of IPyAutocall in user_ns get autocalled immediately | |
|
2186 | obj = self.user_ns.get(iFun,None) | |
|
2187 | if isinstance(obj, IPython.ipapi.IPyAutocall): | |
|
2188 | obj.set_ip(self.api) | |
|
2189 | return self.handle_auto(line,continue_prompt, | |
|
2190 | pre,iFun,theRest,obj) | |
|
2191 | ||
|
2185 | 2192 | # Let's try to find if the input line is a magic fn |
|
2186 | 2193 | oinfo = None |
|
2187 | 2194 | if hasattr(self,'magic_'+iFun): |
@@ -2359,6 +2366,7 b' want to merge them back into the new files.""" % locals()' | |||
|
2359 | 2366 | self.log(line,line,continue_prompt) |
|
2360 | 2367 | return line |
|
2361 | 2368 | |
|
2369 | force_auto = isinstance(obj, IPython.ipapi.IPyAutocall) | |
|
2362 | 2370 | auto_rewrite = True |
|
2363 | 2371 | |
|
2364 | 2372 | if pre == self.ESC_QUOTE: |
@@ -2374,11 +2382,11 b' want to merge them back into the new files.""" % locals()' | |||
|
2374 | 2382 | # We only apply it to argument-less calls if the autocall |
|
2375 | 2383 | # parameter is set to 2. We only need to check that autocall is < |
|
2376 | 2384 | # 2, since this function isn't called unless it's at least 1. |
|
2377 | if not theRest and (self.rc.autocall < 2): | |
|
2385 | if not theRest and (self.rc.autocall < 2) and not force_auto: | |
|
2378 | 2386 | newcmd = '%s %s' % (iFun,theRest) |
|
2379 | 2387 | auto_rewrite = False |
|
2380 | 2388 | else: |
|
2381 | if theRest.startswith('['): | |
|
2389 | if not force_auto and theRest.startswith('['): | |
|
2382 | 2390 | if hasattr(obj,'__getitem__'): |
|
2383 | 2391 | # Don't autocall in this case: item access for an object |
|
2384 | 2392 | # which is BOTH callable and implements __getitem__. |
@@ -11,9 +11,9 b' import IPython.ipapi' | |||
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | from IPython.genutils import Term |
|
14 | from IPython.ipapi import IPyAutocall | |
|
14 | 15 | |
|
15 | ||
|
16 | class Macro: | |
|
16 | class Macro(IPyAutocall): | |
|
17 | 17 | """Simple class to store the value of macros as strings. |
|
18 | 18 | |
|
19 | 19 | Macro is just a callable that executes a string of IPython |
@@ -34,5 +34,5 b' class Macro:' | |||
|
34 | 34 | |
|
35 | 35 | def __call__(self): |
|
36 | 36 | Term.cout.flush() |
|
37 | ip = IPython.ipapi.get() | |
|
38 | ip.runlines(self.value) No newline at end of file | |
|
37 | ||
|
38 | self._ip.runlines(self.value) No newline at end of file |
@@ -10,6 +10,10 b'' | |||
|
10 | 10 | |
|
11 | 11 | * Magic.py, ipy_rehashdir.py, ipy_profile_sh.py: System command |
|
12 | 12 | aliases are now lower case on windows (MyCommand.exe => mycommand). |
|
13 | ||
|
14 | * macro.py, ipapi.py, iplib.py, Prompts.py: Macro system rehaul. | |
|
15 | Macros are now callable objects that inherit from ipapi.IPyAutocall, | |
|
16 | i.e. get autocalled regardless of system autocall setting. | |
|
13 | 17 | |
|
14 | 18 | 2007-05-10 Fernando Perez <Fernando.Perez@colorado.edu> |
|
15 | 19 |
General Comments 0
You need to be logged in to leave comments.
Login now