[IPython-user] Completion in non-interactive windows (NOT a Windows question!)

Fernando Perez Fernando.Perez at colorado.edu
Sat Jan 8 17:42:28 CST 2005


Hi John,

John J Lee wrote:
> On Sat, 1 Jan 2005, John J Lee wrote:
> 
> 
>>On Sat, 1 Jan 2005, John J Lee wrote:
>>
>>
>>>I realise this is not strictly an IPython issue, but does anyone here know
>>>of any work on completion of Python code in editor windows rather than in
>>>interactive shells?
>>>
>>>Existing work seems to fall short of what I'd like:
>>
>>[...]
>>
>>>- pycomplete.py (part of the emacs python-mode project) addresses module
>>>  and class attributes only.
>>
>>Googling further, I see pydev.sf.net (for Eclipse) does completion on
> 
> [...]
> 
>>TruStudio's open source version of it's Eclipse-based product (CPL -- not
>>GPL compatible :-(( ) claims to do clever completion and has Python
>>support.  Haven't tried it yet, will report back.
> 
> [...]
> 
> OK, seems Pythonwin *does* do completion in non-interactive mode.
> 
> Tried Trustudio, and was unable to get completion working.  It also hung
> on me when trying to do something very simple.
> 
> So (switching back to my personal viewpoint) I guess the easiest route to
> "smart" completion in emacs would be to borrow from Pythonwin, and extend
> the basic framework already in python-mode (which uses pymacs).

sorry I have been quite absent as of late, very busy...

You need to keep in mind that for the kind of completion ipython does to work, 
you need the objects in question to actually have been loaded in memory.  For 
an editor (where things may not even be syntactically valid yet) this approach 
doesn't work.  There are basically three ways to get code completion:

1.  What ipython does: your objects live in memory, and you can rely on 
python's introspection capabilities to extract attribute names.  A hook to GNU 
readline binds this to the tab key, but you could get the same results in a 
gui where you have full control of keyboard events.

2.  The etags/dabbrev Emacs approaches.  Basically just static textual 
analysis of the surrounding lists of words in your open buffers (or the ones 
saved to tags files).

3.  Writing a full-blown textual analyzer which can understand the structure 
of python code as it is being written.  This would give you the full 
capabilities of real completion in an editor, but it's also the most difficult 
one to write.

For an editor, ultimately #3 is what you really want, since you may be writing 
code which can really not be loaded in your current environment (imagine 
coding on your laptop something which can't realistically run outside of some 
big database server).

I have to say that so far though, I've been able to function quite well with 
just # 1 and 2.  IPython gives me accurate completion of live objects, and 
emacs's dabbrev is "good enough" for me when coding.  I know it's far from 
perfect, but its shortcomings are not so bad that I'm willing to spend my time 
fighting this particular battle.

But I would certainly like to see this problem better solved, so by all means 
keep us posted of any progress on the topic.

Cheers,

f




More information about the IPython-user mailing list