Show More
@@ -494,10 +494,6 b' class InteractiveShell(Configurable, Magic):' | |||||
494 | setattr(sys, k, v) |
|
494 | setattr(sys, k, v) | |
495 | except AttributeError: |
|
495 | except AttributeError: | |
496 | pass |
|
496 | pass | |
497 | try: |
|
|||
498 | delattr(sys, 'ipcompleter') |
|
|||
499 | except AttributeError: |
|
|||
500 | pass |
|
|||
501 | # Reset what what done in self.init_sys_modules |
|
497 | # Reset what what done in self.init_sys_modules | |
502 | try: |
|
498 | try: | |
503 | sys.modules[self.user_ns['__name__']] = self._orig_sys_modules_main_name |
|
499 | sys.modules[self.user_ns['__name__']] = self._orig_sys_modules_main_name | |
@@ -1458,7 +1454,7 b' class InteractiveShell(Configurable, Magic):' | |||||
1458 | # the code computing the traceback. |
|
1454 | # the code computing the traceback. | |
1459 | if self.InteractiveTB.call_pdb: |
|
1455 | if self.InteractiveTB.call_pdb: | |
1460 | # pdb mucks up readline, fix it back |
|
1456 | # pdb mucks up readline, fix it back | |
1461 | self.set_completer() |
|
1457 | self.set_readline_completer() | |
1462 |
|
1458 | |||
1463 | # Actually show the traceback |
|
1459 | # Actually show the traceback | |
1464 | self._showtraceback(etype, value, stb) |
|
1460 | self._showtraceback(etype, value, stb) | |
@@ -1569,7 +1565,7 b' class InteractiveShell(Configurable, Magic):' | |||||
1569 | self.Completer.__class__) |
|
1565 | self.Completer.__class__) | |
1570 | self.Completer.matchers.insert(pos,newcomp) |
|
1566 | self.Completer.matchers.insert(pos,newcomp) | |
1571 |
|
1567 | |||
1572 | def set_completer(self): |
|
1568 | def set_readline_completer(self): | |
1573 | """Reset readline's completer to be our own.""" |
|
1569 | """Reset readline's completer to be our own.""" | |
1574 | self.readline.set_completer(self.Completer.rlcomplete) |
|
1570 | self.readline.set_completer(self.Completer.rlcomplete) | |
1575 |
|
1571 | |||
@@ -1601,7 +1597,7 b' class InteractiveShell(Configurable, Magic):' | |||||
1601 | # Set a number of methods that depend on readline to be no-op |
|
1597 | # Set a number of methods that depend on readline to be no-op | |
1602 | self.savehist = no_op |
|
1598 | self.savehist = no_op | |
1603 | self.reloadhist = no_op |
|
1599 | self.reloadhist = no_op | |
1604 | self.set_completer = no_op |
|
1600 | self.set_readline_completer = no_op | |
1605 | self.set_custom_completer = no_op |
|
1601 | self.set_custom_completer = no_op | |
1606 | self.set_completer_frame = no_op |
|
1602 | self.set_completer_frame = no_op | |
1607 | warn('Readline services not available or not loaded.') |
|
1603 | warn('Readline services not available or not loaded.') | |
@@ -1610,6 +1606,8 b' class InteractiveShell(Configurable, Magic):' | |||||
1610 | self.readline = readline |
|
1606 | self.readline = readline | |
1611 | sys.modules['readline'] = readline |
|
1607 | sys.modules['readline'] = readline | |
1612 | import atexit |
|
1608 | import atexit | |
|
1609 | ### | |||
|
1610 | ||||
1613 | from IPython.core.completer import IPCompleter |
|
1611 | from IPython.core.completer import IPCompleter | |
1614 | self.Completer = IPCompleter(self, |
|
1612 | self.Completer = IPCompleter(self, | |
1615 | self.user_ns, |
|
1613 | self.user_ns, | |
@@ -1619,6 +1617,7 b' class InteractiveShell(Configurable, Magic):' | |||||
1619 | sdisp = self.strdispatchers.get('complete_command', StrDispatch()) |
|
1617 | sdisp = self.strdispatchers.get('complete_command', StrDispatch()) | |
1620 | self.strdispatchers['complete_command'] = sdisp |
|
1618 | self.strdispatchers['complete_command'] = sdisp | |
1621 | self.Completer.custom_completers = sdisp |
|
1619 | self.Completer.custom_completers = sdisp | |
|
1620 | ||||
1622 | # Platform-specific configuration |
|
1621 | # Platform-specific configuration | |
1623 | if os.name == 'nt': |
|
1622 | if os.name == 'nt': | |
1624 | self.readline_startup_hook = readline.set_pre_input_hook |
|
1623 | self.readline_startup_hook = readline.set_pre_input_hook | |
@@ -1642,9 +1641,7 b' class InteractiveShell(Configurable, Magic):' | |||||
1642 | warn('Problems reading readline initialization file <%s>' |
|
1641 | warn('Problems reading readline initialization file <%s>' | |
1643 | % inputrc_name) |
|
1642 | % inputrc_name) | |
1644 |
|
1643 | |||
1645 | # save this in sys so embedded copies can restore it properly |
|
1644 | self.set_readline_completer() | |
1646 | sys.ipcompleter = self.Completer.rlcomplete |
|
|||
1647 | self.set_completer() |
|
|||
1648 |
|
1645 | |||
1649 | # Configure readline according to user's prefs |
|
1646 | # Configure readline according to user's prefs | |
1650 | # This is only done if GNU readline is being used. If libedit |
|
1647 | # This is only done if GNU readline is being used. If libedit |
@@ -74,8 +74,6 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
74 | usage=None, banner1=None, banner2=None, |
|
74 | usage=None, banner1=None, banner2=None, | |
75 | display_banner=None, exit_msg=u''): |
|
75 | display_banner=None, exit_msg=u''): | |
76 |
|
76 | |||
77 | self.save_sys_ipcompleter() |
|
|||
78 |
|
||||
79 | super(InteractiveShellEmbed,self).__init__( |
|
77 | super(InteractiveShellEmbed,self).__init__( | |
80 | config=config, ipython_dir=ipython_dir, user_ns=user_ns, |
|
78 | config=config, ipython_dir=ipython_dir, user_ns=user_ns, | |
81 | user_global_ns=user_global_ns, custom_exceptions=custom_exceptions, |
|
79 | user_global_ns=user_global_ns, custom_exceptions=custom_exceptions, | |
@@ -92,31 +90,9 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
92 | mode=self.xmode, |
|
90 | mode=self.xmode, | |
93 | call_pdb=self.pdb) |
|
91 | call_pdb=self.pdb) | |
94 |
|
92 | |||
95 | self.restore_sys_ipcompleter() |
|
|||
96 |
|
||||
97 | def init_sys_modules(self): |
|
93 | def init_sys_modules(self): | |
98 | pass |
|
94 | pass | |
99 |
|
95 | |||
100 | def save_sys_ipcompleter(self): |
|
|||
101 | """Save readline completer status.""" |
|
|||
102 | try: |
|
|||
103 | #print 'Save completer',sys.ipcompleter # dbg |
|
|||
104 | self.sys_ipcompleter_orig = sys.ipcompleter |
|
|||
105 | except: |
|
|||
106 | pass # not nested with IPython |
|
|||
107 |
|
||||
108 | def restore_sys_ipcompleter(self): |
|
|||
109 | """Restores the readline completer which was in place. |
|
|||
110 |
|
||||
111 | This allows embedded IPython within IPython not to disrupt the |
|
|||
112 | parent's completion. |
|
|||
113 | """ |
|
|||
114 | try: |
|
|||
115 | self.readline.set_completer(self.sys_ipcompleter_orig) |
|
|||
116 | sys.ipcompleter = self.sys_ipcompleter_orig |
|
|||
117 | except: |
|
|||
118 | pass |
|
|||
119 |
|
||||
120 | def __call__(self, header='', local_ns=None, global_ns=None, dummy=None, |
|
96 | def __call__(self, header='', local_ns=None, global_ns=None, dummy=None, | |
121 | stack_depth=1): |
|
97 | stack_depth=1): | |
122 | """Activate the interactive interpreter. |
|
98 | """Activate the interactive interpreter. | |
@@ -169,8 +145,6 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
169 | if self.exit_msg is not None: |
|
145 | if self.exit_msg is not None: | |
170 | print self.exit_msg |
|
146 | print self.exit_msg | |
171 |
|
147 | |||
172 | self.restore_sys_ipcompleter() |
|
|||
173 |
|
||||
174 | def mainloop(self, local_ns=None, global_ns=None, stack_depth=0, |
|
148 | def mainloop(self, local_ns=None, global_ns=None, stack_depth=0, | |
175 | display_banner=None): |
|
149 | display_banner=None): | |
176 | """Embeds IPython into a running python program. |
|
150 | """Embeds IPython into a running python program. |
General Comments 0
You need to be logged in to leave comments.
Login now