zsh-users
 help / color / mirror / code / Atom feed
* Re: how to customize _all_matches use?
       [not found] ` <20070615202549.MSYR16334.aamtain04-winn.ispmail.ntl.com@a.mx.sunsite.dk>
@ 2007-06-16 17:25   ` Peter Stephenson
  2007-06-16 17:42     ` Peter Stephenson
  2007-06-16 19:05     ` Re[2]: " Vadim Zeitlin
  0 siblings, 2 replies; 5+ messages in thread
From: Peter Stephenson @ 2007-06-16 17:25 UTC (permalink / raw)
  To: zsh-users

Vadim Zeitlin wrote:
>  I'd like to have a key binding which would complete all matches which I
> would get by pressing TAB at once. AFAICS from the manual/user guide, this
> is what the all-matches completer is for and so, following the examples
> there, I tried to do the following:
> 
> 	% zle -C all-matches complete-word _generic
> 	% bindkey '^Xa' all-matches
> 	% zstyle ':completion:all-matches:*' completer _all_matches
> 
> However this doesn't seem to work:
> 
> 	% ls
> 	bar  baz  foo
> 	% ls ^Xa # nothing happens
> 
> I do get the behaviour I want if I do
> 
> 	% zstyle ':completion:all-matches:*' completer _all_matches _complete
> 
> but with one extremely annoying side-effect:
> 
> 	% ls ^Xa
> 	% ls bar baz foo # this is the same line completed by the shell
> 	bar baz foo
> 	bar  baz  foo

The following should fix it:

zstyle ':completion:all-matches:*' insert true

This is mentioned in the manual under the style "insert", but you have
to go hunting and have some idea of what you're looking for (I actually
found it by looking at the completer itself.)  The business about the
completer doesn't seemed to be mentioned at all, but I have the same
experience as you.  It looks like the manual needs to be updated.

>  And, of course, I don't really want to have this behaviour so much for ls
> as for other commands where the completion can't be replaced with just '*'.
> For example, it would be very useful to have for "cvs diff" for which I use
> 
> 	zstyle ':completion::complete:cvs-diff:argument-rest:' \
> 		tag-order existing-files removed-files directories
> 
> so that pressing TAB after "cvs di" normally completes only the modified
> files. But pressing ^Xa also completes the sub-directories -- is there any
> way I could avoid this?

I haven't tried this, but you *should* still be able to use the
tag-order style with all-matches.  The context will be different,
though; as in the styles you quoted it should start
':completion:all-matches:'.  If it's not that obvious or nothing works,
let us know.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: how to customize _all_matches use?
  2007-06-16 17:25   ` how to customize _all_matches use? Peter Stephenson
@ 2007-06-16 17:42     ` Peter Stephenson
  2007-06-16 19:05     ` Re[2]: " Vadim Zeitlin
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2007-06-16 17:42 UTC (permalink / raw)
  To: zsh-users

Here's some deconfusion for the manual.  The additional details will be
relevant to all versions for a long time (certainly 4.2).  I've
confirmed it works with the head of the main line.

Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.200
diff -u -r1.200 compsys.yo
--- Doc/Zsh/compsys.yo	28 May 2007 22:57:40 -0000	1.200
+++ Doc/Zsh/compsys.yo	16 Jun 2007 17:39:01 -0000
@@ -2726,9 +2726,16 @@
 zstyle ':completion:all-matches:*' old-matches only
 zstyle ':completion:all-matches::::' completer _all_matches)
 
-Note that this does not generate completions by itself.  First use
+Note that this does not generate completions by itself:  first use
 any of the standard ways of generating a list of completions,
-then use tt(^Xa) to show all matches.
+then use tt(^Xa) to show all matches.  It is possible instead to
+add a standard completer to the list and request that the
+list of all matches should be directly inserted:
+
+example(zstyle ':completion:all-matches::::' completer _all_matches _complete
+zstyle ':completion:all-matches:*' insert true)
+
+In this case the tt(old-matches) style should not be set.
 )
 findex(_approximate)
 item(tt(_approximate))(

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re[2]: how to customize _all_matches use?
  2007-06-16 17:25   ` how to customize _all_matches use? Peter Stephenson
  2007-06-16 17:42     ` Peter Stephenson
@ 2007-06-16 19:05     ` Vadim Zeitlin
  1 sibling, 0 replies; 5+ messages in thread
