zsh-users
 help / color / mirror / code / Atom feed
* Inserting all completions
@ 1999-07-19 18:30 Danek Duvall
  1999-07-19 19:14 ` Larry P. Schrof
  1999-07-19 22:51 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Danek Duvall @ 1999-07-19 18:30 UTC (permalink / raw)
  To: Zsh Users

Is there a simple way to insert all the possible completions into the
current commandline?  Something like list-choices, but have the results
placed into the commandline, rather than having to copy them one-by-one.

I can't find a builtin widget for it, and it's not clear to me how to write
one.

Thanks,
Danek


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Inserting all completions
  1999-07-19 18:30 Inserting all completions Danek Duvall
@ 1999-07-19 19:14 ` Larry P. Schrof
  1999-07-19 22:51 ` Bart Schaefer
  1 sibling, 0 replies; 6+ messages in thread
From: Larry P. Schrof @ 1999-07-19 19:14 UTC (permalink / raw)
  To: Zsh Users

I would venture to guess that other expansion mechanisms in the shell
may suit your purpose in some cases. (For example, you can store
values in an array, and have those substituted on the command line.)
There's filename expansion too, of course. It's been awhile since I
looked at the man page, but I think you can even view and set shell
options based on pattern matching. You can view aliases with pattern
matching.

Essentially, I'm saying that if you simply want all possible
completions returned, there are (often, not always) other shell
mechanisms to perform this for you.

Hope this helps (a little).

- Larry

On Mon, Jul 19, 1999 at 11:30:13AM -0700, Danek Duvall wrote:
> Is there a simple way to insert all the possible completions into the
> current commandline?  Something like list-choices, but have the results
> placed into the commandline, rather than having to copy them one-by-one.
> 
> I can't find a builtin widget for it, and it's not clear to me how to write
> one.
> 
> Thanks,
> Danek


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Inserting all completions
  1999-07-19 18:30 Inserting all completions Danek Duvall
  1999-07-19 19:14 ` Larry P. Schrof
@ 1999-07-19 22:51 ` Bart Schaefer
  1999-07-19 23:03   ` Danek Duvall
  1 sibling, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 1999-07-19 22:51 UTC (permalink / raw)
  To: Danek Duvall, Zsh Users

On Jul 19, 11:30am, Danek Duvall wrote:
> Subject: Inserting all completions
> Is there a simple way to insert all the possible completions into the
> current commandline?

In the new 3.1.6 completion system, you can use

	compadd -A the_matches ...
	compadd -UQ "$the_matches"

That is, replace the current word (-U) with a single match consisting of
all strings to be inserted, but don't quote (-Q) the spaces between them.
Replace `...' above with the list of potential matches to which compadd
should compare the current word on the command line; those that actually
do match will be placed in $the_matches, quoted and ready for insertion.

Here's a trivial example of actually using this; it assumes you've run
"compinit" or otherwise installed the function-based completion system:

 function _all () {
  local -a the_matches
  compadd -A the_matches one two three four twenty thirty forty "fifty six"
  compadd -UQ "$the_matches"
 }
 compdef _all print

Now if you type

 print -l f<TAB>

you should see

 print -l four forty fifty\ six


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Inserting all completions
  1999-07-19 22:51 ` Bart Schaefer
@ 1999-07-19 23:03   ` Danek Duvall
  1999-07-19 23:59     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Danek Duvall @ 1999-07-19 23:03 UTC (permalink / raw)
  To: Zsh Users

On Mon, Jul 19, 1999 at 10:51:36PM +0000, Bart Schaefer wrote:

> On Jul 19, 11:30am, Danek Duvall wrote:
>
> > Is there a simple way to insert all the possible completions into the
> > current commandline?
> 
> In the new 3.1.6 completion system, you can use
> 
> 	compadd -A the_matches ...
> 	compadd -UQ "$the_matches"
> 
> [ Explanation snipped ]

Hmmm, okay ... I don't want to replace completion with this entirely.  I'd
like to have two keystrokes -- one, tab, is the normal completion
mechanism.  The second, ^X^I or something, puts all the matches on the
line.

Could I do something like:

function _widget() {
  function_to_compute_reply
  local -a the_matches
  compadd -A the_matches $reply
  compadd -UQ "$the_matches"
}

zle -N _widget
bindkey "^X^I" _widget

(I haven't yet migrated to the new completion stuff, so forgive me if I'm
stomping all over the normal usage of compadd ... ;)

The question then is, how to write function_to_compute_reply() in a
suitably generic manner ...

Thanks,
Danek


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Inserting all completions
  1999-07-19 23:03   ` Danek Duvall
