[IPython-dev] function specific tab completion via annotations

Brian Granger ellisonbg@gmail....
Sat Dec 29 14:14:28 CST 2012


We could do the (?.  What about shift-tab?  Would that be too
difficult to manage with all the other meanings of tab?

On Tue, Dec 18, 2012 at 11:41 PM, Matthias Bussonnier
<bussonniermatthias@gmail.com> wrote:
> We could detect (? It is no valid python and seems appropriate
>
> ITOH tooltip can also give info on non callable. One can trigger tooltip
> onlt after ?<tab> and remove the ? To allow fast typing.
>
> Le 19 déc. 2012 00:05, "Brian Granger" <ellisonbg@gmail.com> a écrit :
>
>> I think we want both the tab completion and tooltip to work at the
>> same time = not be mutually exclusive.  I think we should preserve TAB
>> for the completion logic and move tooltip to something else to be
>> consistent.  This new tab completion logic is really important.  Let's
>> brain storm about ways of allowing both to coexist.
>>
>> On Tue, Dec 18, 2012 at 2:03 AM, Matthias BUSSONNIER
>> <bussonniermatthias@gmail.com> wrote:
>> >
>> > Le 18 déc. 2012 à 10:52, Robert McGibbon a écrit :
>> >
>> > Matthias,
>> >
>> > Good call. That's it exactly. Unfortunately, I think dealing with this
>> > issue
>> > is a little above my expertise/experience.
>> >
>> > When I apply this patch (pasted below) to the PR, the tab completions
>> > show
>> > in the notebook for foo(<TAB>.
>> >
>> > The problem is that behavior kind of conflicts with the tooltip feature,
>> > which is not a feature of the terminal console.
>> >
>> >
>> > without your patch,
>> > You could set
>> > this.tooltip_on_tab = true;
>> > L25 in codecell.js to false.
>> > It will trigger the tooltip only if you stay after a opening bracket for
>> > a
>> > certain amount of time.
>> > The the completer should work as expected.
>> >
>> > It should be made configurable.
>> >
>> > we could try to tweak the behavior so that (<tab> trigger tooltip
>> > ([space]<tab> trigger completion.
>> >
>> > But I guess that's beyond the extend of your PR.
>> > --
>> > Matthias
>> >
>> >
>> >
>> > -Robert
>> >
>> > p.s.
>> >
>> > I think I'm finally starting to see the wisdom of the comment on line
>> > 1046
>> > of IPython/core/complete.py,
>> >
>> >         # FIXME: we should extend our api to return a dict with
>> > completions
>> > for
>> >         # different types of objects.  The rlcomplete() method could
>> > then
>> >         # simply collapse the dict into a list for readline, but we'd
>> > have
>> >         # richer completion semantics in other evironments.
>> >
>> >
>> > $ git diff
>> > diff --git a/IPython/frontend/html/notebook/static/js/codecell.js
>> > b/IPython/frontend/html/notebook/static/js/codecell.js
>> > index ea34719..000734b 100644
>> > --- a/IPython/frontend/html/notebook/static/js/codecell.js
>> > +++ b/IPython/frontend/html/notebook/static/js/codecell.js
>> > @@ -155,6 +155,8 @@ var IPython = (function (IPython) {
>> >                  IPython.tooltip.request(that);
>> >                  // Prevent the event from bubbling up.
>> >                  event.stop();
>> > +                console.log('RTM DEBUG');
>> > +                this.completer.startCompletion();
>> >                  // Prevent CodeMirror from handling the tab.
>> >                  return true;
>> >              } else {
>> > diff --git a/IPython/frontend/html/notebook/static/js/completer.js
>> > b/IPython/frontend/html/notebook/static/js/completer.js
>> > index ac2d95c..94aff4b 100644
>> > --- a/IPython/frontend/html/notebook/static/js/completer.js
>> > +++ b/IPython/frontend/html/notebook/static/js/completer.js
>> > @@ -105,8 +105,9 @@ var IPython = (function (IPython) {
>> >          // we need to check that we are still on a word boundary
>> >          // because while typing the completer is still reinvoking
>> > itself
>> >          if (!/[0-9a-z._/\\:~-]/i.test(pre_cursor)) {
>> > -            this.close();
>> > -            return;
>> > +            //this.close();
>> > +            //return;
>> > +            console.log('RTM DEBUG2');
>> >          }
>> >
>> >          this.autopick = false;
>> >
>> >
>> > On Dec 18, 2012, at 1:17 AM, Matthias Bussonnier wrote:
>> >
>> > Ah... Then it's probably the tooltip code that take over.
>> >
>> > Same folder, codecell.js look for TAB or pre_cursor.
>> >
>> > Completion is not triggerd if char in front of cursor is space or
>> > opening
>> > bracket.
>> >
>> > Short from my phone.
>> >
>> > Le 18 déc. 2012 09:28, "Robert McGibbon" <rmcgibbo@gmail.com> a écrit :
>> >>
>> >> Marrhias
>> >>
>> >> the baz(notevaluated).<TAB> is working in the notebook.
>> >>
>> >> it's the foo(<TAB> that's not working... yet.
>> >>
>> >> my fridge is not out of beer, so i'm still working :)
>> >>
>> >> -Robert
>> >>
>> >> On Dec 18, 2012, at 12:22 AM, Matthias BUSSONNIER wrote:
>> >>
>> >>
>> >> Le 18 déc. 2012 à 09:03, Robert McGibbon a écrit :
>> >>
>> >> It's not working in the notebook with the argument specific
>> >> completions,
>> >> but the return value completion is working. There must be some issue
>> >> with a
>> >> difference in the line splitting with readline and without. I'll track
>> >> it
>> >> down.
>> >>
>> >>
>> >> That's probably the js that removes everything between bracket by
>> >> nothing
>> >> (IIRC, first completer was doing that.)
>> >>
>> >> baz(notevaluated).<tab>
>> >> to
>> >> baz.<tab>
>> >>
>> >> before completion. (or is it tooltip... that does it)
>> >>
>> >> Or a security about 'as you type'
>> >>
>> >> Actually every key press recall the completer once it has been invoked
>> >> and
>> >> it decide to 'kill itself'
>> >> on certain things (like closing bracket, spaces...)
>> >>
>> >> That would be
>> >>
>> >> IPython/frontend/html/notebook/static/js/completer.js ~L 100 smth.
>> >> --
>> >> Matthias
>> >>
>> >>
>> >>
>> >>
>> >> -Robert
>> >>
>> >>
>> >> On Dec 17, 2012, at 11:51 PM, Brian Granger wrote:
>> >>
>> >>
>> >> This looks really great.  Have you tested it with the notebook yet?  I
>> >>
>> >> would imagine that it should already work there as well.
>> >>
>> >>
>> >> On Mon, Dec 17, 2012 at 11:27 PM, Robert McGibbon <rmcgibbo@gmail.com>
>> >> wrote:
>> >>
>> >> Hey,
>> >>
>> >>
>> >> I just posted a new PR for annotation based custom tab completion.
>> >>
>> >> https://github.com/ipython/ipython/pull/2701
>> >>
>> >>
>> >> The code is fairly complex (~1000 new lines), so I assume that there
>> >> are
>> >>
>> >> bugs. For that reason (and because its fun!), I encourage people
>> >>
>> >> to try taking it out for a spin.
>> >>
>> >>
>> >>
>> >> It lets you do things like this:
>> >>
>> >>
>> >> In [1]: from IPython.extensions.completion import tab_complete,
>> >> globs_to,
>> >>
>> >> literal
>> >>
>> >>
>> >> In [2]: @tab_complete
>> >>
>> >> ...: def baz(x) -> str:
>> >>
>> >> ...:     pass
>> >>
>> >> ...:
>> >>
>> >>
>> >> In [3]: baz(notevaluated).<TAB>
>> >>
>> >> .capitalize  .find        .isspace     .partition   .rstrip
>> >> .translate
>> >>
>> >> .center      .format      .istitle     .replace     .split       .upper
>> >>
>> >> .count       .index       .isupper     .rfind       .splitlines  .zfill
>> >>
>> >> .decode      .isalnum     .join        .rindex      .startswith
>> >>
>> >> .encode      .isalpha     .ljust       .rjust       .strip
>> >>
>> >> .endswith    .isdigit     .lower       .rpartition  .swapcase
>> >>
>> >> .expandtabs  .islower     .lstrip      .rsplit      .title
>> >>
>> >>
>> >>
>> >> And this:
>> >>
>> >>
>> >> In [4]: @tab_complete
>> >>
>> >> ...: def foo(x : globs_to('*.txt'), mode : literal('r', 'w')):
>> >>
>> >> ...:     pass
>> >>
>> >> ...:
>> >>
>> >>
>> >> In [5]: foo(<TAB>
>> >>
>> >> 'COPYING.txt'        'dist/'              'setupext/'
>> >>
>> >> 'IPython/'           'docs/'              'tools/'
>> >>
>> >> '__pycache__/'       'ipython.egg-info/'
>> >>
>> >> 'build/'             'scripts/'
>> >>
>> >>
>> >> In[6]: foo('COPYING.txt', <TAB>
>> >>
>> >> 'r', 'w'
>> >>
>> >>
>> >>
>> >>
>> >> -Robert
>> >>
>> >>
>> >> _______________________________________________
>> >>
>> >> IPython-dev mailing list
>> >>
>> >> IPython-dev@scipy.org
>> >>
>> >> http://mail.scipy.org/mailman/listinfo/ipython-dev
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> Brian E. Granger
>> >>
>> >> Cal Poly State University, San Luis Obispo
>> >>
>> >> bgranger@calpoly.edu and ellisonbg@gmail.com
>> >>
>> >> _______________________________________________
>> >>
>> >> IPython-dev mailing list
>> >>
>> >> IPython-dev@scipy.org
>> >>
>> >> http://mail.scipy.org/mailman/listinfo/ipython-dev
>> >>
>> >>
>> >> _______________________________________________
>> >>
>> >> IPython-dev mailing list
>> >>
>> >> IPython-dev@scipy.org
>> >>
>> >> http://mail.scipy.org/mailman/listinfo/ipython-dev
>> >>
>> >>
>> >> _______________________________________________
>> >> IPython-dev mailing list
>> >> IPython-dev@scipy.org
>> >> http://mail.scipy.org/mailman/listinfo/ipython-dev
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> IPython-dev mailing list
>> >> IPython-dev@scipy.org
>> >> http://mail.scipy.org/mailman/listinfo/ipython-dev
>> >>
>> > _______________________________________________
>> > IPython-dev mailing list
>> > IPython-dev@scipy.org
>> > http://mail.scipy.org/mailman/listinfo/ipython-dev
>> >
>> >
>> > _______________________________________________
>> > IPython-dev mailing list
>> > IPython-dev@scipy.org
>> > http://mail.scipy.org/mailman/listinfo/ipython-dev
>> >
>> >
>> >
>> > _______________________________________________
>> > IPython-dev mailing list
>> > IPython-dev@scipy.org
>> > http://mail.scipy.org/mailman/listinfo/ipython-dev
>> >
>>
>>
>>
>> --
>> Brian E. Granger
>> Cal Poly State University, San Luis Obispo
>> bgranger@calpoly.edu and ellisonbg@gmail.com
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev@scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>



-- 
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com


More information about the IPython-dev mailing list