bug-readline
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Completions which contain spaces don't work by as expected.


From: Chet Ramey
Subject: Re: Completions which contain spaces don't work by as expected.
Date: Fri, 28 Feb 2020 11:39:52 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 2/20/20 2:40 PM, John Darrington wrote:
> On Thu, Feb 20, 2020 at 02:19:50PM -0500, Chet Ramey wrote:
>      On 2/20/20 2:00 PM, John Darrington wrote:
>      > I have a custom completer which provides a largish number of possible
>      > strings such as:
>      > 
>      > "Arrays"
>      > "Array Instances"
>      > "Array Literals"
>      > "Array Deletion"
>      > "Binary"
>      > "Loops"
>      > ...
>      > 
>      > When completing single words everything is fine.
>      
>      Are you doing this with bash or some other program that uses readline?
>      My guess is the latter.
>      
> Yes - the latter.
> 
> A program of my own creation, which uses a custom completer registered
> with  
>   rl_completion_entry_function = my_function

Well, you have to do two things: figure out how you want to quote the
spaces, since space is a readline completion word break character, and
how you want readline to treat the results that need quoting. You want
the two things to be compatible, so you can handle any readline-generated
quoting (but see below for your application's quoting function).

Readline uses hook functions and variables to set the quoting parameters.
You can change the set of word break characters by modifying
rl_completer_word_break_characters (this is generally the most application-
specific thing), and tell readline to pay attention to quoted strings by
setting rl_completer_quote_characters. If you decide that the characters in
rl_basic_quote_characters are good enough, you don't have to do anything
but set

rl_completer_quote_characters = rl_basic_quote_characters;

but you probably want something more custom.

That buys you most of readline's internal quote recognition. You have to
do a little more work if you want to use backslash as a quoting mechanism.

>From there, you have a couple of ways to go. You probably want to remove
backslash from the word break characters if you want it to act as a
quoting character.

You can always check rl_point from within your quoting function and do
all the work yourself, or set rl_attmpted_completion_function to get a
crack at completing before the completion entry function is called.

If you set rl_completer_quote_characters, you can call a hook function you
assign to rl_char_is_quoted_p to tell whether or not a particular character
is to be quoted, and the readline completion code will call it while trying
to find the boundaries of the word to be completed. It should handle
whatever quoting mechanism you decide. If you want to allow backslashes to
quote word breaks, then write a function  that determines whether a
particular word break character at rl_line_buffer[rl_point] is preceded by
an odd number of backslashes.

Once you do that, readline will pass your completion function something
like "Array\ Inst" if that is exactly what is in the readline line
buffer. You need to dequote it, perform the match, and return any possible
completions. You can have readline quote the results by setting

rl_filename_quoting_desired = 1;

and setting rl_filename_quoting_function to the address of a function you
provide that performs the quoting.

It's a lot of available mechanism, and very little policy.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]