@ 1999-07-19 23:59     ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 1999-07-19 23:59 UTC (permalink / raw)
  To: Danek Duvall, Zsh Users

On Jul 19,  4:03pm, Danek Duvall wrote:
> 
> Hmmm, okay ... I don't want to replace completion with this entirely.  I'd
> like to have two keystrokes -- one, tab, is the normal completion
> mechanism.  The second, ^X^I or something, puts all the matches on the
> line.

Just change the "compdef" in my previous example to:

  compdef -k _all expand-or-complete '^X^I'

This creates a binding that acts like expand-or-complete but that calls
the function _all to generate the matches.

> The question then is, how to write function_to_compute_reply() in a
> suitably generic manner ...

Hmm.  The existing Completions/*/* functions would be ideal for this, if
there were some way to refer to "all the matches that have already been
added by some other completer."  Unfortunately I've forgotten whether
there is, and I can't find anything about it in the docs ... Sven?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Inserting all completions
@ 1999-07-20  7:53 Sven Wischnowsky
  0 siblings, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 1999-07-20  7:53 UTC (permalink / raw)
  To: zsh-users


Bart Schaefer wrote:

> On Jul 19,  4:03pm, Danek Duvall wrote:
> > 
> > Hmmm, okay ... I don't want to replace completion with this entirely.  I'd
> > like to have two keystrokes -- one, tab, is the normal completion
> > mechanism.  The second, ^X^I or something, puts all the matches on the
> > line.
> 
> Just change the "compdef" in my previous example to:
> 
>   compdef -k _all expand-or-complete '^X^I'
> 
> This creates a binding that acts like expand-or-complete but that calls
> the function _all to generate the matches.
> 
> > The question then is, how to write function_to_compute_reply() in a
> > suitably generic manner ...
> 
> Hmm.  The existing Completions/*/* functions would be ideal for this, if
> there were some way to refer to "all the matches that have already been
> added by some other completer."  Unfortunately I've forgotten whether
> there is, and I can't find anything about it in the docs ... Sven?

I hadn't thought about this use, but I once suggested a way to access
the data for the matches already added.

Hm, I see two possibilities:

1) a way to get at the strings for the matches added
2) some more magic with compstate[insert]

Unfortunately 1) is not trivial:

- we really have the information about the matches only *after* the
  completion widget finished, because then the code that sorts the
  matches and eliminates duplicates is run; changing that would make
  adding matches much more expensive (checking for duplicates after
  each added match)
- the completion-inside-braces-problem: if we have a{b<TAB>, the
  matches are abx, aby, and so on and only the match-insertion code
  really knows where to re-insert the brace(s) correctly

Because of these two problems I haven't implemented something like
that yet.

The 2) is something I only thought about now. That wouldn't be too
hard, I think. We could make compstate[insert] accept a comma-
separated list of ranges or something like that (a la cut), e.g.:
`compstate[insert]=1-' would insert all matches, and something like
`compstate[insert]=1,3,5-10' would insert the first, third, and
fifth-to-tenth match (in that order).

We could also try to combine 1) and 2), i.e. a way to get at the
match-strings plus `compstate[insert]="($foo $bar)"' -- but that
wouldn't work with the braces-stuff.

Comments? Opinions?

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-07-20  7:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-19 18:30 Inserting all completions Danek Duvall
1999-07-19 19:14 ` Larry P. Schrof
1999-07-19 22:51 ` Bart Schaefer
1999-07-19 23:03   ` Danek Duvall
1999-07-19 23:59     ` Bart Schaefer
1999-07-20  7:53 Sven Wischnowsky

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).