Tab completion in Python3.4

S

Steven D'Aprano

By default, Python 3.4 will ship with tab completion turned on. When you
hit the tab key, Python will try to complete the current function,
method, variable or other name, if necessary displaying the alternatives
is there are more than one:


py> d = {}
py> d.pop
d.pop( d.popitem(


This is a great feature, and very welcome to become on by default. Many
thanks to Antoine Pitrou for finally making this happen! I've been using
tab completion using a custom startup file for a few years, and of course
anyone familiar with the common Linux shells will also be familiar with
it.

But there is one sting in the tail: the current 3.4 implementation makes
it impossible to use the tab key to indent code. Pressing TAB at the
start of the line tries to complete on *everything*, instead of indenting:


py> for x in range(3):
....
Display all 195 possibilities? (y or n)


This is a problem: it means you either have to indent using multiple
spaces, which is a pain, or a single space, which is ugly and hard to
read:

py> for x in range(3):
.... print(x)
....
0
1
2


I don't consider either of these solutions to be satisfactory. If you
agree, I urge you to try it out for yourself, and then leave a comment on
the bug tracker asking for tab completion to still insert tabs at the
beginning of the line:

http://bugs.python.org/issue5845



For anyone wanting to see my version of tab completion and history:

https://code.google.com/p/my-startup-file/source/browse/completer.py
https://code.google.com/p/my-startup-file/source/browse/history.py


Usage is simple: in my startup file, or just do it manually:

try:
import history
except ImportError:
print('*** warning: command line history not available ***')
else:
history = history.History()

try:
import completer
except ImportError:
print('*** warning: command line completion not available ***')
else:
completer = completer.Completer(
bindings=(r'"\C-xo": overwrite-mode',
r'"\C-xd": dump-functions',
)
)
 
A

Antoine Pitrou

Steven D'Aprano said:
I don't consider either of these solutions to be satisfactory. If you
agree, I urge you to try it out for yourself, and then leave a comment on
the bug tracker asking for tab completion to still insert tabs at the
beginning of the line:

Such a change is much more likely to happen if someone actually proposes
a patch for it, rather than merely "ask for it". I don't think anyone is
ideologically opposed to it.

Regards

Antoine.
 
S

Steven D'Aprano

Such a change is much more likely to happen if someone actually proposes
a patch for it, rather than merely "ask for it". I don't think anyone is
ideologically opposed to it.

I thought you were and am glad to hear you aren't :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top