Base of an as you type completer. #1039

Merged
merged 7 commits into from Nov 30, 2011

Projects

None yet

3 participants

@Carreau
IPython member

when invoking the completer, instead of having to chose/dismiss, you can
continue typing, it will filter the result "as you type" and dismiss itself
if ther is no match left.

As it is now, it's only works with lowercase letters, I need to find a workaroud
for this.

for example
if you type :

* P-y-<tab>-S-o-m-e-t-h-i-n-g
* it will propose PySide, but will dismiss when 'o' is pressed and pasting Pyso with a lower case 's'

I've rebase and squash everything (the code was quite old), so not sure if it perfectly works with the tooltip merged of a few hours ago ... and there are still edge case annoying for a merged on master

@fperez
IPython member

It looks good already, thanks! One usability note: if you could also fix a couple of annoyances of the nb completer compared to readline:

  • once there's only one completion, hitting <tab> should finish up the compleiton immediately. Right now, if the filtering has brought the list down to one item, you first have to hit tab once to dismiss it, and then again to finish the completion. It should dismiss and complete with a single <tab>.

  • indeed it gets confused with uppercase letters. Try for example plt.<tab> and then type 'ci'. It will offer Circle with uppercase C, which then doesn't actually complete. It should match exactly the casing of what has been typed so far.

  • the first completion should also write as many letters as are unique up to the new stuff. For example, if you do plt.au<tab> (with plt == matplotlib.pyplot), then all the completions start with 'aut'. In the terminal, the 't' is automatically added and then the completions are shown. Here you must manually type the 't'. We really should match how readline works here, which is the right way to do it.

Thanks again for the good work!

@Carreau
IPython member

Thank you for your review, i've already think of most of thoses cases plus some more.
I would have changed your third point to a 'triggerd on tab' only, but once it done it shouldn't be to hard to change the behaviour

For lowercase, it's half by choice. I'm using charfromCode(event.which) which alway give me upper case :-(
I'll have to split the logic because keydown event doesn't reflect wether the typed letter is upper or lower case. I feel that having both keydown and keypress event will make lots of edge case...

I also sugest finding some sort of library which already register the value of each keypress/keydown to a more readable api, like key.tab or key.esc I know you already have event.which but i'm starting to be lost in my own handeling of the keycodes

So it's start to grow complex, and I was wondering if splitting it into another file is worth.

@fperez
IPython member
Carreau added some commits Nov 24, 2011
@Carreau Carreau Base of an as you type conpleter.
	when invoking the completer, instead of having to chose/dismiss, you can
	continue typing, it will filter the result "as you type" and dismiss itself
	if ther is no match left.

	As it is now, it's only works with lowercase letters, I need to find a workaroud
	for this.

	for example
	if you type :
	* P-y-<tab>-S-o-m-e-t-h-i-n-g
	* it will propose PySide, but will dismiss when 'o' is pressed and pasting Pyso with a lower case 's'
6b2d9cc
@Carreau Carreau protect shift extend on Uppercase 0492e42
@Carreau Carreau Handle lower and uppercase e65ec88
@Carreau
IPython member

Rebased on master, handle upper and lowercase.

Perhaps there's another call that would provide the exact character?

@fperez
Yes, it was keypress (instead of keydown)... but keypress is silent for shift, ctrl, tab..etc.
I wrote a function which is called by both keypress and keydown and filter afterward. seem to do the trick.

I'll try to mimic readline so that tab 'fast forward' the completion and clean the code after.

@fperez
IPython member

OK, this is looking great. Once you finish implementing support for tab fully completing when there's only one selection left and clean it up, let me know and we'll merge it. Excellent work, thanks!

@Carreau
IPython member

Now <tab> when the completer is already present update until the common prefix of all the availlable completion.

@fperez
IPython member

much better! Last request: once the list has filtered down to only one option, should simply do the completion. For example, in this sequence: (with --pylab):

1. plt.a<tab>
2. type n
3. the only option left is 'annotate'.
4. at this point, one more <tab> should finish the completion.  

Instead, I have to hit enter, which is acceptable but different from readline, so it causes confusion to people whose muscle memory is used to having tab finish the completion when there's only one option left.

With that fixed, we should be able to merge. Thanks!

Carreau added some commits Nov 29, 2011
@Carreau Carreau tab pick if only one match left 938981c
@Carreau Carreau tidy up code 850c994
@Carreau Carreau fix double tooltip
	there was a possibility of 2 tooltip if clicking in two cell
	and one that it wasn't able to dismiss
f1f0856
@Carreau
IPython member

@fperez,
you can try now. As you type 'Completion caracter' are specified in a list so I have added letters and underscore to it for now, and I dont see what else could be part of a function name or object to complete... do you see some other 'caracters' to add ?

This also have a fix for some case when 2 tooltips could appear...
good night.

@fperez
IPython member

This is awesome, usability-wise. Merging now, great work!

@fperez fperez merged commit b44cdc3 into ipython:master Nov 30, 2011
@syed

Is this possible in the CLI/Qt console too. I really like bpython's completion-as-you-type

@fperez
IPython member

It's possible in the qt one, not in the text one because there's no event loop in the text console (or rather, there are only two events: 'return' and 'tab', but individual keystrokes don't produce events).

@fperez
IPython member

... but obviously it would need to be also implemented in the qt console, it's not automatic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment