From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zzapper <david@tvis.co.uk>
Cc: zsh-users@sunsite.dk
Subject: Re: Why doesn't cd ignore files when you type say "cd fred*"
Date: Fri, 05 Dec 2003 15:27:05 +0100 [thread overview]
Message-ID: <16498.1070634425@gmcs3.local> (raw)
In-Reply-To: <9hp0tv0i0066fbbh857hklmcs43v78u67d@4ax.com>
zzapper wrote:
> >
> >bindkey '\e*' match-word
> >zstyle ':completion:match-word::::' completer _all_matches _match _ignored
> >zstyle ':completion:match-word:*' match-original both
> >zle -C match-word complete-word _generic
>
> Oliver that works great but what is all that gobbledegook?
It's not easy to explain that fully in a short e-mail.
Hopefully you're already familar with bindkey. It allows you to bind a
key or key combination to an editor command. This binds escape * to
`match-word'.
In addition to lots of builtin editor commands, zsh allows you to
define your own. The `zle -C' command here creates the match-word
editor command. Editor commands which do completion are a little
different so they are defined with `zle -C' instead of `zle -N'.
To implement a user-defined editor widget, a function has to be
written. In this case, we use _generic which is an already existing
completion function. _generic hooks in to the existing function based
completion system. With it, escape * is now going to behave like a
second tab key and do completion. With the zstyle commands we make it
behave differently while still doing completion.
zstyle is a powerful command which is used for configuring many aspects
of completion. It is similar to setting shell options or variables but
a particular "style" can have a different value in different contexts.
You may have already used zstyle in your startup file. The `completer'
style is a very common one. For example, you may use something like:
zstyle ':completion:::::' completer _expand _complete _approximate
This defines the default completer so will be used for your tab key.
This would allow completion to do expansion (expanding file patterns
like fred*), then normal completion and then approximate completion
(which allows for errors in what you have typed).
Above, I used ':completion:match-word::::' as the context. This
restricts the style to applying for our new match-word editor command.
So escape * now does completion but uses a different set of completers.
The important completer in this case was _match. It alone would do the
job you were asking about. The other two completers (_all_matches and
_ignored) just add some extra functionality.
The same goes for the second (match-original) style. That just allows
you to go back to the original string you had typed (such as fred*)
more easily if completion finds several matches.
I hope that makes it clearer. Completion is very configurable and this
isn't the simplist example to start with.
Oliver
next prev parent reply other threads:[~2003-12-05 14:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-04 14:54 zzapper
2003-12-04 15:37 ` Peter Stephenson
2003-12-04 16:47 ` zzapper
2003-12-05 10:54 ` Oliver Kiddle
2003-12-05 11:06 ` zzapper
2003-12-05 14:27 ` Oliver Kiddle [this message]
2003-12-04 17:30 ` Bart Schaefer
2003-12-04 20:50 ` zzapper
2003-12-04 22:56 ` Pavol Juhas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16498.1070634425@gmcs3.local \
--to=okiddle@yahoo.co.uk \
--cc=david@tvis.co.uk \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).