Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Getting completion to tell the user what to do



Bart Schaefer wrote:

> This ought to be an easy one in the new 3.1.6 completion system, but I just
> can't get it to work.
> 
> I'm trying to complete "subject string goes here" as in
> 
> 	mail -s "subject string goes here"
> 
> What I want is to offer no completions at all, because the subject is free-
> form text, but print a hint to the user as to what he's supposed to type.
> 
> The following almost works (inside a completion function the rest of which
> is not interesting):
> 
>   compadd -S '' -X 'Please enter the subject of the message' ''
> 
> but because there's a unique completion, the explanation is printed only
> when the user types ^D, and there's no beep to let him know why tab isn't
> doing anything.  OK, I thought, I can force a listing:
> 
>   compadd -S '' -X 'Please enter the subject of the message' ''
>   compstate[list]=list
>   compstate[force_list]=yes
>   compstate[restore]=no
> 
> but that doesn't work -- there's still no explanation printed.
> 
> What obvious thing have I forgotten/overlooked here?  Is there an entirely
> better alternative to using compadd -X ?

Time for dirty tricks:

  compadd -UX 'Please...' -n ''
  compstate[insert]=''
  compstate[list]=list
  compstate[force_list]=yes

You need the -U because otherwise the empty string never matches
what's on the line (not even the empty string on the line). Then we
can switch of insertion completely.

If you want the string to be listed only on a TAB with an empty string 
you can do `compadd -X "Please..." -n dummy' -- i.e. add a string with 
matching.

The -n, of course, is just to be sure that the matches are not visible.

Is that good enough?

Bye
 Sven


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author