New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[qtconsole] take %,%% prefix into account for completion #1944
Conversation
I'm busy today, but if anyone can review and test this, it would be great. This is an important fix to get in for 0.13, so it would be better to have it before the first beta (which I'm delaying to give @ellisonbg some time to review some NB stuff) |
I've run it and verified that it fixes the bug. |
Great, go for it then. It's an important one; I have to run now. |
prefix = u'%' | ||
if prefix : | ||
prefix_filter = lambda x: u"".join(x.split(u'%', 2)) | ||
items = map(prefix_filter, items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there ought to be a neater way to do this. How about [s.lstrip('%') for s in items]
. Admittedly that would remove any number of leading %
, but if we ever do have something with 3, that's probably the behaviour we want anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do lstrip(ESC_MAGIC)
elsewhere in inspection, so this should be fine.
Doing it in the kernel would require an addition to the messaging protocol. If we think that's the right way to do it, I think we should apply this quick fix for 0.13, give or take some small tweaks, and revisit it after the release. I'm happy that it works with the code we have today, and I don't think we want to start refactoring completion code just now. |
I thing that i can extract the prefixes, reverse them, and find the common sufixes of the prefix,that should be doable. |
Not sure I follow that ;-) |
Forced push to have only one commit, should take into account any prefix made of #!$...
Sure you'll understand while reading the code (just because os.path.commonsuffix does not exist) |
I did understand the code...eventually ;-) I'm pretty sure there should be a more readable solution. It might involve a regex. |
I think I'm going to keep this quote for a long time. |
On Wed, Jun 13, 2012 at 2:01 PM, Min RK
+1 |
Yes, it did feel a bit odd typing that. I stand by it, though - regexes have their place. Thinking about this a bit more, I'm not sure that https://github.com/ipython/ipython/blob/master/IPython/frontend/qt/console/ipython_widget.py#L138 |
Absolutely true, and I am a lot more comfortable with them now than I used to be. Still an amusing statement. |
IPython console : typed >>> ti<tab>
compl >>> ti # I would expect time....
%%timeit %time %timeit IPython qtonsole (myfix): typed >>> ti<tab>
compl >>> %time # got a leading %
%%timeit %time %timeit In[1] >>> import time
typed >>> ti<tab>
compl >>> time
%%timeit %time %timeit time At least for me... so IMHO, the current solution is not a the level of what users would expect. It does not transform the prompt to And I'll let you try with regex :-) |
We don't have to achieve everything the user could expect - tab completion is a complex thing, and there will be time to improve it later. What's important is that it shouldn't remove what you've typed without a good reason. I'll have a play with it later and see what I can come up with. |
Sorry, my memory is faulty, I though that at 0.12 milestone, after importing So please consider this PR as both a fix and a proposal for enhancement that could eventually be brought to other frontend. I just want to point out that it is the behaviour of the current notebook completer, but for the sake of consistency between frontend, I would accept to remove tis 'feature' also from the notebook if you think it is necessary. |
I don't think consistency between frontends is a big concern right now |
I haven't quite followed this review, so is this one ready for merge now? |
@takluyver wrote :
I think Thomas want go try with regular expressions. |
Sorry, I forgot about it. I'll have a look now and see if I can come up with something cleaner. |
(Refer to #1972) |
Focussing on this one again: I think if we take the regex from #1972, we can separate prefixes and items more easily:
That saves us the think-through-this-carefully lambda to get prefixes. I think the common-suffix line is the best way of doing what it does. |
Also, let's make the docstring a bit clearer. Something like: "Return the longest common prefix of a list of strings, but with special treatment of escape characters that might precede commands in IPython, such as %magic functions. Used in tab completion. For a more general function, see os.path.commonprefix" |
lstrip is much faster on a few test, i'll keep it |
Ok, done with regular expression. |
OK, this is looking OK to me, and I've just done a quick manual test. I'm happy for you to merge this when you're ready. |
Merging then. |
[qtconsole] take %,%% prefix into account for completion
[qtconsole] take %,%% prefix into account for completion
fixes #1767