Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93023 > unrolled thread

How do I get the currently installed tab completion function?

Started bySteven D'Aprano <steve@pearwood.info>
First post2015-06-23 11:02 +1000
Last post2015-06-23 12:32 +1000
Articles 5 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How do I get the currently installed tab completion function? Steven D'Aprano <steve@pearwood.info> - 2015-06-23 11:02 +1000
    Re: How do I get the currently installed tab completion function? Chris Angelico <rosuav@gmail.com> - 2015-06-23 11:23 +1000
      Re: How do I get the currently installed tab completion function? Steven D'Aprano <steve@pearwood.info> - 2015-06-23 11:41 +1000
        Re: How do I get the currently installed tab completion function? Chris Angelico <rosuav@gmail.com> - 2015-06-23 12:02 +1000
          Re: How do I get the currently installed tab completion function? Steven D'Aprano <steve@pearwood.info> - 2015-06-23 12:32 +1000

#93023 — How do I get the currently installed tab completion function?

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-23 11:02 +1000
SubjectHow do I get the currently installed tab completion function?
Message-ID<5588b01b$0$1649$c3e8da3$5496439d@news.astraweb.com>
I have two (or more) different types of tab completion, and I want one to
apply under certain circumstances, and the other to apply at others. For
example, let's say I want one to apply inside a function which uses
raw_input (or input in Python 3), and the other to apply the rest of the
time.

So I might use this:

def getfilename():
    prev = get_the_current_completer()  # <<--- this
    readline.set_completer(filename_completer)
    try:
        return raw_input("What file do you want? ")
    finally:
        readline.set_completer(prev)


Is that the best (only) way?

How do I get the currently installed completer?

Solutions for any version of Python acceptable, but if they work all the way
back to 2.4 or older, even better.



-- 
Steven

[toc] | [next] | [standalone]


#93024

FromChris Angelico <rosuav@gmail.com>
Date2015-06-23 11:23 +1000
Message-ID<mailman.716.1435022639.13271.python-list@python.org>
In reply to#93023
On Tue, Jun 23, 2015 at 11:02 AM, Steven D'Aprano <steve@pearwood.info> wrote:
> How do I get the currently installed completer?
>
> Solutions for any version of Python acceptable, but if they work all the way
> back to 2.4 or older, even better.

Whether there's a way to avoid the whole try/finally I can't say, but
I just went looking for the obvious "readline.get_completer()", and it
does seem to be there. Is there something I'm missing here?

Found it on 3.4, 3.5, 3.6, and 2.7, but I don't have anything older to test on.

ChrisA

[toc] | [prev] | [next] | [standalone]


#93026

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-23 11:41 +1000
Message-ID<5588b957$0$1664$c3e8da3$5496439d@news.astraweb.com>
In reply to#93024
On Tue, 23 Jun 2015 11:23 am, Chris Angelico wrote:

> On Tue, Jun 23, 2015 at 11:02 AM, Steven D'Aprano <steve@pearwood.info>
> wrote:
>> How do I get the currently installed completer?
>>
>> Solutions for any version of Python acceptable, but if they work all the
>> way back to 2.4 or older, even better.
> 
> Whether there's a way to avoid the whole try/finally I can't say, but
> I just went looking for the obvious "readline.get_completer()", and it
> does seem to be there. Is there something I'm missing here?

No, but there's obviously something *I'm* missing.

I don't know how I missed that :-(

It's especially embarrassing because it is available all the way back to
version 2.4, which is exactly what I need.


Sorry for the noise.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#93027

FromChris Angelico <rosuav@gmail.com>
Date2015-06-23 12:02 +1000
Message-ID<mailman.717.1435024955.13271.python-list@python.org>
In reply to#93026
On Tue, Jun 23, 2015 at 11:41 AM, Steven D'Aprano <steve@pearwood.info> wrote:
> On Tue, 23 Jun 2015 11:23 am, Chris Angelico wrote:
>
>> On Tue, Jun 23, 2015 at 11:02 AM, Steven D'Aprano <steve@pearwood.info>
>> wrote:
>>> How do I get the currently installed completer?
>>>
>>> Solutions for any version of Python acceptable, but if they work all the
>>> way back to 2.4 or older, even better.
>>
>> Whether there's a way to avoid the whole try/finally I can't say, but
>> I just went looking for the obvious "readline.get_completer()", and it
>> does seem to be there. Is there something I'm missing here?
>
> No, but there's obviously something *I'm* missing.
>
> I don't know how I missed that :-(
>
> It's especially embarrassing because it is available all the way back to
> version 2.4, which is exactly what I need.
>
>
> Sorry for the noise.

That's still only the lesser option, of course. Better would be a way
to say raw_input("prompt? ", completer=filename_completer) but that's
not an option, so it'd have to be an explicit readline.something()
call. I can't find any way to actually ask the readline module to read
a line, though, but given that my experience with that module is
effectively zip, someone else may well be able to offer a superior
suggestion.

ChrisA

[toc] | [prev] | [next] | [standalone]


#93028

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-23 12:32 +1000
Message-ID<5588c536$0$1668$c3e8da3$5496439d@news.astraweb.com>
In reply to#93027
On Tue, 23 Jun 2015 12:02 pm, Chris Angelico wrote:

> On Tue, Jun 23, 2015 at 11:41 AM, Steven D'Aprano <steve@pearwood.info>
> wrote:
>> On Tue, 23 Jun 2015 11:23 am, Chris Angelico wrote:
>>
>>> On Tue, Jun 23, 2015 at 11:02 AM, Steven D'Aprano <steve@pearwood.info>
>>> wrote:
>>>> How do I get the currently installed completer?
>>>>
>>>> Solutions for any version of Python acceptable, but if they work all
>>>> the way back to 2.4 or older, even better.
>>>
>>> Whether there's a way to avoid the whole try/finally I can't say, but
>>> I just went looking for the obvious "readline.get_completer()", and it
>>> does seem to be there. Is there something I'm missing here?
>>
>> No, but there's obviously something *I'm* missing.
>>
>> I don't know how I missed that :-(
>>
>> It's especially embarrassing because it is available all the way back to
>> version 2.4, which is exactly what I need.
>>
>>
>> Sorry for the noise.
> 
> That's still only the lesser option, of course. Better would be a way
> to say raw_input("prompt? ", completer=filename_completer) but that's
> not an option, so it'd have to be an explicit readline.something()
> call. I can't find any way to actually ask the readline module to read
> a line, though, but given that my experience with that module is
> effectively zip, someone else may well be able to offer a superior
> suggestion.

The point is to have the completion available while the user types at the
prompt, not to apply it afterwards. So you have to install it as a
completer function under readline.




-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web