bug-readline
[Top][All Lists]
Advanced

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

Re: [Bug-readline] partial word completion


From: Chet Ramey
Subject: Re: [Bug-readline] partial word completion
Date: Mon, 23 Feb 2009 11:13:13 -0500
User-agent: Thunderbird 2.0.0.19 (Macintosh/20081209)

David Fang wrote:
> Hi,
>     (Apologies if this is not appropriate for the bug list but I found
> no other readline mailing list!)
>     I'm trying to perform completion on a *part* of a word like the
> following:
> 
> shell% whatis foo.bar.<TAB>
> 
> by parsing "foo.bar" to determine the context of what could follow,
> I'm successfully able to generate a list of members of foo.bar:
> 
>   xx  yy  zz
> 
> But for completion, readline considers "foo.bar." the entire word, and
> after tab-completing "foo.bar.x", I'm left with only:
> 
> shell% whatis xx
> 
> The prefix was deleted/replaced.

Because the list of completions you supplied to readline didn't include it.
If you remove the prefix, readline assumes you really meant to do that
and no longer considers it as part of the words to be completed.

The standard readline mechanism for multiple completions is an array of
matches, where matches[0] contains the common prefix, and matches[1..n]
contain the possible completions, including the common prefix.  This
allows readline to sort, eliminate duplicates, and so on.

> I would like this to behave similarly to directory completion:
> % cd foo/bar/x<TAB>
> % cd foo/bar/xx
> 
> What additional steps do I need to be able to retain the prefix-portion
> of a word being substituted, and only substitute the tail-portion?

You need to handle the display of possible completions yourself.

The way to do that is to `register' a function to display matches by
assigning its address to rl_completion_display_matches_hook.  That
function receives the list of matches in the form described above, the
number of matches in the list, and the length in characters of the
longest entry.

Your code can manipulate the list of matches to remove the common
prefix, if you'd like, but make sure that you keep any new common prefix
in matches[0].  Readline provides a convenience function to display
the contents of the array, rl_display_match_list(), which you can call
with your modified array and the same two additional arguments your
function received, modified appropriately.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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