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

Stefan Reichör stefan at xsteve.at
Wed Jan 12 00:41:59 CST 2005


Alexander Schmolck <a.schmolck at gmx.net> writes:

>>> 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.
>>
>> Trustudio and Pythonwin take this approach.
>>
>>
>>> 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).
>>
>> Sure.
>>
>>
>>> 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
>> [...]
>>
>> I've come to the same conclusion.  Would of course also be pleased to see
>> an unreasonable man/woman do this "properly" (ie. approach #3 above) in
>> emacs.
>
> 3. Is of course impossible to do "properly" (i.e. you simply *can't* determine
> everything you'd need for code completion to work 100% statically), but if all
> you'd like is self.<tab> to do method completion on the methods of the current
> class (and possibly superclass methods, too) then I think that's really fairly
> trivial (i.e. one could in principle code up a version that handle's most
> cases in less than 30 minutes -- either by just using emacs functionality or
> if you prefer calling a python script from emacs that returns the required
> info).
>
> Here is an outline of a primitive example algorithm for emacs:
>
> - py-beginning-of-def-or-class (repeat till the def starts with self, otherwise
>   it's just a local function definition)
> - extract definition arguments per regexp or simply by moving by forward 2
>   words and then copying each following word and moving forward to the next word)
> - repeat the same for all defs at the same level till you reach a line that
>   starts with 'class'
> - Goto the end of the class with py-end-of-def-or-class and then move up
>   definitions till you go past your original starting point
>
> Properties are easily added but if you want completion on superclass methods
> that requires of course a bit more work and you'll presumably want to cache
> results (but even here a simple minded version should be quickly coded) --
> have a look at bicycle repair man, though -- I'd think that they must already
> have done most of the hard work so maybe it ought to be possible to leverage
> that for code completion.

Semantic (http://cedet.sourceforge.net/semantic.shtml) provides a
python parser for emacs. That could be considered also.

Stefan.




More information about the IPython-user mailing list