diff --git a/IPython/completer.py b/IPython/completer.py index 781aaf2..60eb7ed 100644 --- a/IPython/completer.py +++ b/IPython/completer.py @@ -599,12 +599,19 @@ class IPCompleter(Completer): return None - - def complete(self, text, state): + def complete(self, text, state,line_buffer=None): """Return the next possible completion for 'text'. This is called successively with state == 0, 1, 2, ... until it - returns None. The completion should begin with 'text'. """ + returns None. The completion should begin with 'text'. + + :Keywords: + - line_buffer: string + If not given, the completer attempts to obtain the current line buffer + via readline. This keyword allows clients which are requesting for + text completions in non-readline contexts to inform the completer of + the entire text. + """ #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg @@ -616,16 +623,20 @@ class IPCompleter(Completer): # don't apply this on 'dumb' terminals, such as emacs buffers, so we # don't interfere with their own tab-completion mechanism. - self.full_lbuf = self.get_line_buffer() - self.lbuf = self.full_lbuf[:self.readline.get_endidx()] - if not (self.dumb_terminal or self.get_line_buffer().strip()): + if line_buffer is None: + self.full_lbuf = self.get_line_buffer() + else: + self.full_lbuf = line_buffer + + if not (self.dumb_terminal or self.full_lbuf.strip()): self.readline.insert_text('\t') return None - magic_escape = self.magic_escape magic_prefix = self.magic_prefix + self.lbuf = self.full_lbuf[:self.readline.get_endidx()] + try: if text.startswith(magic_escape): text = text.replace(magic_escape,magic_prefix) diff --git a/IPython/iplib.py b/IPython/iplib.py index 5fb394b..d04557d 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.3 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 2196 2007-04-02 06:02:16Z fperez $ +$Id: iplib.py 2197 2007-04-02 07:36:55Z fperez $ """ #***************************************************************************** @@ -1003,10 +1003,11 @@ class InteractiveShell(object,Magic): complete = self.Completer.complete state = 0 # use a dict so we get unique keys, since ipyhton's multiple - # completers can return duplicates. + # completers can return duplicates. When we make 2.4 a requirement, + # start using sets instead, which are faster. comps = {} while True: - newcomp = complete(text,state) + newcomp = complete(text,state,line_buffer=text) if newcomp is None: break comps[newcomp] = 1 diff --git a/doc/ChangeLog b/doc/ChangeLog index c4d00e2..700eb6a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,9 @@ 2007-04-02 Fernando Perez + * IPython/completer.py (IPCompleter.complete): extend the + complete() call API to support completions by other mechanisms + than readline. Closes #109. + * IPython/iplib.py (safe_execfile): add a safeguard under Win32 to protect against a bug in Python's execfile(). Closes #123.