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