From: Vadim Zeitlin @ 2007-06-16 19:05 UTC (permalink / raw)
  To: zsh-users

On Sat, 16 Jun 2007 18:25:58 +0100 Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:

PS> The following should fix it:
PS> 
PS> zstyle ':completion:all-matches:*' insert true

 Thanks a lot Peter! With your hint it does indeed work as [I] expected.

PS> This is mentioned in the manual under the style "insert", but you have
PS> to go hunting and have some idea of what you're looking for (I actually
PS> found it by looking at the completer itself.)  The business about the
PS> completer doesn't seemed to be mentioned at all, but I have the same
PS> experience as you.  It looks like the manual needs to be updated.

 Your patch in the other message indeed makes it much more clear, thanks.

PS> >  And, of course, I don't really want to have this behaviour so much for ls
PS> > as for other commands where the completion can't be replaced with just '*'.
PS> > For example, it would be very useful to have for "cvs diff" for which I use
PS> > 
PS> > 	zstyle ':completion::complete:cvs-diff:argument-rest:' \
PS> > 		tag-order existing-files removed-files directories
PS> > 
PS> > so that pressing TAB after "cvs di" normally completes only the modified
PS> > files. But pressing ^Xa also completes the sub-directories -- is there any
PS> > way I could avoid this?
PS> 
PS> I haven't tried this, but you should still be able to use the
PS> tag-order style with all-matches.  The context will be different,
PS> though; as in the styles you quoted it should start
PS> ':completion:all-matches:'.  If it's not that obvious or nothing works,
PS> let us know.

 It does work if I do

	zstyle ':completion:all-matches:*' tag-order ...

but I still don't know how to limit this for cvs completion only as using
the context of ':completion:all-matches:cvs-commit:*' doesn't work. I
wonder if _complete_help can somehow be used to show the context for
another completer?

 Anyhow, for now I'm quite happy with setting the tag-order globally and
it's very nice to have this available. Thanks once again for your help and
the manual update (and thanks to Bart for explaining why was I getting 2
completion prompts, this was quite mysterious to me so I'm glad to know the
reason now)!
VZ


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

* Re: how to customize _all_matches use?
       [not found] <4672f5ca.216f420a.0ac9.ffffac6fSMTPIN_ADDED@mx.google.com>
@ 2007-06-16 17:14 ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2007-06-16 17:14 UTC (permalink / raw)
  To: zsh-users

On Jun 15, 10:25pm, Vadim Zeitlin wrote:
} 
}  I'd like to have a key binding which would complete all matches which I
} would get by pressing TAB at once.
} 
} 	% zstyle ':completion:all-matches:*' completer _all_matches
} 
} However this doesn't seem to work

There's an important bit in the docs under _all_matches:

     Note that this does not generate completions by itself.  First use
     any of the standard ways of generating a list of completions, then
     use ^Xa to show all matches.

} I do get the behaviour I want if I do
} 
} 	% zstyle ':completion:all-matches:*' completer _all_matches _complete
} 
} but with one extremely annoying side-effect:
} 
} 	% ls ^Xa
} 	% ls bar baz foo # this is the same line completed by the shell
} 	bar baz foo
} 	bar  baz  foo
} 
} i.e. although I do get all the completions I also get *2* lists of them
} below.

Nope, that's only one list.  It's a list containing (1) the single match
that was built by _all_matches containing all the other strings at once,
and (2 through 4) the individual matches generated by _complete.

