Auto complete and Calltips for Python

I created this page go give an overview and get possible hints/ correction/improvements for getting and implementing good Code completition and Calltips in an (Python) programmers editor. As these to things are very useful and common nowadays (so as syntax coloring is a "must"), I want to take a critical look at it ;)

The first question: how shall we call it? Autocomplete or Codecomplete or Code Completition?

I favour CodeCompletion, because Autocompletion is to common and could mean any completion to help/ make text editing more efficient. At the other side, AutoComplete is the word used in Scintilla.

DrPython

In DrPython (current state) there are three modes of text completion:

a) Abbreviations plugin: Based on of SciTes Abbreviations with a abbreviation file acting as template.

b) FindAndComplete: Suggests an word already available in the open file. This could also be called "AutoComplete".

lisa fan franz fred

typing f open code completion: suggests: fan franz fred

typing fr suggests: franz fred

c) Plugin Code Completition

Comparison between some editors

(which I prefer, because they are written in python/wxpython apart from SciTE, because it is nice for python editing too):

criteria: import module before: example: in editing code, there must be import wx before, before you get wx. code completions.

sorted case sensitive: is the list sorted case sensitive (better in my opinion, if it is not)

Speed

triggered by key '.' (this is very comfortable)

list seems to be complete

leave codecompletion open after false typing (char not fit)

close codecompletion after backspace when reaching first char

typing case sensitive (I prefer no case sensivity)

completition with: (should be standard enter and tab)

variable completition: you type btn=wx.Button => next line btn. <here you should get code completion)

optimal would be also supporting self variables

style: normal (would be nice to have icons for variables and methods; also bold for not inhereted members)

None of them distinguishes (as in Visual Assist for Visual Studio) between direct in the class created constants/variables/procedures and derived

(inherited from base classes) ones.

All is tested on Win XP, Python 2.4, wxPython 2.6

Stanis editor Spe

Version: 0.7.2.c

import module before: no

sorted case sensitive: yes

Speed (until pop up appear): normal

triggered by key '.'

list seems to be complete: yes

leave codecompletion open after false typing (char not fit): no

close codecompletion after backspace when reaching first char: yes

typing case sensitive: yes (buggy)

completition with: enter and tab key

variable completition: no

style: normal

Remark: seems little buggy os.O_ (underscore is in here os.O_APPEND, all the same, it is closed after typing '_') good: recognizing the type of "self"!!

Pycrust respectively PyShell

import module before: yes

sorted case sensitive: no

Speed (until pop up appear): fast

triggered by key '.'

list seems to be complete: yes

false typing (char not fit): close codecompletion

leave codecompletion open after false typing (char not fit): yes

close codecompletion after backspace when reaching first char: yes

typing case sensitive: no

completition with: enter and tab key

variable completition: yes

style: normal

Remark: I have the impression, it is very fast sometimes, it tolerates false typing, sometimes not (?) Autocompletion adjustable:

DrPython's Code Completion plugin

Version: DrPython 3.10.13, Code Completition 0.2.1

import module before: no

sorted case sensitive: yes

Speed (until pop up appear): normal

triggered by key '.': yes

list seems to be complete: yes

leave codecompletion open after false typing (char not fit): no

close codecompletion after backspace when reaching first char: no

case sensitive typing: yes

completition with: enter and tab key

variable completition: yes

style: normal

Remark: enable/disable autocomplete with hotkey Also there is an option: enable CodeCompletion by default. wx. it shows also wx. in the listbox

Boa Constructor

Version 0.4.3:

(thanks Werner F. Bruhin for help)

import module before: yes

sorted case sensitive: no

Speed (until pop up appear): fast

triggered by key '.': no CTRL-space

list seems to be complete: yes

false typing (char not fit): no, you can backspace, correct etc

leave codecompletion open after false typing (char not fit): yes

close codecompletion after backspace when reaching first char: no

typing case sensitive: no

completition with: enter and tab key

variable completition: yes, event with self. you get code completition

style: normal

Remark: interesting Browse to source, code transformation (sounds interesting; what is it?)

disregarded now; it seems there are some bugs in this version)

completion of self variables!

SciTE

Version: 1.61

import module before: no

sorted case sensitive: no

Speed (until pop up appear): fast

triggered by key '.'

list seems to be complete: no

leave codecompletion open after false typing (char not fit): no

close codecompletion after backspace when reaching first char: no

typing case sensitive: no

completition with: enter and tab key

variable completition: no

style: normal

Remark: not really code completition in that sense, there is a file gen_python_api.py to generate code completition.

import: shows also os.path.basename, ...

SciTe does "manual" code completition with ctrl-i or ctrl-space)

Additional thoughts, for what I think, good Code Completion is

sorted case sensitive: (no) => option

Speed (annoying to wait until the listbox appears)

case sensitive sort (off) make it an option

case sensitive typing: no

distinguish between direct members/variables (bold style, icons) and from base class

hide "internal" function, which begins with (on) make it an option (display somewhere "filtered" or similar

tolerant to false typing (should not close listbox) this could be an option

launch it with typing '.' and with a hotkey (you have not to press backspace until 'wx.')

Calltips and Editors

Other people call it Intellisense.

taken init string or class description or both (option)

What string:

tested: wx.Frame, os.path.basename

=== Stanis editor Spe == wx.Frame: Proxy of C++ Frame Class (Press ESC to close) (takes class docstring)

os.path.basename: (p) Returns the final document of a pathname (Press ESC to close)

Remark: Calltips adjustable:

nice background colour

Pycrust respectively PyShell

wx.Frame: (inserts init doc string)

os.path.basename:

Remark:

Option Show Calltips

DrPython's Code Completion plugin

wx.Frame: Proxy of C++ Frame Class (takes class docstring)

os.path.basename: Returns the final document of a pathname

Remark: I don't like the intensive yellow field; rather light yellow from Pycrust

If Code completions is turned off, no calltips appear (own calltips switch(?))

Boa

wx.Frame: (inserts init doc string)

os.path.basename:

Remark:

SciTE

wx.Frame: no Calltips

os.path.basename: os.path.basename(??) [doc: Returns the final document of a pathname]

Remark: -

What I think, good Call Tips are

Esc should close them, also when hitting ')', after return, or when focus of editor is lost or window change, cursor keys.

Fast disable/enable them (pycrust); option enable by default yes/no

Key to insert the actual calltips into the current cursor position (only the first line?) (tab key?)

Pycrust has good Calltips.

Should open, when tpying '(' and open with a hotkey.

Should show the init docstring (like pycrust) and maybe the class docstring extra, or about

base class would be also interesting.

class docstring


init docstring

example wx.Frame:

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

class Frame(TopLevelWindow): """Proxy of C++ Frame class"""


(self, Window parent, int id=-1, String title=EmptyString,

-> Frame

If there are some expression/grammatical errors (I'm no native english speaker),

then please feel free to correct them.

thanks.

AutoCompletion (last edited 2008-03-11 10:50:36 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.