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 14:31:18 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 2/28/20 11:39 AM, Chet Ramey wrote:
> 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.

I should mention here that if you only want to use single or double quotes
to quote your completions, there is much less work to do.

You can get away with just setting up your word break and quoting
characters, and readline will recognize unclosed quoted strings, perform
completion on the quoted portion, and take care of adding the closing
quote.

That's the common case. But if you want to use backslashes in addition to
those quote characters, you do have to do most of that work yourself.

-- 
``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]