The reason you're getting the listing is because four matches are an
ambiguous situation: zsh doesn't know which of the four you wanted.  It
also inserts the first one because of MENU_COMPLETE (or at least that's
my best guess as to what's happening based on other things you wrote).

} Also, I'd like to not see anything at all if possible. So what am I
} doing wrong?

As far as I can tell, there's no simple way to get what you want, because
you must first generate matches before you can add another match that
consists of all the previous matches; which means you're guaranteed to
get an ambiguous completion (unless there's only one match from _complete
in the first place).  The tag-order style doesn't help here because it's
checked inside _tags and hence inside _complete where the all-matches
tag doesn't yet exist.

So you'll have to play a game like _approximate does, where compadd is
redefined as a function to capture all the matches that other completers
attempt to add, and then don't really add them until the end.  The idea
is to check for the -O/-A/-D options, and if none are present, then add
a -O option for your own array, and in eiher case call through to
"builtin compadd ...".  Finally, in a comppostfunc, remove the compadd
function and call the real compadd with the string resulting from a
join of your array.
 
} For example, it would be very useful to have for "cvs diff" [...]
} so that pressing TAB after "cvs di" normally completes only the
} modified files. But pressing ^Xa also completes the sub-directories --
} is there any way I could avoid this?

Unfortunately there you're stuck by _cvs_modified_entries which adds
all the entries and subdirectories under the single tag "files".  It has
nothing to do with _all_matches.


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

* how to customize _all_matches use?
@ 2007-06-15 20:25 Vadim Zeitlin
  0 siblings, 0 replies; 5+ messages in thread
From: Vadim Zeitlin @ 2007-06-15 20:25 UTC (permalink / raw)
  To: zsh-users

 Hello,

 I'd like to have a key binding which would complete all matches which I
would get by pressing TAB at once. AFAICS from the manual/user guide, this
is what the all-matches completer is for and so, following the examples
there, I tried to do the following:

	% zle -C all-matches complete-word _generic
	% bindkey '^Xa' all-matches
	% zstyle ':completion:all-matches:*' completer _all_matches

However this doesn't seem to work:

	% ls
	bar  baz  foo
	% ls ^Xa # nothing happens

I do get the behaviour I want if I do

	% zstyle ':completion:all-matches:*' completer _all_matches _complete

but with one extremely annoying side-effect:

	% ls ^Xa
	% ls bar baz foo # this is the same line completed by the shell
	bar baz foo
	bar  baz  foo

i.e. although I do get all the completions I also get *2* lists of them
below. I would understand it if I was getting 1 line because I use
MENU_COMPLETE (and no other non-default completion options), but where does
the second one come from? Also, I'd like to not see anything at all if
possible. So what am I doing wrong?


 And, of course, I don't really want to have this behaviour so much for ls
as for other commands where the completion can't be replaced with just '*'.
For example, it would be very useful to have for "cvs diff" for which I use

	zstyle ':completion::complete:cvs-diff:argument-rest:' \
		tag-order existing-files removed-files directories

so that pressing TAB after "cvs di" normally completes only the modified
files. But pressing ^Xa also completes the sub-directories -- is there any
way I could avoid this?

 Thanks in advance for any help!
VZ

P.S. If it matters, I'm using 4.3.2 under Debian Linux


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

end of thread, other threads:[~2007-06-16 19:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <vz-zsh@zeitlins.org>
     [not found] ` <20070615202549.MSYR16334.aamtain04-winn.ispmail.ntl.com@a.mx.sunsite.dk>
2007-06-16 17:25   ` how to customize _all_matches use? Peter Stephenson
2007-06-16 17:42     ` Peter Stephenson
2007-06-16 19:05     ` Re[2]: " Vadim Zeitlin
     [not found] <4672f5ca.216f420a.0ac9.ffffac6fSMTPIN_ADDED@mx.google.com>
2007-06-16 17:14 ` Bart Schaefer
2007-06-15 20:25 Vadim Zeitlin

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).