##// END OF EJS Templates
Replace magic exit function with exit subclassing IPyAutocall. Credit to David Warde-Farley (@dwf) for tackling this issue.
Thomas Kluyver -
Show More
@@ -7,6 +7,7 b' Authors:'
7
7
8 * Brian Granger
8 * Brian Granger
9 * Fernando Perez
9 * Fernando Perez
10 * Thomas Kluyver
10
11
11 Notes
12 Notes
12 -----
13 -----
@@ -34,8 +35,11 b' class IPyAutocall(object):'
34 This happens regardless of 'autocall' variable state. Use this to
35 This happens regardless of 'autocall' variable state. Use this to
35 develop macro-like mechanisms.
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 """ Will be used to set _ip point to current ipython instance b/f call
43 """ Will be used to set _ip point to current ipython instance b/f call
40
44
41 Override this method if you don't want this to happen.
45 Override this method if you don't want this to happen.
@@ -43,3 +47,10 b' class IPyAutocall(object):'
43 """
47 """
44 self._ip = ip
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 b' from IPython.core import prefilter'
39 from IPython.core import shadowns
39 from IPython.core import shadowns
40 from IPython.core import ultratb
40 from IPython.core import ultratb
41 from IPython.core.alias import AliasManager
41 from IPython.core.alias import AliasManager
42 from IPython.core.autocall import ExitAutocall
42 from IPython.core.builtin_trap import BuiltinTrap
43 from IPython.core.builtin_trap import BuiltinTrap
43 from IPython.core.compilerop import CachingCompiler
44 from IPython.core.compilerop import CachingCompiler
44 from IPython.core.display_trap import DisplayTrap
45 from IPython.core.display_trap import DisplayTrap
@@ -1023,6 +1024,10 b' class InteractiveShell(Configurable, Magic):'
1023
1024
1024 # Store myself as the public api!!!
1025 # Store myself as the public api!!!
1025 ns['get_ipython'] = self.get_ipython
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 # Sync what we've added so far to user_ns_hidden so these aren't seen
1032 # Sync what we've added so far to user_ns_hidden so these aren't seen
1028 # by %who
1033 # by %who
@@ -2503,14 +2503,6 b' Defaulting color scheme to \'NoColor\'"""'
2503 ptformatter.pprint = bool(1 - ptformatter.pprint)
2503 ptformatter.pprint = bool(1 - ptformatter.pprint)
2504 print 'Pretty printing has been turned', \
2504 print 'Pretty printing has been turned', \
2505 ['OFF','ON'][ptformatter.pprint]
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 # Functions to implement unix shell-type things
2508 # Functions to implement unix shell-type things
General Comments 0
You need to be logged in to leave comments. Login now