Show More
@@ -7,6 +7,7 Authors: | |||
|
7 | 7 | |
|
8 | 8 | * Brian Granger |
|
9 | 9 | * Fernando Perez |
|
10 | * Thomas Kluyver | |
|
10 | 11 | |
|
11 | 12 | Notes |
|
12 | 13 | ----- |
@@ -34,8 +35,11 class IPyAutocall(object): | |||
|
34 | 35 | This happens regardless of 'autocall' variable state. Use this to |
|
35 | 36 | develop macro-like mechanisms. |
|
36 | 37 | """ |
|
38 | _ip = None | |
|
39 | def __init__(self, ip=None): | |
|
40 | self._ip = ip | |
|
37 | 41 | |
|
38 | def set_ip(self,ip): | |
|
42 | def set_ip(self, ip): | |
|
39 | 43 | """ Will be used to set _ip point to current ipython instance b/f call |
|
40 | 44 | |
|
41 | 45 | Override this method if you don't want this to happen. |
@@ -43,3 +47,10 class IPyAutocall(object): | |||
|
43 | 47 | """ |
|
44 | 48 | self._ip = ip |
|
45 | 49 | |
|
50 | ||
|
51 | class ExitAutocall(IPyAutocall): | |
|
52 | """An autocallable object which will be added to the user namespace so that | |
|
53 | exit, exit(), quit or quit() are all valid ways to close the shell.""" | |
|
54 | ||
|
55 | def __call__(self): | |
|
56 | self._ip.ask_exit() |
@@ -39,6 +39,7 from IPython.core import prefilter | |||
|
39 | 39 | from IPython.core import shadowns |
|
40 | 40 | from IPython.core import ultratb |
|
41 | 41 | from IPython.core.alias import AliasManager |
|
42 | from IPython.core.autocall import ExitAutocall | |
|
42 | 43 | from IPython.core.builtin_trap import BuiltinTrap |
|
43 | 44 | from IPython.core.compilerop import CachingCompiler |
|
44 | 45 | from IPython.core.display_trap import DisplayTrap |
@@ -1023,6 +1024,10 class InteractiveShell(Configurable, Magic): | |||
|
1023 | 1024 | |
|
1024 | 1025 | # Store myself as the public api!!! |
|
1025 | 1026 | ns['get_ipython'] = self.get_ipython |
|
1027 | ||
|
1028 | exiter = ExitAutocall(self) | |
|
1029 | for n in ['exit', 'Exit', 'quit', 'Quit']: | |
|
1030 | ns[n] = exiter | |
|
1026 | 1031 | |
|
1027 | 1032 | # Sync what we've added so far to user_ns_hidden so these aren't seen |
|
1028 | 1033 | # by %who |
@@ -2503,14 +2503,6 Defaulting color scheme to 'NoColor'""" | |||
|
2503 | 2503 | ptformatter.pprint = bool(1 - ptformatter.pprint) |
|
2504 | 2504 | print 'Pretty printing has been turned', \ |
|
2505 | 2505 | ['OFF','ON'][ptformatter.pprint] |
|
2506 | ||
|
2507 | def magic_Exit(self, parameter_s=''): | |
|
2508 | """Exit IPython.""" | |
|
2509 | ||
|
2510 | self.shell.ask_exit() | |
|
2511 | ||
|
2512 | # Add aliases as magics so all common forms work: exit, quit, Exit, Quit. | |
|
2513 | magic_exit = magic_quit = magic_Quit = magic_Exit | |
|
2514 | 2506 | |
|
2515 | 2507 | #...................................................................... |
|
2516 | 2508 | # Functions to implement unix shell-type things |
General Comments 0
You need to be logged in to leave comments.
Login now