From 49794057c5930fb46815394a69be73aad2c82ec7 2005-09-01 00:27:53 From: fperez Date: 2005-09-01 00:27:53 Subject: [PATCH] Added .complete() method to ipython. This exposes the attribute completion machinery which normally only readline sees. It will be useful to Brian for the remote kernels, and also for the GUIs to do tab completion. Please merge into chainsaw/tzanko branches. --- diff --git a/IPython/iplib.py b/IPython/iplib.py index 0779094..8ef9c16 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.1 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 723 2005-08-19 17:37:46Z fperez $ +$Id: iplib.py 774 2005-09-01 00:27:53Z fperez $ """ #***************************************************************************** @@ -888,6 +888,40 @@ class InteractiveShell(code.InteractiveConsole, Logger, Magic): self.Completer.__class__) self.Completer.matchers.insert(pos,newcomp) + def complete(self,text): + """Return a sorted list of all possible completions on text. + + Inputs: + + - text: a string of text to be completed on. + + This is a wrapper around the completion mechanism, similar to what + readline does at the command line when the TAB key is hit. By + exposing it as a method, it can be used by other non-readline + environments (such as GUIs) for text completion. + + Simple usage example: + + In [1]: x = 'hello' + + In [2]: __IP.complete('x.l') + Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']""" + + complete = self.Completer.complete + state = 0 + # use a dict so we get unique keys, since ipyhton's multiple + # completers can return duplicates. + comps = {} + while True: + newcomp = complete(text,state) + if newcomp is None: + break + comps[newcomp] = 1 + state += 1 + outcomps = comps.keys() + outcomps.sort() + return outcomps + def post_config_initialization(self): """Post configuration init method diff --git a/doc/ChangeLog b/doc/ChangeLog index 7bc198e..b4d7747 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2005-08-31 Fernando Perez + + * IPython/iplib.py (InteractiveShell.complete): Added new + top-level completion method to expose the completion mechanism + beyond readline-based environments. + 2005-08-19 Fernando Perez * tools/ipsvnc (svnversion): fix svnversion capture.