Sophie

Sophie

distrib > Mandriva > 8.1 > i586 > by-pkgid > 628e26a49117deea42e952d5b0d0f0d7 > files > 54

zsh-doc-4.0.2-2mdk.i586.rpm

<HTML>
<HEAD>
<!-- Created by texi2html 1.56k from ./zsh.texi on 26 June 2001 -->

<TITLE>zsh - Completion System</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="zsh_1.html">first</A>, <A HREF="zsh_18.html">previous</A>, <A HREF="zsh_20.html">next</A>, <A HREF="zsh_29.html">last</A> section, <A HREF="zsh_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC105" HREF="zsh_toc.html#TOC105">Completion System</A></H1>
<P>
<A NAME="IDX1075"></A>
<A NAME="IDX1076"></A>
<A NAME="IDX1077"></A>




<H2><A NAME="SEC106" HREF="zsh_toc.html#TOC106">Description</A></H2>
<P>


<P>
This describes the shell code for the new completion system.  It consists
of various shell functions; those beginning `<TT>comp</TT>' are to be called
directly by the user, while those beginning `<TT>_</TT>' are called by the
completion code.  The shell functions of the second set which implement
completion behaviour and which may be bound to keystrokes, are referred to
as `widgets'.


<P>


<P>




<H2><A NAME="SEC107" HREF="zsh_toc.html#TOC107">Initialization</A></H2>
<P>
<A NAME="IDX1078"></A>
<A NAME="IDX1079"></A>


<P>
If the system was installed completely, it should be enough to
call the shell function <TT>compinit</TT> from your initialization file; see the
next section.  However, the function <TT>compinstall</TT> can be run by a user
to configure various aspects of the completion system.


<P>
Usually, <TT>compinstall</TT> will insert code into <TT>.zshrc</TT>, although if
that is not writable it will save it in another file and tell you that
file's location.  Note that it is up to you to make sure that the lines
added to <TT>.zshrc</TT> are actually run; you may, for example, need to move
them to an earlier place in the file if <TT>.zshrc</TT> usually returns early.
So long as you keep them all together (including the comment lines at the
start and finish), you can rerun <TT>compinstall</TT> and it will correctly
locate and modify these lines.  Note, however, that any code you add to
this section by hand is likely to be lost if you rerun <TT>compinstall</TT>,
although lines using the command `<TT>zstyle</TT>' should be gracefully handled.


<P>
The new code will take effect next time you start the shell, or run
<TT>.zshrc</TT> by hand; there is also an option to make them take effect
immediately.  However, if <TT>compinstall</TT> has removed definitions, you will
need to restart the shell to see the changes.


<P>
To run <TT>compinstall</TT> you will need to make sure it is in a directory
mentioned in your <TT>fpath</TT> parameter, which should already be the case if
zsh was properly configured as long as your startup files do not remove the
appropriate directories from <TT>fpath</TT>.  Then it must be autoloaded
(`<TT>autoload -U compinstall</TT>' is recommended).  You can abort the
installation any time you are being prompted for information, and your
<TT>.zshrc</TT> will not be altered at all; changes only take place right at the
end, where you are specifically asked for confirmation.


<P>




<H3><A NAME="SEC108" HREF="zsh_toc.html#TOC108">Use of compinit</A></H3>
<P>
<A NAME="IDX1080"></A>
<A NAME="IDX1081"></A>


<P>
This section describes the use of <TT>compinit</TT> to initialize completion for
the current session when run directly by the user; if you have run
<TT>compinstall</TT> it will be called automatically from your <TT>.zshrc</TT>.


<P>
To initialize the system, the function <TT>compinit</TT> should be in a
directory mentioned in the <TT>fpath</TT> parameter, and should be autoloaded
(`<TT>autoload -U compinit</TT>' is recommended), and then run simply as
`<TT>compinit</TT>'.  This will define a
few utility functions, arrange for all the necessary shell functions to be
autoloaded, and will then re-define all widgets that do completion to use the
new system.  If you use the <TT>menu-select</TT> widget, which is part of the
<TT>zsh/complist</TT> module, you should make sure that that module is loaded
before the call to <TT>compinit</TT> so that that widget is also
re-defined.  If completion styles (see below) are set up to perform
expansion as well as completion by default, and the TAB key is bound to
<TT>expand-or-complete</TT>, <TT>compinit</TT> will rebind it to <TT>complete-word</TT>;
this is necessary to use the correct form of expansion.


<P>
Should you need to use the original completion commands, you can still
bind keys to the old widgets by putting a `<TT>.</TT>' in front of the
widget name, e.g. `<TT>.expand-or-complete</TT>'.


<P>
To speed up the running of <TT>compinit</TT>, it can be made to produce a dumped
configuration which will be read in on future invocations; this is the
default, although it can be turned off by calling <TT>compinit</TT> with the
option <TT>-D</TT>.  The dumped file is <TT>.zcompdump</TT> in the same
directory as the startup files (i.e. <TT>$ZDOTDIR</TT> or <TT>$HOME</TT>);
alternatively, an explicit file name can be given by `<TT>compinit -d</TT>
<VAR>dumpfile</VAR>'.  On the next call to <TT>compinit</TT>, it will read the dumped
file instead of performing a full initialization.


<P>
If the number of completion files changes, <TT>compinit</TT> will recognise this
and produce a new dump file.  However, if the name of a function or the
arguments in the first line of a <TT>#compdef</TT> function (as described below)
change, it is easiest to delete the dump file by hand so that
<TT>compinit</TT> will re-create it the next time it is run.  The check
performed to see if there are new functions can be omitted by giving
the option <TT>-C</TT>.  In this case the dump file will only be created if
there isn't one already.


<P>
The dumping is actually done by another function, <TT>compdump</TT>, but you
will only need to run this yourself if you change the configuration
(e.g. using <TT>compdef</TT>) and then want to dump the new one.  The name of
the old dumped file will be remembered for this purpose.


<P>
If the parameter <TT>_compdir</TT> is set, <TT>compinit</TT> uses it as a directory
where completion functions can be found; this is only necessary if they are
not already in the function search path.


<P>
For security reasons <TT>compinit</TT> also checks if the completion system
would use files not owned by root or by the current user, or files in
directories that are world- or group-writable or that are not owned by 
root or by the current user.  If such files or directories are found,
<TT>compinit</TT> will ask if the completion system should really be used.  To
avoid these tests and make all files found be used without asking, use the
option <TT>-u</TT>, and to make <TT>compinit</TT> silently ignore all insecure files
and directories use the option <TT>-i</TT>.  This security check is skipped
entirely when the <TT>-C</TT> option is given.


<P>
<A NAME="IDX1082"></A>
The security check can be retried at any time by running the function
<TT>compaudit</TT>.  This is the same check used by <TT>compinit</TT>, but when it
is executed directly any changes to <TT>fpath</TT> are made local to the
function so they do not persist.  The directories to be checked may be
passed as arguments; if none are given, <TT>compaudit</TT> uses <TT>fpath</TT> and
<TT>_compdir</TT> to find completion system directories, adding missing ones
to <TT>fpath</TT> as necessary.  To force a check of exactly the directories
currently named in <TT>fpath</TT>, set <TT>_compdir</TT> to an empty string before
calling <TT>compaudit</TT> or <TT>compinit</TT>.


<P>




<H3><A NAME="SEC109" HREF="zsh_toc.html#TOC109">Autoloaded files</A></H3>
<P>
<A NAME="IDX1083"></A>


<P>
The convention for autoloaded functions used in completion is that they
start with an underscore; as already mentioned, the <TT>fpath/FPATH</TT>
parameter must contain the directory in which they are stored.  If <TT>zsh</TT>
was properly installed on your system, then <TT>fpath/FPATH</TT> automatically
contains the required directories for the standard functions.


<P>
For incomplete installations, if <TT>compinit</TT> does not find enough files
beginning with an underscore (fewer than twenty) in the search path, it
will try to find more by adding the directory <TT>_compdir</TT> to the search
path.  If that directory has a subdirectory named <TT>Base</TT>, all
subdirectories will be added to the path.  Furthermore, if the subdirectory
<TT>Base</TT> has a subdirectory named <TT>Core</TT>, <TT>compinit</TT> will add all
subdirectories of the subdirectories is to the path: this allows
the functions to be in the same format as in the <TT>zsh</TT> source
distribution.


<P>
<A NAME="IDX1084"></A>
When <TT>compinit</TT> is run, it searches all such files accessible via
<TT>fpath/FPATH</TT> and reads the first line of each of them.  This line should
contain one of the tags described below.  Files whose first line does not
start with one of these tags are not considered to be part of the
completion system and will not be treated specially.


<P>
The tags are:


<P>
<DL COMPACT>

<DT><TT>#compdef</TT> <VAR>names...</VAR>
<DD>
The file will be made autoloadable and the function defined 
in it will be called when completing <VAR>names</VAR>, each of which is
either the name of a command whose arguments are to be completed or one of
a number of special contexts in the form <TT>-</TT><VAR>context</VAR><TT>-</TT> described
below for the <TT>_complete</TT> function.

Each <VAR>name</VAR> may also be of the form `<VAR>cmd</VAR><TT>=</TT><VAR>service</VAR>'.  This
is used by functions that offer multiple services, i.e. different
completion behaviour for multiple commands.  Such a string
makes the completion system call the function when completing
arguments for the command `<TT>cmd</TT>', setting the parameter <TT>$service</TT> 
to the string `<TT>service</TT>'.  The function can then use that parameter 
to decide what to complete.

<DT><TT>#compdef -p</TT> <VAR>pattern</VAR>
<DD>
The file will be made autoloadable and the function defined in it will be
called when completing for a command whose name matches the given
<VAR>pattern</VAR> (a standard globbing pattern).  Note that only one
<VAR>pattern</VAR> may be given.

<DT><TT>#compdef -P</TT> <VAR>pattern</VAR>
<DD>
Like the previous one, but the function will be called only if no
completion function for the command on the line could be found.

<DT><TT>#compdef -k</TT> <VAR>style key-sequences...</VAR>
<DD>
This can be used to bind special completion functions to the
<VAR>key-sequences</VAR> specified.  It creates a widget behaving like the
builtin widget <VAR>style</VAR>, which must be one of those that perform
completion, namely <TT>complete-word</TT>, <TT>delete-char-or-list</TT>,
<TT>expand-or-complete</TT>, <TT>expand-or-complete-prefix</TT>, <TT>list-choices</TT>,
<TT>menu-complete</TT>, <TT>menu-expand-or-complete</TT>, or
<TT>reverse-menu-complete</TT>.  If the <TT>zsh/complist</TT> module is loaded (see
section <A HREF="zsh_21.html#SEC136">The zsh/complist Module</A>), the same happens to the <TT>menu-select</TT> widget.

The widget is then bound to all the <VAR>key-sequences</VAR> given, if any: when
one of the <VAR>key-sequences</VAR> is typed, the function in the file will
be invoked to generate the matches.  Note that a key will not be re-bound
if if it already was (that is, was bound to something other than
<TT>undefined-key</TT>).  The widget created has the same name as the file and
can be bound to any other keys using <TT>bindkey</TT> as usual.

<DT><TT>#compdef -K</TT> <VAR>widget-name</VAR> <VAR>style</VAR> <VAR>key-sequences</VAR> ...
<DD>
This is similar to <TT>-k</TT>, with the same <VAR>style</VAR> and <VAR>key-sequences</VAR>
arguments, preceded by a string giving the name of a widget.
In this case only one <VAR>key-sequences</VAR> argument may be given, but the
entire set of three arguments may be repeated with a different set of
arguments.  In particular, the <VAR>widget-name</VAR> must be distinct in each
set.  It should begin with `<TT>_</TT>', else one will be added, and should not
clash with the name of any existing widget: names based on the name of the
function are most useful.  For example,


<PRE>
#compdef -K _foo_complete complete-word "^X^C" \ 
  _foo_list list-choices "^X^D"
</PRE>

(all on one line) defines a widget <TT>_foo_complete</TT> for completion, bound
to `<TT>^X^C</TT>', and a widget <TT>_foo_list</TT> for listing, bound to `<TT>^X^D</TT>'.

<DT><TT>#autoload</TT> [ <VAR>options</VAR> ]
<DD>
This is used for files defining utility functions that are not to be
called directly as completion functions but should be loaded automatically
when invoked.  Typically they are to be called from within one of the
completion functions.

The <VAR>options</VAR> will be given to the <TT>autoload</TT> builtin command
when making the function autoloaded.  Most often, this will be <TT>+X</TT> to
force the function to be loaded immediately.  Note that the <TT>-U</TT> flag is
always implicitly added.

</DL>

<P>
The <TT>#</TT> is part of the tag name and no white space is allowed after it.
The <TT>#compdef</TT> tags use the <TT>compdef</TT> function described below; the
main difference is that the name of the function is supplied implicitly.


<P>
Note also that the functions for the completion system assume that the
<TT>KSH_AUTOLOAD</TT> option is not set and cannot be loaded when it is
set.  To avoid having to unset <TT>KSH_AUTOLOAD</TT>, you can instead use one or
more <TT>zwc</TT> file(s) which have been created with the command <TT>zcompile
-z</TT> to load the functions for the completion system; see
section <A HREF="zsh_16.html#SEC83">Shell Builtin Commands</A>.  This forces the functions to be autoloaded the way zsh normally
loads functions.


<P>




<H3><A NAME="SEC110" HREF="zsh_toc.html#TOC110">Functions</A></H3>
<P>


<P>
The <TT>compinit</TT> file defines the following function, which may
also be called directly by the user.


<P>
<A NAME="IDX1085"></A>
<A NAME="IDX1086"></A>
<DL COMPACT>

<DT><TT>compdef</TT> [ <TT>-an</TT> ] <VAR>function names...</VAR>
<DD>
<DT><TT>compdef -d</TT> <VAR>names...</VAR>
<DD>
<DT><TT>compdef -p</TT> [ <TT>-a</TT> ] <VAR>function pattern</VAR>
<DD>
<DT><TT>compdef -P</TT> [ <TT>-a</TT> ] <VAR>function pattern</VAR>
<DD>
<DT><TT>compdef -k</TT> [ <TT>-an</TT> ] <VAR>function style key-sequences...</VAR>
<DD>
<DT><TT>compdef -K</TT> [ <TT>-an</TT> ] <VAR>function name style key-sequences ...</VAR>
<DD>
The first form tells the completion system to call the given
<VAR>function</VAR> when completing for the contexts or commands
whose <VAR>names</VAR> are given:  this is like the <TT>#compdef</TT> tag unless
the first word contains an equal sign.  In this case all words have to 
be of the form `<VAR>cmd</VAR><TT>=</TT><VAR>service</VAR>' where <VAR>service</VAR> is the
name of a command or of a service defined by an autoloaded function
with the <TT>#compdef</TT> tag and an argument of the form
`<VAR>cmd</VAR><TT>=</TT><VAR>service</VAR>'.  This kind of use makes the arguments of
the <VAR>cmd</VAR>s be completed as those for the <VAR>services</VAR>.

If the
<TT>-n</TT> option is given, any existing completion behaviour for particular
contexts or commands will not be altered.  These definitions can be deleted
by giving the <TT>-d</TT> option as in the second form.

The form with <TT>-p</TT> is similar to the first, but <VAR>function</VAR> will be
called for all commands whose name matches the <VAR>pattern</VAR>; this is like
the <TT>#compdef -p</TT> function tag.

The form with <TT>-P</TT> is like the third, but the <VAR>function</VAR> will be
called only if no function for the command itself was found or if one
was found and it set the <TT>_compskip</TT> parameter to a value <EM>not</EM>
containing the substring <TT>patterns</TT>.

The form with <TT>-k</TT> defines a widget with the same name as the <VAR>function</VAR>
which will be called for each of the <VAR>key-sequences</VAR>; this is like the
<TT>#compdef -k</TT> tag.  The function should generate the completions needed
and will otherwise behave like the builtin widget whose name is given as
the <VAR>style</VAR> argument. The widgets usable for this are:
<TT>complete-word</TT>, <TT>delete-char-or-list</TT>, <TT>expand-or-complete</TT>,
<TT>expand-or-complete-prefix</TT>, <TT>list-choices</TT>, <TT>menu-complete</TT>,
<TT>menu-expand-or-complete</TT>, and <TT>reverse-menu-complete</TT>, as well as
<TT>menu-select</TT> if the <TT>zsh/complist</TT> module is loaded.  The option <TT>-n</TT>
prevents the key being bound if it is already to bound to something other
than <TT>undefined-key</TT>.

The form with <TT>-K</TT> is similar and defines multiple widgets based on the
same <VAR>function</VAR>, each of which requires the set of three arguments
<VAR>name</VAR>, <VAR>style</VAR> and <VAR>key-sequences</VAR>, where the latter two are as
for <TT>-k</TT> and the first must be a unique widget name beginning with an
underscore.

In each of the forms supporting it the <TT>-a</TT> option makes the
<VAR>function</VAR> autoloadable (exactly equivalent to
<TT>autoload -U </TT><VAR>function</VAR>).

</DL>

<P>
The <TT>compdef</TT> function is the place to turn to when one wants to
define what the completion system should complete for a certain
command.  The function named can of course be one of the functions
supplied or one written by the user.  For example, if one has a
command <TT>foo</TT> that gets process identifiers as arguments, one could
do:


<P>

<PRE>
compdef _pids foo
</PRE>

<P>
using the <TT>_pids</TT> function from the distribution to generate the
process identifiers.  Not also the <TT>_gnu_generic</TT> function described
below, which can be used to complete options for commands that
understand the `<TT>-</TT><TT>-help</TT>' option.


<P>




<H2><A NAME="SEC111" HREF="zsh_toc.html#TOC111">Completion System Configuration</A></H2>
<P>
<A NAME="IDX1087"></A>


<P>
This section gives a short overview of how the completion system works,
and then more detail on how users can configure how and when matches are
generated.


<P>




<H3><A NAME="SEC112" HREF="zsh_toc.html#TOC112">Overview</A></H3>
<P>


<P>
When completion is attempted somewhere on a command line the
completion system first tries to find out the context where completion 
was tried.  The context depends on such things as the name of the
command when completing an argument, and possibly also
the name of an option when completing an argument to that option.


<P>
The `context' of a completion is a string consisting of multiple fields. This
is used to look up styles that can be used to configure the
completion system.  Since it is not possible to build the whole context 
string in advance, completion functions may modify some of the fields and 
hence the context used for lookup may vary during the same call
to the completion system.


<P>
The context string always consists of the following fields, separated
by colons and with a leading colon before the first:


<P>

<UL>

<LI>

The literal string <TT>completion</TT>, saying that this style is used by
the completion system.

<LI>

The <VAR>function</VAR>; in many cases this field will be blank, but when
the completion system is called from other functions, like
<TT>predict-on</TT> or one of the functions in the <TT>Command</TT> directory of 
the distribution, this field contains the name of that function, often
in an abbreviated form.

<LI>

The <VAR>completer</VAR> currently active, which is the name of the function
without the leading underscore.  A `completer' is in
overall control of how completion is to be performed; `<TT>complete</TT>'
is the basic one for ordinary completion, but completers may perform
various related tasks such as correction, or modify the behaviour of a
later completer (see
section <A HREF="zsh_19.html#SEC115">Control Functions</A> 
for more information).  

<LI>

The <VAR>context</VAR> or <VAR>command</VAR>.  This is either one of the special
context names such as <TT>-condition-</TT> as explained for the
<TT>_complete</TT> completer below, or the name of the command we are
completing arguments for.  Completion functions for commands that have
sub-commands usually modify this field to contain the name of the
command followed by a minus sign and the sub-command (e.g. the
completion function for the <TT>cvs</TT> command sets this field to strings
such as <TT>cvs-add</TT> when completing for the <TT>add</TT> sub-command).

<LI>

The <VAR>argument</VAR>, describing which argument we are
completing.  Normally this is either a string of the form
<TT>argument-</TT><VAR>n</VAR>, where <VAR>n</VAR> is the number of the argument or it
is a string of the form <TT>option-</TT><VAR>opt</VAR><TT>-</TT><VAR>n</VAR> when completing the
<VAR>n</VAR>'th argument of the option <VAR>opt</VAR>.

<LI>

The <VAR>tag</VAR>.  Tags are used to discriminate between the types
of matches a completion function can generate in a certain context.

</UL>

<P>
As an example, the context name


<P>

<PRE>
<TT>:completion::complete:dvips:option-o-1:files</TT>
</PRE>

<P>
says that normal completion was attempted on an argument of the <TT>dvips</TT>
command (more precisely: completion was attempted on the first argument
after the <TT>-o</TT> option) and the completion function will generate
filenames for this context.


<P>
In many of the possible contexts the completion system can generate
matches, often multiple types of matches.  These types are represented as
simple names called `tags'.  The completion system will decide internally
what sort of tags are allowed; a list of the standard possibilities is given
below.  To determine in which order the tags are to be used by the
completion function, the `<TT>tag-order</TT>' style for the appropriate
context may be set, as described in the list of standard styles below.
Only those types of matches whose tags were selected by this style
will be produced, and in the order given, although the default is to try
all relevant tags in an order determined by the particular completion in
use.


<P>
The <TT>_complete_help</TT> bindable command described in 
section <A HREF="zsh_19.html#SEC116">Bindable Commands</A>
can be invoked to find out the context and tag names and styles used at a
particular point in completion.  It shows the list of contexts and tags 
that would be used in if completion were tried at the current cursor
position.  Hence one can easily find out all the information needed to
change the behaviour of the <TT>tag-order</TT> style for a particular context.


<P>
Completion behaviour can be modified by various other
styles defined with the <TT>zstyle</TT> builtin command (section <A HREF="zsh_21.html#SEC161">The zsh/zutil Module</A>).
When looking up styles the completion system uses full context names,
including the tag.


<P>
Styles determine such things as how the matches are generated; some of them
correspond to shell options (for example, the use of menu completion), but
styles provide more specific control.  They can have any number of strings as
their value.  Looking up the value of a style therefore consists of two
things:  the context, which may be matched as a pattern, and the name of
the style itself, which must be given exactly.


<P>
For example, many completion functions can generate matches in a
simple and a verbose form and use the <TT>verbose</TT> style to decide
which form should be used.  To make all such functions use the verbose form,
put


<P>

<PRE>
zstyle ':completion:*' verbose yes
</PRE>

<P>
in one of the startup files like <TT>.zshrc</TT>; this sort of style can also be
configured with the <TT>compinstall</TT> function.  This definition simply
means that the <TT>verbose</TT> style has <TT>yes</TT> as its value in every
context inside the completion system.  If the context pattern were `<TT>*</TT>',
the verbose style would have this value anywhere the style mechanism is
used, not just in completion.


<P>
As a more specific example, the completion function for the <TT>kill</TT>
builtin command uses the <TT>verbose</TT> style to decide if jobs and processes
are listed only as job numbers and process identifiers or if they are
listed with the full job texts and the command lines of the processes (the
latter is achieved by calling the <TT>ps</TT> command).  To make this builtin
list the matches only as numbers one could call:


<P>

<PRE>
zstyle ':completion:*:*:kill:*' verbose no
</PRE>

<P>
Furthermore, if one wanted to see the command lines for processes but not the
job texts one could use the fact that the context name contains the tag name
when styles are looked up.  As the function for the <TT>kill</TT>
builtin command uses the tags <TT>jobs</TT> and <TT>processes</TT>, we can use:


<P>

<PRE>
zstyle ':completion:*:*:kill:*:jobs' verbose no
</PRE>

<P>
To have more control over when certain values for styles are used one
can use the special parameters available in completion widgets (see
section <A HREF="zsh_18.html#SEC98">Completion Widgets</A>)) and the <TT>-e</TT> option to <TT>zstyle</TT> that makes the value be
evaluated when looked up.  For example, to make the <TT>completer</TT>
style have a different value when completing for the <TT>cvs</TT> command,
one could use the <TT>words</TT> special array:


<P>

<PRE>
zstyle -e ':completion:*' completer '
    if [[ $words[1] = cvs ]]; then
      reply=(_complete)
    else
      reply=(_complete _approximate)
    fi'
</PRE>

<P>
One should be careful not to use too complicated code with this
option, at least for the styles that are looked up quite often.  These 
are basically those that define some global completion behaviour but
allow that to be different for all matches or groups of matches (such
as the <TT>menu</TT> and <TT>list-rows-first</TT> styles).  Alternatively one
can always use a less general pattern for the context than in the
example above and use a second call to <TT>zstyle</TT> with a generic
pattern and without using the <TT>-e</TT> option to define the default
behaviour.


<P>
Note that the order in which styles are <EM>defined</EM> does not matter; the
style mechanism uses the most specific possible match for a particular
style to determine the set of values.  More precisely, strings are
preferred over patterns (for example, `<TT>:completion::complete:foo</TT>' is
more specific than `<TT>:completion::complete:*'</TT>), and longer patterns are
preferred over shorter patterns.


<P>
As with tags, completion functions can use any style they choose, so
there can't be a complete list.  However, the following two sections
list those tags and styles that are used in many places of the
completion system.


<P>




<H3><A NAME="SEC113" HREF="zsh_toc.html#TOC113">Standard Tags</A></H3>
<P>
<A NAME="IDX1088"></A>


<P>
Here are the tags currently used by the completion system.  Some of them
are only used when looking up styles and do not refer to a particular type
of match.


<P>
<DL COMPACT>

<DT><TT>accounts</TT>
<DD>
<A NAME="IDX1089"></A>
 
used to look up the <TT>users-hosts</TT> style

<A NAME="IDX1090"></A>
<DT><TT>all-expansions</TT>
<DD>
used by the <TT>_expand</TT> completer when adding the single string containing
all possible expansions

<A NAME="IDX1091"></A>
<DT><TT>all-files</TT>
<DD>
for the names of all files (as distinct from a particular subset, see the
<TT>globbed-files</TT> tag).

<A NAME="IDX1092"></A>
<DT><TT>arguments</TT>
<DD>
when an argument of a command may be completed

<A NAME="IDX1093"></A>
<DT><TT>arrays</TT>
<DD>
for names of array parameters

<A NAME="IDX1094"></A>
<DT><TT>association-keys</TT>
<DD>
for keys of associative arrays; used when completing inside a
subscript of a parameter of this type

<A NAME="IDX1095"></A>
<DT><TT>bookmarks</TT>
<DD>
when completing bookmarks (e.g. for URLs and the <TT>zftp</TT> function suite)

<A NAME="IDX1096"></A>
<DT><TT>builtins</TT>
<DD>
for names of builtin commands

<A NAME="IDX1097"></A>
<DT><TT>characters</TT>
<DD>
used for commands like <TT>stty</TT> when completing characters; also used
when completing character classes after a opening bracket

<A NAME="IDX1098"></A>
<DT><TT>colormapids</TT>
<DD>
for X colormap ids

<A NAME="IDX1099"></A>
<DT><TT>colors</TT>
<DD>
for color names

<A NAME="IDX1100"></A>
<DT><TT>commands</TT>
<DD>
for names of external commands and names of sub-commands (used by some 
commands like <TT>cvs</TT>)

<A NAME="IDX1101"></A>
<DT><TT>contexts</TT>
<DD>
for contexts used by the zstyle builtin command

<A NAME="IDX1102"></A>
<DT><TT>corrections</TT>
<DD>
used by the <TT>_approximate</TT> and <TT>_correct</TT> completers for the possible
corrections

<A NAME="IDX1103"></A>
<DT><TT>cursors</TT>
<DD>
for cursor names used by X programs

<A NAME="IDX1104"></A>
<DT><TT>default</TT>
<DD>
used to look up default values for various styles that may also be set 
for tags that are used when generating matches; note that this tag is
used when only the <VAR>function</VAR> field of the context name is set up

<A NAME="IDX1105"></A>
<DT><TT>descriptions</TT>
<DD>
used when looking up the value of the <TT>format</TT> style for
descriptions

<A NAME="IDX1106"></A>
<DT><TT>devices</TT>
<DD>
for names of device special files

<A NAME="IDX1107"></A>
<DT><TT>directories</TT>
<DD>
for names of directories

<A NAME="IDX1108"></A>
<DT><TT>directory-stack</TT>
<DD>
for entries in the directory stack

<A NAME="IDX1109"></A>
<DT><TT>displays</TT>
<DD>
for X display names

<A NAME="IDX1110"></A>
<DT><TT>domains</TT>
<DD>
for network domains

<A NAME="IDX1111"></A>
<DT><TT>expansions</TT>
<DD>
used by the <TT>_expand</TT> completer for individual possibilities resulting
from expansion of a word

<A NAME="IDX1112"></A>
<DT><TT>extensions</TT>
<DD>
for X server extensions

<A NAME="IDX1113"></A>
<DT><TT>file-descriptors</TT>
<DD>
for the numbers of open file descriptors

<A NAME="IDX1114"></A>
<DT><TT>files</TT>
<DD>
the generic file-matching tag used by completion functions that can
complete the names of some kind of file

<A NAME="IDX1115"></A>
<DT><TT>fonts</TT>
<DD>
used for X font names

<A NAME="IDX1116"></A>
<DT><TT>functions</TT>
<DD>
names of functions, normally shell functions although certain commands may
understand other kinds of function

<A NAME="IDX1117"></A>
<DT><TT>globbed-files</TT>
<DD>
for names of files matching the glob pattern used by completion
functions that expect a certain type of file

<A NAME="IDX1118"></A>
<DT><TT>groups</TT>
<DD>
used when completing names of user groups

<A NAME="IDX1119"></A>
<DT><TT>history-words</TT>
<DD>
for words from the history

<A NAME="IDX1120"></A>
<DT><TT>hosts</TT>
<DD>
for hostnames

<A NAME="IDX1121"></A>
<DT><TT>indexes</TT>
<DD>
used for array indexes

<A NAME="IDX1122"></A>
<DT><TT>jobs</TT>
<DD>
used for jobs

<A NAME="IDX1123"></A>
<DT><TT>keymaps</TT>
<DD>
for names of zsh keymaps

<A NAME="IDX1124"></A>
<DT><TT>keysyms</TT>
<DD>
for names of X keysyms

<A NAME="IDX1125"></A>
<DT><TT>libraries</TT>
<DD>
for names of system libraries

<A NAME="IDX1126"></A>
<DT><TT>limits</TT>
<DD>
for system limits

<A NAME="IDX1127"></A>
<DT><TT>local-directories</TT>
<DD>
for names of directories which are subdirectories of the current working
directory when completing for the <TT>cd</TT> and related builtin commands

<A NAME="IDX1128"></A>
<DT><TT>manuals</TT>
<DD>
for names of manual pages

<A NAME="IDX1129"></A>
<DT><TT>maps</TT>
<DD>
for map names (e.g. NIS maps)

<A NAME="IDX1130"></A>
<DT><TT>messages</TT>
<DD>
used to look up the <TT>format</TT> style for messages

<A NAME="IDX1131"></A>
<DT><TT>modifiers</TT>
<DD>
for names of X modifiers

<A NAME="IDX1132"></A>
<DT><TT>modules</TT>
<DD>
for modules (e.g. <TT>zsh</TT> modules)

<A NAME="IDX1133"></A>
<DT><TT>my-accounts</TT>
<DD>
used to look up the <TT>users-hosts</TT> style

<A NAME="IDX1134"></A>
<DT><TT>named-directories</TT>
<DD>
for named directories (you wouldn't have guessed that, would you?)

<A NAME="IDX1135"></A>
<DT><TT>names</TT>
<DD>
for all kinds of names

<A NAME="IDX1136"></A>
<DT><TT>nicknames</TT>
<DD>
for nicknames of NIS maps

<A NAME="IDX1137"></A>
<DT><TT>options</TT>
<DD>
for command options

<A NAME="IDX1138"></A>
<DT><TT>original</TT>
<DD>
used by the <TT>_approximate</TT>, <TT>_correct</TT> and <TT>_expand</TT> completers when
adding the original string

<A NAME="IDX1139"></A>
<DT><TT>other-accounts</TT>
<DD>
used to look up the <TT>users-hosts</TT> style

<A NAME="IDX1140"></A>
<DT><TT>packages</TT>
<DD>
for packages (e.g. <TT>rpm</TT> or installed <TT>Debian</TT> packages)

<A NAME="IDX1141"></A>
<DT><TT>parameters</TT>
<DD>
for names of parameters

<A NAME="IDX1142"></A>
<DT><TT>path-directories</TT>
<DD>
for names of directories found by searching the <TT>cdpath</TT> array when
completing for the <TT>cd</TT> and related builtin commands

<A NAME="IDX1143"></A>
<DT><TT>paths</TT>
<DD>
used to look up the values of the <TT>expand</TT>, <TT>ambiguous</TT> and
<TT>special-dirs</TT> styles

<A NAME="IDX1144"></A>
<DT><TT>pods</TT>
<DD>
for perl pods (documentation files)

<A NAME="IDX1145"></A>
<DT><TT>ports</TT>
<DD>
for communication ports

<A NAME="IDX1146"></A>
<DT><TT>prefixes</TT>
<DD>
for prefixes (like those of a URL)

<A NAME="IDX1147"></A>
<DT><TT>printers</TT>
<DD>
for printer names

<A NAME="IDX1148"></A>
<DT><TT>processes</TT>
<DD>
for process identifiers

<A NAME="IDX1149"></A>
<DT><TT>processes-names</TT>
<DD>
used to look up the <TT>command</TT> style when generating the names of
processes for <TT>killall</TT>

<A NAME="IDX1150"></A>
<DT><TT>sequences</TT>
<DD>
for sequences (e.g. <TT>mh</TT> sequences)

<A NAME="IDX1151"></A>
<DT><TT>sessions</TT>
<DD>
for sessions in the <TT>zftp</TT> function suite

<A NAME="IDX1152"></A>
<DT><TT>signals</TT>
<DD>
for signal names

<A NAME="IDX1153"></A>
<DT><TT>strings</TT>
<DD>
for strings (e.g. the replacement strings for the <TT>cd</TT> builtin
command)

<A NAME="IDX1154"></A>
<DT><TT>styles</TT>
<DD>
for styles used by the zstyle builtin command

<A NAME="IDX1155"></A>
<DT><TT>tags</TT>
<DD>
for tags (e.g. <TT>rpm</TT> tags)

<A NAME="IDX1156"></A>
<DT><TT>targets</TT>
<DD>
for makefile targets

<A NAME="IDX1157"></A>
<DT><TT>types</TT>
<DD>
for types of whatever (e.g. address types for the <TT>xhost</TT> command)

<A NAME="IDX1158"></A>
<DT><TT>urls</TT>
<DD>
used to look up the <TT>urls</TT> and <TT>local</TT> styles when completing URLs

<A NAME="IDX1159"></A>
<DT><TT>users</TT>
<DD>
for usernames

<A NAME="IDX1160"></A>
<DT><TT>values</TT>
<DD>
when completing a value out of a set of values (or a list of such
values)

<A NAME="IDX1161"></A>
<DT><TT>version</TT>
<DD>
used by <TT>_call_program</TT> to look up the command to run to determine the installed
version of various other commands (such as <TT>diff</TT> and <TT>make</TT>).

<A NAME="IDX1162"></A>
<DT><TT>warnings</TT>
<DD>
used to look up the <TT>format</TT> style for warnings

<A NAME="IDX1163"></A>
<DT><TT>widgets</TT>
<DD>
for zsh widget names

<A NAME="IDX1164"></A>
<DT><TT>windows</TT>
<DD>
for IDs of X windows

<A NAME="IDX1165"></A>
<DT><TT>zsh-options</TT>
<DD>
for shell options

</DL>

<P>




<H3><A NAME="SEC114" HREF="zsh_toc.html#TOC114">Standard Styles</A></H3>
<P>
<A NAME="IDX1166"></A>


<P>
Here are the names of the styles used by the completion system.  Note
that the values of several of these styles represent boolean
values; here, any of the strings `<TT>true</TT>', `<TT>on</TT>',
`<TT>yes</TT>', and `<TT>1</TT>' can be used for the truth value `true' and
the strings `<TT>false</TT>', `<TT>off</TT>', `<TT>no</TT>', and `<TT>0</TT>' are
interpreted as `false'.  The behavior for any other value is undefined 
unless the description for the particular style mentions other
possible values; in particular, the default value may be either on or off
if the style is not set.


<P>
Some of these styles are tested for every tag used to add possible
matches and for the <TT>default</TT> tag (most notably <TT>menu</TT>,
<TT>list-colors</TT> and the styles controlling the completion listing like 
<TT>list-packed</TT> and <TT>last-prompt</TT>). When tested for the <TT>default</TT>
tag, only the <VAR>function</VAR> field of the context will be set up, so
the default value will normally be set like:


<P>

<PRE>
zstyle ':completion:*:default' menu ...
</PRE>

<P>
<DL COMPACT>

<DT><TT>accept-exact</TT>
<DD>
<A NAME="IDX1167"></A>
 
This is tested for the default tag and the tags used when generating
matches.  If it is set to `true' for at least one match which is the
same as the string on the line, this match will immediately be
accepted.

When completing pathnames (where it is looked up for the <TT>paths</TT>
tag), this style also accepts any number of patterns as the value. If
this is used, pathnames matching one of these patterns will be
accepted immediately even if the command line contains some more
partially typed pathname components and these match no file under the
directory accepted.

Note that this is also used by the <TT>_expand</TT> completer to decide if
words beginning with a tilde or parameter expansion should be
expanded. This means that if, for example, there are parameters
<TT>foo</TT> and <TT>foobar</TT>, the string `<TT>$foo</TT>' will only be expanded if 
<TT>accept-exact</TT> is set to `true'.

<A NAME="IDX1168"></A>
<DT><TT>add-space</TT>
<DD>
This style is used by the <TT>_expand</TT> completer.  If it is `true' (the
default), a space will be inserted after all words resulting from the 
expansion (except for directory names which get a slash).  The value
may also be the string `<TT>file</TT>' to make the completer add a space
only to names of existing files.  Finally, the `true' values and
`<TT>file</TT>' may be combined with `<TT>subst</TT>' to keep the completer from 
adding a space when the resulting words were generated by expanding a
substitution of the form `<TT>$(...)</TT>' or `<TT>${...}</TT>'.

It is also used by the <TT>_prefix</TT> completer as a simple boolean value
to decide if a space should be inserted before the suffix.

<A NAME="IDX1169"></A>
<DT><TT>ambiguous</TT>
<DD>
This applies when completing non-final components of filename paths.
If it is set, the cursor is left after the first ambiguous component, even
if menu completion is in use.  It is tested with the <TT>paths</TT> tag.

<A NAME="IDX1170"></A>
<DT><TT>assign-list</TT>
<DD>
When completing after an equals sign, the completion system normally
completes only one filename.  In some cases, particularly for certain
parameters such as <TT>PATH</TT>, a list of filenames separated by colons is
required.  This style can be set to a list of patterns matching the names
of such parameters.

The default is to complete lists when the word on the line already
contains a colon.

<A NAME="IDX1171"></A>
<DT><TT>auto-description</TT>
<DD>
If set, this style's value will be used as the description for options which
are not described by the completion functions, but that have exactly
one argument.  The sequence `<TT>%d</TT>' in the value will be replaced by
the description for this argument.  Depending on personal preferences,
it may be useful to set this style to something like `<TT>specify: %d</TT>'. 
Note that this may not work for some commands.

<A NAME="IDX1172"></A>
<DT><TT>avoid-completer</TT>
<DD>
This is used by the <TT>_all_matches</TT> completer to decide if the string 
consisting of all matches should be added to the list currently being
generated.  Its value is a list of names of completers.  If any of
these is the name of the completer that generated the matches in this
completion, the string will not be added.

The default value for this style is `<TT>_expand _old_list _correct
_approximate</TT>', i.e. it contains the completers for which a string
with all matches will almost never be wanted.

<A NAME="IDX1173"></A>
<DT><TT>cache-path</TT>
<DD>
This style defines the path where any cache files containing dumped
completion data are stored.  Defaults to `<TT>$ZDOTDIR/.zcompcache</TT>', or
`<TT>$HOME/.zcompcache</TT>' if <TT>$ZDOTDIR</TT> is not defined.  The completion
layer will not be used unless the <TT>use-cache</TT> style is set.

<A NAME="IDX1174"></A>
<DT><TT>call-command</TT>
<DD>
Currently this is only used by the function completing <TT>make</TT>
targets.  If it is set to `true' and the installed version of the
<TT>make</TT> command allows it, <TT>make</TT> is called in a way to generate
all possible targets.  The default value of this style is `false'
because calling <TT>make</TT> can potentially take a very long time and in
some cases may even cause actions from the makefile be executed
despite the options given to <TT>make</TT>.

<A NAME="IDX1175"></A>
<DT><TT>command</TT>
<DD>
In many places, completion functions need to call external commands to
generate the list of completions.  This style can be used to override the
command which is called in some such cases.  The elements of the value are
joined with spaces to form a command line to execute.  The value can also
start with a hyphen, in which case the usual command will be added to the
end; this is most useful for putting `<TT>builtin</TT>' or `<TT>command</TT>' in
front to make sure the appropriate version of a command is called, for
example to avoid calling a shell function with the same name as an external
command.

As an example, the function generating process IDs as matches uses this
style with the <TT>processes</TT> tag to generate the IDs to complete and
the list of processes to display (if the <TT>verbose</TT> style is `true').
The list produced by the command should look like the output of the
<TT>ps</TT> command.  The first line is not displayed, but is searched for
the string `<TT>PID</TT>' (or `<TT>pid</TT>') to find the position of the
process IDs in the following lines.  If the line does not contain
`<TT>PID</TT>', the first numbers in each of the other lines are taken as the 
process IDs to complete.

Note that the completion function generally has to call the command
every time it is called.  Because of that care should be taken to
specify only commands that take a short time to run (and that will
eventually stop at all).

<A NAME="IDX1176"></A>
<DT><TT>commands</TT>
<DD>
This is used by the function completing sub-commands for the system
initialisation scripts (residing in <TT>/etc/init.d</TT> or somewhere not
too far away from that).  It's values give the default commands to
complete for those commands for which the completion function isn't
able to find them out automatically.  The default for this style are
the two strings `<TT>start</TT>' and `<TT>stop</TT>'.

<A NAME="IDX1177"></A>
<DT><TT>complete</TT>
<DD>
This is used by the <TT>_expand_alias</TT> function when invoked as a
bindable command.  If it set to `true' and the word on the command
line is not the name of an alias, matching alias names will be
completed.

<A NAME="IDX1178"></A>
<DT><TT>completer</TT>
<DD>
The strings given as the value of this style provide the names of the
completer functions to use. The available completer functions are
described in
section <A HREF="zsh_19.html#SEC115">Control Functions</A>.

Each string may be the name of a completer function or a string of the 
form `<VAR>function</VAR><TT>:</TT><VAR>name</VAR>'. In the first case the
<VAR>completer</VAR> field of the context will contain the name of the
completer without the leading underscore and with all other
underscores replaced by hyphens.  In the second case the
<VAR>function</VAR> is the name of the completer to call, but the context
will contain the <VAR>name</VAR> in the <VAR>completer</VAR> field of the
context.  If the <VAR>name</VAR> starts with a hyphen, the string for the
context will be build from the name of the completer function as in
the first case with the <VAR>name</VAR> appended to it.  For example: 


<PRE>
zstyle ':completion:*' completer _complete _complete:-foo
</PRE>

Here, completion will call the <TT>_complete</TT> completer twice, once
using `<TT>complete</TT>' and once using `<TT>complete-foo</TT>' in the
<VAR>completer</VAR> field of the context.  Normally, using the same
completer more than once makes only sense when used with the
`<VAR>functions</VAR><TT>:</TT><VAR>name</VAR>' form, because otherwise the context
name will be the same in all calls to the completer; possible
exceptions to this rule are the <TT>_ignored</TT> and <TT>_prefix</TT>
completers.

The default value for this style is <TT>_complete _ignored</TT>,
i.e. normally only completion will be done, first using the
<TT>ignored-patterns</TT> style and the <TT>$fignore</TT> array and then without 
ignoring matches.

<A NAME="IDX1179"></A>
<DT><TT>condition</TT>
<DD>
This style is used by the <TT>_list</TT> completer function to decide if
insertion of matches should be delayed unconditionally. The default is 
`true'.

<A NAME="IDX1180"></A>
<DT><TT>disabled</TT>
<DD>
If this is set to `true', the <TT>_expand_alias</TT> completer and bindable 
command will try to expand disabled aliases, too.  The default is
`<TT>false</TT>'.

<A NAME="IDX1181"></A>
<DT><TT>disable-stat</TT>
<DD>
This is used with an empty tag by the function completing for the
<TT>cvs</TT> command to decide if the <TT>zsh/stat</TT> module should be used to
generate names of modified files in the appropriate places (this is its
only use).  If set, completion will use the <TT>ls</TT> command.

<A NAME="IDX1182"></A>
<DT><TT>domains</TT>
<DD>
If set, gives the names of network domains that should be
completed.  If this is not set by the user domain names will be taken from
the file <TT>/etc/resolv.conf</TT>.

<A NAME="IDX1183"></A>
<DT><TT>expand</TT>
<DD>
This style is used when completing strings consisting of multiple
parts, such as path names.  If its
value contains the string `<TT>prefix</TT>', the partially typed word from
the line will be expanded as far as possible even if trailing parts
cannot be completed.  If it contains the string `<TT>suffix</TT>'
and normal (non-menu-) completion is used, matching names for
components after the first ambiguous one will also be added.  This
means that the resulting string is the longest unambiguous string
possible, but if menu completion is started on the list of matches
generated this way (e.g. due to the option <TT>AUTO_MENU</TT> being set),
this will also cycle through the names of the files in pathname
components after the first ambiguous one.

<A NAME="IDX1184"></A>
<DT><TT>fake-files</TT>
<DD>
This style is used when completing files and looked up 
without a tag.  Its values are of the form
`<VAR>dir</VAR><TT>:</TT><VAR>names...</VAR>'.  This will add the <VAR>names</VAR> (strings
separated by spaces) as
possible matches when completing in the directory <VAR>dir</VAR>, even if no 
such files really exist.

This can be useful on systems that support special filesystems whose
top-level pathnames can not be listed or generated with glob patterns.
It can also be used for directories for which one does not have read
permission.

<A NAME="IDX1185"></A>
<DT><TT>fake-parameters</TT>
<DD>
This is used by the completion function generating parameter names as
matches.  Its values are names of parameters which might not yet be
set, but which should be completed nonetheless.  Each name may also be 
followed by a colon and a string specifying the type of the parameter
(like `<TT>scalar</TT>', `<TT>array</TT>' or `<TT>integer</TT>').  If such a type is
given, the name will only be completed if parameters of that type are
requested in the particular context.  Names for which no type is
specified will always be completed.

<A NAME="IDX1186"></A>
<DT><TT>file-patterns</TT>
<DD>
In most places where filenames are completed, the function <TT>_files</TT>
is used which can be configured with this style.  If the style is
unset, <TT>_files</TT> offers, one after another, up to three tags:
`<TT>globbed-files</TT>',
`<TT>directories</TT>' and `<TT>all-files</TT>', depending on the types of files
expected by the caller of <TT>_files</TT>.

If the <TT>file-patterns</TT> style is set, the default tags are not
used.  Instead, the value of the style says which tags and which
patterns are to be offered.  The strings in the value contain
specifications of the form
`<VAR>pattern</VAR><TT>:</TT><VAR>tag</VAR>'; each string may contain any number of
such specifications.  The <VAR>pattern</VAR> gives a glob 
pattern that is to be used to generate
filenames.  If it contains the sequence `<TT>%p</TT>', that is replaced by
the pattern(s) given by the calling function.
Colons in the pattern must be preceded by a backslash to
make them distinguishable from the colon before the <VAR>tag</VAR>.  If more
than one pattern is needed, the patterns can be given inside braces,
separated by commas.  The
<VAR>tag</VAR>s of all strings in the value will be offered by <TT>_files</TT>
(again, one after another) and used when looking up other styles.  For
strings containing more than one specification, the filenames for all
specifications will be generated at the same try.  If
no `<TT>:</TT><VAR>tag</VAR>' is given the `<TT>files</TT>' tag will be used.  The
<VAR>tag</VAR> may also be
followed by an optional second colon and a description.  If that is
given, this description will be used for the `<TT>%d</TT>' in the value of
the <TT>format</TT> style (if that is set) instead of the default
description supplied by the completion function.  If the description
given here contains itself a `<TT>%d</TT>', that is replaced with the
description supplied by the completion function.

For example, to make the <TT>rm</TT> command first complete only names of
object files and the names of all files if no object file matches
the string on the line, one would do:


<PRE>
zstyle ':completion:*:*:rm:*' file-patterns \ 
    '*.o:object-files' '%p:all-files'
</PRE>

Another interesting example is to change the default behaviour that
makes completion first offer files matching the patterns given by the
calling function, then directories and then all files.  Many people 
prefer to get both the files matching the given patterns and the
directories in the first try and all files at the second try.  To
achieve this, one could do:


<PRE>
zstyle ':completion:*' file-patterns \ 
    '%p:globbed-files *(-/):directories' '*:all-files'
</PRE>

This works even for contexts in which all files would be completed,
because <TT>_files</TT> will not try a pattern more than once and it stops
when the pattern `<TT>*</TT>' was tried.

Note also that during the execution of completion functions, the
<TT>EXTENDED_GLOB</TT> option is in effect, so the characters `<TT>#</TT>',
`<TT>~</TT>' and `<TT>^</TT>' have special meanings in the patterns.

<A NAME="IDX1187"></A>
<DT><TT>file-sort</TT>
<DD>
The completion function that generates filenames as possible matches
uses this style without a tag to determine in which order the 
names should be listed and completed when using menu completion.  The
value may be one of `<TT>size</TT>' to sort them by the size of the file,
`<TT>links</TT>' to sort them by the number of links to the file,
`<TT>modification</TT>' (or `<TT>time</TT>' or `<TT>date</TT>') to sort them by the last
modification time, `<TT>access</TT>' to sort them by the last access time, or
`<TT>inode</TT>' (or `<TT>change</TT>') to sort them by the last inode change
time.  If the style is set to any other value, or is unset, files will be
sorted alphabetically by name.  If the value contains the string
`<TT>reverse</TT>', sorting is done in decreasing order.

<A NAME="IDX1188"></A>
<DT><TT>force-list</TT>
<DD>
This forces a list of completions to be shown at any point where listing is
done, even in cases where the list would usually be suppressed.
For example, normally the list is only shown if
there are at least two different matches.  By setting this style to
`<TT>always</TT>', the list will always be shown, even if there is only a
single match which is immediately accepted.  The style may also
be set to a number.  In this case the list will be shown if there are
at least that many matches, even if they would all insert the same
string.

This style is tested for the default tag and all tags used when
generating matches. This allows one to turn unconditional listing on
for certain types of matches.

<A NAME="IDX1189"></A>
<DT><TT>format</TT>
<DD>
If this is set for the <TT>descriptions</TT> tag, its value is used as a
string to display above matches in completion lists.  The sequence
`<TT>%d</TT>' in this string will be replaced with a short description of
what these matches are.  This string may also contain the sequences to
specify output attributes, such as `<TT>%B</TT>', `<TT>%S</TT>' and
`<TT>%{</TT>...<TT>%}</TT>'.

For the same purpose, this style is also tested with the tags used when
matches are generated before it is tested for the <TT>descriptions</TT>
tag.  This provides the possibility of defining different format
strings for different types of matches.

Note also that some completer functions define additional
`<TT>%</TT>'-sequences.  These are described for the completer functions that 
make use of them.

For the <TT>messages</TT> tag, this style defines a string used by some
completion functions to display messages.  Here, the `<TT>%d</TT>' is
replaced with a message given by the completion function.

Finally, when set with the <TT>warnings</TT> tag, the format string is
printed when no matches could be generated at all.  In this case the
`<TT>%d</TT>' is replaced with the descriptions for the matches that were
expected separated by spaces and the sequence `<TT>%D</TT>' is replaced with
those descriptions separated by newlines.

The `<TT>%</TT>' for the sequences that are replaced by strings provided by 
the completion functions like the `<TT>%d</TT>' may be followed by field
width specifications as  described for the <TT>zformat</TT> builtin command
from the <TT>zsh/zutil</TT> module, see
section <A HREF="zsh_21.html#SEC161">The zsh/zutil Module</A>.

<A NAME="IDX1190"></A>
<DT><TT>glob</TT>
<DD>
This is used by the <TT>_expand</TT> completer.  If
it is set to `true' (the default), globbing will be attempted on the
words resulting from substitution (see the <TT>substitute</TT> style) or
the original string from the line.

<A NAME="IDX1191"></A>
<DT><TT>global</TT>
<DD>
If this is set to `true' (the default), the <TT>_expand_alias</TT>
completer and bindable command will try to expand global aliases.

<A NAME="IDX1192"></A>
<DT><TT>group-name</TT>
<DD>
The completion system can put different types of matches in different
groups which are then displayed separately in the list of possible
completions.  This style can be used to give the names for these groups
for particular tags.  For example, in command position the completion
system generates names of builtin and external commands, names of
aliases, shell functions and parameters and reserved words as possible
completions.  To have the external commands and shell functions listed
separately, one can set:


<PRE>
zstyle ':completion:*:*:-command-:*:commands' group-name commands
zstyle ':completion:*:*:-command-:*:functions' group-name functions
</PRE>

This also means that if the same name is used for different types of
matches, then those matches will be displayed together in the same
group.

If the name given is the empty string, then the name of the tag for
the matches will be used as the name of the group. So, to have all
different types of matches displayed separately, one can just set:


<PRE>
zstyle ':completion:*' group-name ''
</PRE>

All matches for which no group name is defined will be put in a group
named <TT>-default-</TT>.

<A NAME="IDX1193"></A>
<DT><TT>group-order</TT>
<DD>
This style is to be used together with the <TT>group-name</TT> style.  Once
different types of matches are put into different groups, this style
can be used to define in which order these groups should appear when listing 
(compare <TT>tag-order</TT>, which determines which completions appear at
all).  The strings in the value are taken as group names and the named
groups will be shown in the order in which their names appear in the
value.  All groups whose names are not given in the value of this style 
will appear in the order defined by the function generating the
matches.

For example, to have names of builtin commands, shell functions and
external commands appear in this order when completing in command
position one would set:


<PRE>
zstyle ':completion:*:*:-command-:*' group-order \ 
       builtins functions commands
</PRE>

<A NAME="IDX1194"></A>
<DT><TT>groups</TT>
<DD>
A style holding the names of the groups that should be completed. If
this is not set by the user, the group names from the YP database or
the file `<TT>/etc/group</TT>' will be used.

<A NAME="IDX1195"></A>
<DT><TT>hidden</TT>
<DD>
If this is set to one of the `true' values, the matches for the tags
for which this is set will not appear in the list; only the
description for the matches as set with the <TT>format</TT> style will be
shown.  If this is set to `<TT>all</TT>', not even the description will be
displayed.

Note that the matches will still be completed; they are just not shown 
in the list.  To avoid having matches considered as possible
completions at all, the <TT>tag-order</TT> style can be modified as described
below.

<A NAME="IDX1196"></A>
<DT><TT>hosts</TT>
<DD>
A style holding the names of hosts that should be completed. If this
is not set by the user the hostnames in `<TT>/etc/hosts</TT>' will be used.

<A NAME="IDX1197"></A>
<DT><TT>hosts-ports</TT>
<DD>
This style is used by commands that need or accept hostnames and
ports.  The strings in the value should be of the form
`<VAR>host</VAR><TT>:</TT><VAR>port</VAR>'.  These hostnames and ports are completed
depending on the information already on the line, so that if, for
example, the hostname is already typed, only those ports specified for that
host will be completed.  Multiple ports for the same host may appear.

<A NAME="IDX1198"></A>
<DT><TT>ignore-line</TT>
<DD>
This style is tested for the tags used when generating matches.  If it
is set to `true', then none of the words that are already on the line
will be considered possible completions.  If it is set to
`<TT>current</TT>', the word the cursor is on will not be considered a
possible completion.  The same happens if the value is
`<TT>current-shown</TT>', but only if the list of completions is currently
shown on the screen.  Finally, if it is set to `<TT>other</TT>' all words
except the current one will not be considered to be a possible
completion.

The values `<TT>current</TT>' and `<TT>current-shown</TT>' are a bit like the
opposite of <TT>accept-exact</TT>. They mean that only strings with
missing characters will be completed.

Note that you almost certainly don't want to set this to `true' or
`<TT>other</TT>' for a general
context such as `<TT>:completion:*</TT>'.  This is because it would disallow
completion of, for example, options multiple times even if the command
in question accepts the option more than once.

<A NAME="IDX1199"></A>
<DT><TT>ignore-parents</TT>
<DD>
The style is tested by the function completing pathnames without a tag to
determine whether to ignore
the names of directories already mentioned in the current word, or the
name of the current working directory.  The value must include one or both
of the following strings:

<DL COMPACT>

<DT><TT>parent</TT>
<DD>
The name of any directory whose path is already contained in the word on
the line is ignored.  For example, when completing after <TT>foo/../</TT>, the
directory <TT>foo</TT> will not be considered a valid completion.

<DT><TT>pwd</TT>
<DD>
The name of the current working directory will not be completed, so that,
for example, completion after <TT>../</TT> will not use the name of the current
directory.

</DL>

In addition, the value may include one or both of:

<DL COMPACT>

<DT><TT>..</TT>
<DD>
Ignore the specified directories only when the word on the line contains
the substring `<TT>../</TT>'.

<DT><TT>directory</TT>
<DD>
Ignore only when names of directories are completed, not when completing
names of files.

</DL>

Note that names of directories ignored because of one of the tests
will be ignored in the same way as the matches ignored because of the
<TT>ignored-patterns</TT> style.  I.e., by using the <TT>_ignored</TT> completer
it is possible to complete these directories nonetheless.

<A NAME="IDX1200"></A>
<DT><TT>ignored-patterns</TT>
<DD>
This style can be used to specify a list of patterns which are tested
against against the trial completions in a given context; any matching
completions will be removed from the list of possibilities.  The
<TT>_ignored</TT> completer can appear in the list of completers to produce a
list which includes these matches once more.  This is a more configurable
version of the shell parameter <TT>$fignore</TT>.

Note that during the execution of completion functions, the
<TT>EXTENDED_GLOB</TT> option is in effect, so the characters `<TT>#</TT>',
`<TT>~</TT>' and `<TT>^</TT>' have special meanings in the patterns.

<A NAME="IDX1201"></A>
<DT><TT>insert-ids</TT>
<DD>
When completing process IDs, for example as arguments to the <TT>kill</TT> and
<TT>wait</TT> builtins, completion allows the user to type the name of a
command, which will be converted to the appropriate process ID.  A problem
arises when the process name typed is not unique.  By default (or if this
style is set explicitly to `<TT>menu</TT>') the name will be converted
immediately to a set of possible IDs, and menu completion will be started
to cycle through them.  If the value of the style is `<TT>single</TT>', however,
the shell will wait until the user has typed enough to make the command
unique before converting the name to an ID; the user must type any
additional characters required.  If the value is any other string, menu
completion will be started when the string typed by the user is longer than
the common prefix of the corresponding IDs.

<A NAME="IDX1202"></A>
<DT><TT>insert-tab</TT>
<DD>
If this has one of the `true' values, the completion system will
insert a TAB character (assuming it was used to start completion) instead
of performing completion when there is no non-blank character to the left
of the cursor.  If set to `false', completion will be done even there.

The value may also contain the substrings `<TT>pending</TT>' or
`<TT>pending=</TT><VAR>val</VAR>' to make the character typed to start completion 
be inserted instead of completion being tried when there is input
pending which has not yet been processed by the shell. If a <VAR>val</VAR>
is given, completion will not be done if there are at least that many
characters of unprocessed input. This is often useful to have set when 
pasting characters into a terminal. Note however, that it relies on
the <TT>$PENDING</TT> special parameter from the <TT>zsh/zle</TT> module being set
properly which is not guaranteed on all platforms.

The default value of this style is `true' unless when completing
inside the <TT>vared</TT> builtin command, where it defaults to `false'.

<A NAME="IDX1203"></A>
<DT><TT>insert-unambiguous</TT>
<DD>
This is used by the <TT>_match</TT> and <TT>_approximate</TT> completer
functions, where the possible completions may not have a common prefix so
that menu completion is often the most useful may of choosing completions.
If the style is set to `true', the completer will start menu
completion only if no unambiguous string could be generated that is at
least as long as the original string typed by the user.  Note that the
<TT>_approximate</TT> completer uses it after setting the completer field
in the context name to one of <TT>correct-</TT><VAR>num</VAR> or
<TT>approximate-</TT><VAR>num</VAR>, where <VAR>num</VAR> is the number of errors that
were accepted.

When used for the <TT>_match</TT> completer, the style may also be set to
the string `<TT>pattern</TT>'.  This makes the pattern on the line be left
unchanged if it didn't match unambiguously.

<A NAME="IDX1204"></A>
<DT><TT>keep-prefix</TT>
<DD>
This style is used by the <TT>_expand</TT> completer.  If it is `true', the
completer will try to keep a prefix containing a tilde or parameter
expansion.  I.e., the string `<TT>~/f*</TT>' would be expanded to
`<TT>~/foo</TT>' instead of `<TT>/home/user/foo</TT>'.  If the style is set to
`<TT>changed</TT>' (the default), the prefix will only be left unchanged if
there were other changes between the expanded words and the original
word from the command line.  Any other value makes the prefix be
expanded unconditionally.

Note that with one of the `true' values, the <TT>_expand</TT> completer
returns if there is only one expansion and that is, after restoring
the original prefix, the same as the original word.  This means that
other completers will be called immediately after <TT>_expand</TT>.

<A NAME="IDX1205"></A>
<DT><TT>last-prompt</TT>
<DD>
This is used to determine if the completion code should try to put the
cursor back onto the previous command line after showing a completion
listing (as for the <TT>ALWAYS_LAST_PROMPT</TT> option).  As with several other
styles, it is tested for the <TT>default</TT> tag as well as all the possible
tags when generating matches.  The cursor will be moved back to the
previous line if this style is `true' for all types of matches added.  Note
also that this is independent of the numeric argument, unlike the
<TT>ALWAYS_LAST_PROMPT</TT> option.

<A NAME="IDX1206"></A>
<DT><TT>list</TT>
<DD>
This style is used by the <TT>_history_complete_word</TT> bindable command.
If it is set to `true' it has no effect, but if it is set to `false'
the matches will not be listed, overriding the setting of the options
that control listing behaviour, especially <TT>AUTO_LIST</TT>. Use the
context prefix `<TT>:completion:history-words</TT>'.

<A NAME="IDX1207"></A>
<DT><TT>list-colors</TT>
<DD>
If the <TT>zsh/complist</TT> module is used, this style can be used to set
color specifications as with the <TT>ZLS_COLORS</TT> and <TT>ZLS_COLOURS</TT>
parameters, which will not be honored under this completion system (see
section <A HREF="zsh_21.html#SEC136">The zsh/complist Module</A>).

If this style is set for the <TT>default</TT> tag, the strings in the value 
are taken as specifications that are to be used everywhere.  If it is
set for other tags, the specifications are used only for matches of
the type described by the tag.  For this to work best, the <TT>group-name</TT>
style must be set to an empty string.  If the <TT>group-name</TT> tag
specifies other names for the groups the matches in these groups can
be colored by using these names together with the `<TT>(group)...</TT>'
syntax described for the <TT>ZLS_COLORS</TT> and <TT>ZLS_COLOURS</TT> parameters 
and adding the specifications to the value for this style with the
<TT>default</TT> tag (although in most cases it should work by setting this 
style for the appropriate tags).

It is possible to use the same specifications set up for the GNU
version of the <TT>ls</TT> command:


<PRE>
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
</PRE>

The default colors are the same as for the GNU <TT>ls</TT> command and can be
obtained by setting the style to an empty string (i.e. <TT>''</TT>).

<A NAME="IDX1208"></A>
<DT><TT>list-packed</TT>
<DD>
Like the <TT>list-colors</TT> style, this is tested with the <TT>default</TT>
tag and all tags used when generating matches.  If it is set to `true'
for a tag, the matches added for it will be listed as if the
<TT>LIST_PACKED</TT> option were set.  If it is set to `false',
they are listed normally.

<A NAME="IDX1209"></A>
<DT><TT>list-prompt</TT>
<DD>
If this style is set for the <TT>default</TT> tag,
completion lists that don't fit on the screen can be scrolled (see
section <A HREF="zsh_21.html#SEC136">The zsh/complist Module</A>).  The value, if not the empty string, will be displayed after every
screenful and the shell will prompt for a key press; if the style is
set to the empty string,
a default prompt will be used.  The value may contain the escape sequences
`<TT>%l</TT>' or `<TT>%L</TT>', which will be replaced by the number of the last line
displayed and the total number of lines; `<TT>%m</TT>' or `<TT>%M</TT>', which will
be replaced by the number of the  last match shown and the total number of
matches; and `<TT>%p</TT>' and `<TT>%P</TT>', which will be replaced by `<TT>Top</TT>'
when at the beginning of the list, `<TT>Bottom</TT>' when at the end and the
position shown in percent of the total length otherwise.  In each of these
cases the form with the uppercase letter is replaced by a string of fixed
width, padded to the  right with spaces.  As in other prompt strings, the
escape sequences `<TT>%S</TT>', `<TT>%s</TT>', `<TT>%B</TT>', `<TT>%b</TT>', `<TT>%U</TT>',
`<TT>%u</TT>', and `<TT>%{</TT>...<TT>%}</TT>' for entering and leaving the display modes
standout, bold and underline are also available.

<A NAME="IDX1210"></A>
<DT><TT>list-rows-first</TT>
<DD>
This style is tested in the same way as the <TT>list-packed</TT> style and
determines if matches are to be listed in a rows-first fashion, as for the
<TT>LIST_ROWS_FIRST</TT> option.

<A NAME="IDX1211"></A>
<DT><TT>list-suffixes</TT>
<DD>
This style is used by the function used to complete filenames.  If
completion is attempted on a string containing multiple partially
typed pathname components and this style is set to `true', all
components starting with the first one for which more than one match
could be generated will be shown.

<A NAME="IDX1212"></A>
<DT><TT>local</TT>
<DD>
This style is used by completion functions which generate URLs as
possible matches to add suitable matches when a URL points to a
local web server, that is, one whose files are available directly on the
local file system.  Its value should consist of three strings: a
hostname, the path to the default web pages for the server and the
directory name used by a user placing web pages within their home
area.  For example, completion after `<TT>http://toast/~yousir/</TT>' will
attempt to match the name `<TT>toast</TT>' against the first argument to the
style, and if successful will look in the directory under <TT>~yousir</TT> given
by the third argument to the style for possible completions.

<A NAME="IDX1213"></A>
<DT><TT>match-original</TT>
<DD>
This is used by the <TT>_match</TT> completer.  If it is set to
<TT>only</TT>, <TT>_match</TT> will try to generate matches without inserting a
`<TT>*</TT>' at the cursor position.  If set to any other non-empty value,
it will first try to generate matches without inserting the `<TT>*</TT>'
and if that yields no matches, it will try again with the `<TT>*</TT>'
inserted.  If it is unset or set to the empty string, matching will
only be done with the `<TT>*</TT>' inserted.

<A NAME="IDX1214"></A>
<DT><TT>matcher</TT>
<DD>
This style is tested for tags used when generating matches.  Its value
is used as an match specification additional to any given by the
<TT>matcher-list</TT> style which should be in the form described in
section <A HREF="zsh_18.html#SEC103">Matching Control</A>.

<A NAME="IDX1215"></A>
<DT><TT>matcher-list</TT>
<DD>
This style is used by the main completion function to retrieve match
specifications that are to be used everywhere.  Its value should be a
list of such specifications.  The completion system will try them one
after another for each completer selected. For example, to first try
simple completion and, if that generates no matches, case-insensitive
completion one would do:


<PRE>
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
</PRE>

By default every specification replaces previous ones. If specification
is prefixed with <TT>+</TT>, it is added to the existing list. This allows
testing more general patterns without repeating the whole list every
time, as in:


<PRE>
zstyle ':completion:*' matcher-list '' '+m{a-Z}={A-Z}' '+m{A-Z}={a-z}'
</PRE>

The style allows even finer control by specifying a particular completer,
without the leading underscore, in the third field of the completion
context.  For example, if one uses the completers <TT>_complete</TT> and
<TT>_prefix</TT> but wants to try case-insensitive completion only when using
the <TT>_complete</TT> completer, one would do:


<PRE>
zstyle ':completion:*' completer _complete _prefix
zstyle ':completion:*:complete:*' matcher-list \ 
       '' 'm:{a-zA-Z}={A-Za-z}'
</PRE>

Note that the <TT>completer</TT> style allows user-defined names to 
be used in the context instead of the name of the completer.
This is useful if, for example, one wants to try
normal completion without a match specification and with
case-insensitive matching first, correction if that doesn't generate
any matches and partial-word completion if that doesn't yield any
matches either.  In this case one can give the <TT>_complete</TT>
completer more than once in the <TT>completer</TT> style and define different
match specifications for each occurrence, as in:


<PRE>
zstyle ':completion:*' completer _complete _correct _complete:foo
zstyle ':completion:*:complete:*' matcher-list \ 
    '' 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*:foo:*' matcher-list \ 
    'm:{a-zA-Z}={A-Za-z} r:|[-_./]=* r:|=*'
</PRE>

If the style is unset in any context no match specification is applied;
further, some completers such as <TT>_correct</TT> and <TT>_approximate</TT> do not
use the match specifications at all.  However, it is always safe
to use the simple form for this style (as in the first example above),
since any completers which do not use match specifications will only ever
be called once, rather than once per specification.

Since the specification-strings in this style have to be tried one after
another, it is a good idea to keep their number low.  In most cases
one to three strings (each of which may, without to large a performance 
hit, consist of more than one single match specification) will give
acceptable performance.

<A NAME="IDX1216"></A>
<DT><TT>max-errors</TT>
<DD>
This is used by the <TT>_approximate</TT> and <TT>_correct</TT> completer functions
to determine the maximum number of errors to allow.  The completer will try
to generate completions by first allowing one error, then two errors, and
so on, until either a match or matches were found or the maximum number of
errors given by this style has been reached.

If the value for this style contains the string `<TT>numeric</TT>', the 
completer function will take any numeric argument as the
maximum number of errors allowed. For example, with


<PRE>
zstyle ':completion:*:approximate:::' max-errors 2 numeric
</PRE>

two errors are allowed if no numeric argument is given, but with
a numeric argument of six (as in `<TT>ESC-6 TAB</TT>'), up to six
errors are accepted.  Hence with a value of `<TT>0 numeric</TT>', no correcting
completion will be attempted unless a numeric argument is given.

If the value contains the string `<TT>not-numeric</TT>', the completer
will <EM>not</EM> try to generate corrected
completions when given a numeric argument, so in this case the number given
should be greater than zero.  For example, `<TT>2 not-numeric</TT>' specifies that
correcting completion with two errors will usually be performed, but if a
numeric argument is given, correcting completion will not be
performed.

The default value for this style is `<TT>2 numeric</TT>'.

<A NAME="IDX1217"></A>
<DT><TT>menu</TT>
<DD>
If this is set to true in a given context, using any of the tags defined
for a given completion, menu completion will be used.  The tag
`<TT>default</TT>' can be used to set the default value, but a specific tag will take
precedence.  If none of the values found in this way is true but at least
one is set to `<TT>auto</TT>' the behaviour will be as for the <TT>AUTO_MENU</TT>
option.  Finally, if one of the values is explicitly set to false, menu
completion will be turned off even if it would otherwise be active (for
example, with the <TT>MENU_COMPLETE</TT> option).

Using the form `<TT>yes=</TT><VAR>num</VAR>', where `<TT>yes</TT>' may be any of the
true values (`<TT>yes</TT>', `<TT>true</TT>', `<TT>on</TT>' and `<TT>1</TT>') turns on
menu completion if there at least <VAR>num</VAR> matches.  Using this for one
of the `false' values (as in `<TT>no=10</TT>') makes menu completion
<EM>not</EM> be used if there are <VAR>num</VAR> or more matches.  Of course,
this is only useful when menu completion is normally used, e.g. by
setting the <TT>MENU_COMPLETE</TT> option.  The `true' values may also be
used in the form `<TT>yes=long</TT>' to turn on menu completion
if the list does not fit onto the screen.  This will start menu
completion only if normal completion was attempted, not when only the
list of possible completions was requested.  To start menu completion
even then, the value `<TT>yes=long-list</TT>' can be used.

In addition to (or instead of) the above possibilities, the value may
contain the string `<TT>select</TT>', optionally followed by an equals sign and a
number.  In this case menu selection (as defined by the <TT>zsh/complist</TT>
module) will be started.  Without the optional number, it will be started
unconditionally and with a number it will be started only if at least that
many matches are generated; if the values for more than one tag provide a
number, the smallest number is taken.  Menu selection can be turned off
explicitly by defining a value containing the string `<TT>no-select</TT>'.

It is also possible to start menu selection only if the list of
matches does not fit on the screen by using the value
`<TT>select=long</TT>'.  This will only start menu selection if the widget
invoked does completion, not simply listing as done by
<TT>delete-char-or-list</TT>; to start menu selection even here, use the value
`<TT>select=long-list</TT>'.

To turn on menu completion or menu selection when a certain number of
matches is generated <EM>or</EM> the list of matches does not fit onto the
screen, both of `<TT>yes=</TT>' and `<TT>select=</TT>' can be given twice, once
with a number and once with `<TT>long</TT>' or `<TT>long-list</TT>'.

<A NAME="IDX1218"></A>
<DT><TT>numbers</TT>
<DD>
This is used with the <TT>jobs</TT> tag.  If it is `true', the shell will
complete the job numbers instead of the shortest unambiguous strings
of the jobs' command lines.  If the value is a number, job numbers will
only be used if that many words from the job descriptions are required to
resolve ambiguities.  For example, if the value is `<TT>1</TT>', strings will
only be used if all jobs differ in the first word on their command lines.

<A NAME="IDX1219"></A>
<DT><TT>old-list</TT>
<DD>
This is used by the <TT>_oldlist</TT> completer.  If it is set to `<TT>always</TT>',
then standard widgets which perform listing will retain the current list of
matches, however they were generated; this can be turned off explicitly
with the value `<TT>never</TT>', giving the behaviour without the <TT>_oldlist</TT>
completer.  If the style is unset, or any other value, then the existing
list of completions is displayed if it is not already; otherwise, the
standard completion list is generated; this is the default behaviour of
<TT>_oldlist</TT>.  However, if there is an old list and this style contains
the name of the completer function that generated the list, then the
old list will be used even if it was generated by a widget which does
not do listing.

For example, suppose you type <TT>^Xc</TT> to use the <TT>_correct_word</TT>
widget, which generates a list of corrections for the word under the
cursor.  Usually, typing <TT>^D</TT> would generate a standard list of
completions for the word on the command line, and show that.  With
<TT>_oldlist</TT>, it will instead show the list of corrections already
generated.

As another example consider the <TT>_match</TT> completer: with the
<TT>insert-unambiguous</TT> style set to `true' it inserts only a common prefix
string, if there is any.  However, this may remove parts of the original
pattern, so that further completion could produce more matches than on the
first attempt.  By using the <TT>_oldlist</TT> completer and setting this style
to <TT>_match</TT>, the list of matches generated on the first attempt will be
used again.

<A NAME="IDX1220"></A>
<DT><TT>old-matches</TT>
<DD>
This is used by the <TT>_all_matches</TT> completer to decide if an old
list of matches should be used if one exists.  It may be set to one of 
the `true' values or to the string `<TT>only</TT>' to use such a list.  If
it is set to `<TT>only</TT>', <TT>_all_matches</TT> will only use an old list
and won't have any effect on the list of matches currently being
generated.

<A NAME="IDX1221"></A>
<DT><TT>old-menu</TT>
<DD>
This is used by the <TT>_oldlist</TT> completer.  It controls how menu
completion behaves when a completion has already been inserted and the
user types a standard completion key type such as <TT>TAB</TT>.  The default
behaviour of <TT>_oldlist</TT> is that menu completion always continues
with the existing list of completions.  If this style is set to
`false', however, a new completion is started if the old list was
generated by a different completion command; this is the behaviour without
the  <TT>_oldlist</TT> completer.

For example, suppose you type <TT>^Xc</TT> to generate a list of corrections,
and menu completion is started in one of the usual ways.  Usually, or with
this style set to <TT>false</TT>, typing <TT>TAB</TT> at this point would start
trying to complete the line as it now appears.  With <TT>_oldlist</TT>, it
instead continues to cycle through the list of corrections.

<A NAME="IDX1222"></A>
<DT><TT>original</TT>
<DD>
This is used by the <TT>_approximate</TT> and <TT>_correct</TT>
completers to decide if the original string should be added as
one possible completion.  Normally, this is done only if there are
at least two possible corrections, but if this style is set to `true', it
is always added.  Note that these completers use this style after
setting the completer field in the context name to
<TT>correct-</TT><VAR>num</VAR> or <TT>approximate-</TT><VAR>num</VAR>, where <VAR>num</VAR> is
the number of errors that were accepted.

<A NAME="IDX1223"></A>
<DT><TT>packageset</TT>
<DD>
This style is used when completing arguments of the Debian `<TT>dpkg</TT>'
program.  It contains an override for the default package set
for a given context.  For example,


<PRE>
zstyle ':completion:*:complete:dpkg:option--status-1:*' \ 
               packageset avail
</PRE>

causes available packages, rather than only installed packages,
to be completed for `dpkg --status'.

<A NAME="IDX1224"></A>
<DT><TT>path</TT>
<DD>
The function that completes color names uses this style with the 
<TT>colors</TT> tag.  The value should be the pathname of a file
containing color names in the format of an X11 <TT>rgb.txt</TT> file.  If
the style is not set but this file is found in one of various standard
locations it will be used as the default.

<A NAME="IDX1225"></A>
<DT><TT>ports</TT>
<DD>
A style holding the service names of ports to complete.  If this is
not set by the user, the service names from `<TT>/etc/services</TT>' will
be used.

<A NAME="IDX1226"></A>
<DT><TT>prefix-hidden</TT>
<DD>
This is used when matches with a common prefix are added (e.g. option
names).  If it is `true', this prefix will not be shown in the list of
matches.

The default value for this style is `false'.

<A NAME="IDX1227"></A>
<DT><TT>prefix-needed</TT>
<DD>
This, too, is used for matches with a common prefix.  If it is set to
`true' this common prefix has to be typed by the user to generate the
matches.  E.g. for options this means that the `<TT>-</TT>', `<TT>+</TT>', or
`<TT>-</TT><TT>-</TT>' has to be on the line to make option names be completed at
all.

The default style for this style is `true'.

<A NAME="IDX1228"></A>
<DT><TT>range</TT>
<DD>
This is used by the <TT>_history</TT> completer and the
<TT>_history_complete_word</TT> bindable command to decide which words
should be completed.  It may be set to a number, <VAR>N</VAR>, to say that
only the last <VAR>N</VAR> words from the history should be completed.  The
value may also be of the form `<VAR>max</VAR><TT>:</TT><VAR>slice</VAR>'.  This means
that first the last <VAR>slice</VAR> words will be completed.  If that
yields no matches, the <VAR>slice</VAR> words before those will be tried and 
so on, until either at least one match is generated or <VAR>max</VAR> words
have been tried.  The default is to complete all words from the
history at once.

<A NAME="IDX1229"></A>
<DT><TT>regular</TT>
<DD>
This style is used by the <TT>_expand_alias</TT> completer and bindable 
command.  If set to `true' (the default), regular aliases will be
expanded but only in command position.  If it is set to `false', regular
aliases will never be expanded and if it is set to the string
`<TT>always</TT>', regular aliases will be expanded even if not in command
position.

<A NAME="IDX1230"></A>
<DT><TT>remove-all-dups</TT>
<DD>
The <TT>_history_complete_word</TT> bindable command and the <TT>_history</TT>
completer use this to decide if all duplicate matches should be
removed, rather than just consecutive duplicates.

<A NAME="IDX1231"></A>
<DT><TT>select-prompt</TT>
<DD>
If this is set for the <TT>default</TT> tag, its
value will be displayed during menu selection (see the <TT>menu</TT> style
above) when the completion list does not fit on the screen as a
whole.  The same escapes as for the <TT>list-prompt</TT> style are
understood, but give the number of the match or line the mark is
on.  A default prompt is used when the value is the empty string.

<A NAME="IDX1232"></A>
<DT><TT>select-scroll</TT>
<DD>
This style is tested for the <TT>default</TT> tag and determines how a
completion list is scrolled during a menu selection (see the <TT>menu</TT>
style above) when the completion list does not fit on the screen as a
whole.  Its value should be `<TT>0</TT>' (zero) to scroll by
half-screenfuls, a positive integer to scroll by that many lines and a
negative number to scroll by the number of lines of the screen minus
that number (or plus the number, since it is negative).  The default is to
scroll by single lines.

<A NAME="IDX1233"></A>
<DT><TT>single-ignored</TT>
<DD>
This is used by the <TT>_ignored</TT> completer.  It specifies what
should be done if it can generate only one match, which is often a
special case.  If its value is `<TT>show</TT>', the single match will be
displayed but not inserted.  If the value is `<TT>menu</TT>', then the single
match and the original string are both added as matches and menu completion
is started so that one can easily select either of them.

<A NAME="IDX1234"></A>
<DT><TT>sort</TT>
<DD>
If set to `true', completion functions that generate words from the
history as possible matches sort these words alphabetically instead of
keeping them in the order in which they appear in the history (from
youngest to oldest).

This is also used by the <TT>_expand</TT> completer.  Here, if it is set to
`true', the expansions generated will always be sorted.  If it is set
to `<TT>menu</TT>', then the expansions are only sorted when they are offered 
as single strings (not in the string containing all possible
expansions).

<A NAME="IDX1235"></A>
<DT><TT>special-dirs</TT>
<DD>
Normally, the completion code will not produce the directory names
`<TT>.</TT>' and `<TT>..</TT>' as possible completions.  If this style is set to
`true', it will add both `<TT>.</TT>' and `<TT>..</TT>' as possible completions;
if it is set to `<TT>..</TT>', only `<TT>..</TT>' will be added.

<A NAME="IDX1236"></A>
<DT><TT>squeeze-slashes</TT>
<DD>
If set to `true', sequences of slashes (as in `<TT>foo//bar</TT>') will be
treated as if they were only one slash when completing pathnames.  This
is the usual behaviour of UNIX paths.  However, by default the file
completion function behaves as if there were a `<TT>*</TT>' between
the slashes.

<A NAME="IDX1237"></A>
<DT><TT>stop</TT>
<DD>
If set to `true', the <TT>_history_complete_word</TT> bindable
command will stop once when reaching the beginning or end of the
history.  Invoking <TT>_history_complete_word</TT> will then wrap around to 
the opposite end of the history.  If this style is set to `false' (the 
default), <TT>_history_complete_word</TT> will loop immediately as in a
menu completion.

<A NAME="IDX1238"></A>
<DT><TT>subst-globs-only</TT>
<DD>
This is used by the <TT>_expand</TT> completer.  If it is set to `true',
the expansion will only be used if it resulted from globbing; hence,
if expansions resulted from the use of the <TT>substitute</TT> style
described below, but these were not further changed by globbing, the
expansions will be rejected.

The default for this style is `false'.

<A NAME="IDX1239"></A>
<DT><TT>substitute</TT>
<DD>
This boolean style controls whether the <TT>_expand</TT> completer will
first try to expand all substitutions in the string (such as
`<TT>$(...)</TT>' and `<TT>${...}</TT>').

The default is `true'.

<A NAME="IDX1240"></A>
<DT><TT>suffix</TT>
<DD>
This is used by the <TT>_expand</TT> completer if the word starts with a
tilde or contains a parameter expansion. If it is set to `true', the word will
only be expanded if it doesn't have a suffix, i.e. if it is something
like `<TT>~foo</TT>' or `<TT>$foo</TT>', but not if it is `<TT>~foo/</TT>' or
`<TT>$foo/bar</TT>', unless that suffix itself contains characters eligible
for expansion.  The default for this style is `true'.

<A NAME="IDX1241"></A>
<DT><TT>tag-order</TT>
<DD>
This provides a mechanism for sorting how the tags available in a
particular context will be used.

The values for the style are sets of space-separated lists of tags.
The tags in each value will be tried at the same time; if no match is
found, the next value is used.  (See the <TT>file-patterns</TT> style for
an exception to this behavior.)

For example:


<PRE>
zstyle ':completion:*:complete:-command-:*' tag-order \ 
    'commands functions'
</PRE>

specifies that completion in command position should offer only
completions for external commands and shell functions immediately.

In addition to tag names, each string in the value may take one of the
following forms:

<DL COMPACT>

<DT><TT>-</TT>
<DD>
If any string in the value consists of only a hyphen,
then <EM>only</EM> the tags specified by the other strings in the value are
generated.  Normally all tags not explicitly selected are tried last
if the specified tags fail to generate any matches.  This means 
that a value consisting only of a single hyphen turns off completion.

<DT><TT>!</TT> <VAR>tags</VAR>...
<DD>
A string starting with an exclamation mark
specifies names of tags that are <EM>not</EM> to be used.  The effect is
the same as if all other possible tags for the context had been
listed.

<DT><VAR>tag</VAR><TT>:</TT><VAR>label</VAR> ...
<DD>
In strings not starting with an exclamation mark, it is also possible
to specify tag labels instead of only tags, where <VAR>tag</VAR> is one of
the tags offered
by the completion function for the current context and <VAR>label</VAR> is a 
name.  For this, the completion function will generate matches in the
same way as for the <VAR>tag</VAR> but it will use the <VAR>label</VAR> in place
of the tag in the context names used to look up styles.  If the
<VAR>label</VAR> starts with a hyphen, the <VAR>tag</VAR> is prepended to the
<VAR>label</VAR> to form the name used for lookup.  This can be
used to make the completion system try a certain tag more than once,
supplying different style settings for each attempt, see below for an
example.

The <VAR>label</VAR> may optionally be followed by a second colon and a
description.  This description will then be used for the `<TT>%d</TT>' in
the value of the <TT>format</TT> style instead of the default description
supplied by the completion function.  Spaces in the description have to 
be quoted by preceding them with a backslash and a `<TT>%d</TT>' appearing
in the description is replaced with the description given by the
completion function.

</DL>

In each of the cases above, the tag may also be a pattern or more than 
one pattern inside braces and separated by commas.  In this
case all of the offered tags matching the pattern(s) will be used except 
for those that are given explicitly in the same string.  There are
probably two main uses of this.  One is the case where one wants to try
one of the tags more than once, setting other styles differently for
each try, but still wants to use all the other tags without having to
repeat them all.  For example, to make completion of function names in
command position ignore all the completion functions starting with an
underscore the first time completion is tried, one could do:


<PRE>
zstyle ':completion:*:*:-command-:*' tag-order \ 
    'functions:-non-comp *' functions
zstyle ':completion:*:functions-non-comp' ignored-patterns '_*'
</PRE>

Here, the completion system will first try all tags offered, but will
use the tag label <TT>functions-non-comp</TT> when looking up styles for
the function names completed.  For this, the <TT>ignored-patterns</TT> style 
is set to exclude functions starting with an underscore from the set
of possible matches.  If none of the generated matches match the string 
on the line, the completion system will use the second value of the
<TT>tag-order</TT> style and complete functions names again, but this time
using the name <TT>functions</TT> to look up styles, so that the
<TT>ignored-patterns</TT> style is not used and all function names
are considered.

Of course, this can also be used to split the matches for one tag into 
different groups. For example:


<PRE>
zstyle ':completion:*' tag-order \ 
    'options:-long:long\ options
     options:-short:short\ options
     options:-single-letter:single\ letter\ options'

zstyle ':completion:*:options-long' ignored-patterns '[-+](|-|[^-]*)'
zstyle ':completion:*:options-short' ignored-patterns '--*' '[-+]?'
zstyle ':completion:*:options-single-letter' ignored-patterns '???*'
</PRE>

With the <TT>group-names</TT> style set, this makes options beginning with
`<TT>-</TT><TT>-</TT>', options beginning with a single `<TT>-</TT>' or `<TT>+</TT>' but
containing multiple characters, and single-letter options be displayed
in separate groups with different descriptions.

The second interesting use of patterns is the case where one wants to
try multiple match specifications one after another.  The
<TT>matcher-list</TT> style offers something similar, but it is tested very
early in the completion system and hence can't be set for single
commands nor for more specific contexts.  Here is how to
try normal completion without any match specification and, if that
generates no matches, try again with case-insensitive matching, restricting
the effect to arguments of the command <TT>foo</TT>:

<PRE>
zstyle ':completion:*:*:foo:*' tag-order '*' '*:-case'
zstyle ':completion:*-case' matcher 'm:{a-z}={A-Z}'
</PRE>

First, all the tags offered when completing after <TT>foo</TT> are tried using
the normal tag name.  If that generates no matches, the second value of
<TT>tag-order</TT> is used, which tries all tags again except that this time
each has <TT>-case</TT> appended to its name for lookup of styles.  Hence this
time the value for the <TT>matcher</TT> style from the second call to <TT>zstyle</TT>
in the example is used to make completion case-insensitive.

Using the <TT>-e</TT> option of the <TT>zstyle</TT> builtin command, it is
possible to specify conditions saying when certain tags are to be
used. For example:


<PRE>
zstyle -e '*:-command-:*' tag-order '
    if [[ -n $PREFIX ]]; then
      reply=( )
    else
      reply=( - )
    fi'
</PRE>

Makes completion in command position happen only if the string on 
the line is not empty.  This is tested using the <TT>PREFIX</TT>
parameter which is special in completion widgets; see
section <A HREF="zsh_18.html#SEC98">Completion Widgets</A>
for a description of these special parameters.
Setting <TT>reply</TT> to an empty array ensures that only the default
behaviour of trying all tags at once is used and setting it to an
array containing only a hyphen disables that default behaviour -- thus 
keeping all tags from being tried.

If no style has been defined for a context, the strings
`<TT>(|*-)argument-* (|*-)option-* values</TT>' and `<TT>options</TT>' plus all
tags offered by the completion function will be used to provide a
sensible default behavior that causes arguments (whether normal command
arguments or arguments of options) to be completed before option names for
most commands.

<A NAME="IDX1242"></A>
<DT><TT>urls</TT>
<DD>
This is used together with the the <TT>urls</TT> tag by completion
functions that generate URLs as possible matches.  If the value
consists of more than one string or if the only string does not name a 
file or directory, the strings are used as the URLs to complete.

If the value contains only one string and that is the name of a normal 
file, the URLs are taken from that file (where the URLs may be
separated by white space or newlines).

Finally, if the only string in the value names a directory, that
should contain sub-directories named after the
retrieval methods which occur as the first part of a URL, i.e.
`<TT>http</TT>', `<TT>ftp</TT>', `<TT>bookmark</TT>', and so on.  These
sub-directories should contain files and other sub-directories whose
pathnames are possible completions after the initial `<TT>http://</TT>',
`<TT>ftp://</TT>', etc. See the description in the file <TT>_urls</TT> in the
<TT>User</TT> sub-directory of the completion system for more information.

<A NAME="IDX1243"></A>
<DT><TT>use-cache</TT>
<DD>
If this is set, the completion caching layer is activated for any completions
which use it (via the <TT>_store_cache</TT>, <TT>_retrieve_cache</TT>, and
<TT>_cache_invalid</TT> functions).  The directory containing the cache
files can be changed with the <TT>cache-path</TT> style.

<A NAME="IDX1244"></A>
<DT><TT>use-compctl</TT>
<DD>
If this style is set to a string <EM>not</EM> equal to <TT>false</TT>, <TT>0</TT>,
<TT>no</TT>, and <TT>off</TT>, the completion system may use any completion
specifications defined with the <TT>compctl</TT> builtin command.  If the
style is unset, this is done only if the <TT>zsh/compctl</TT> module
is loaded.  The string may also contain the substring `<TT>first</TT>' to
make the definition for `<TT>compctl -T</TT>' be used, and the substring
`<TT>default</TT>' to make the one for `<TT>compctl -D</TT>' be used.

Note that this is only intended to smooth the transition from
<TT>compctl</TT> to the new completion system and may disappear in the
future.

Note also that the definitions from <TT>compctl</TT> will only be used if
there is no specific completion function for the command in question.  For
example, while completing arguments to the command <TT>foo</TT>, if this was
handled by a command function <TT>_foo</TT>, <TT>compctl</TT> would never be tried,
while if it was handled by <TT>_default</TT>, <TT>compctl</TT> would be tried.

<A NAME="IDX1245"></A>
<DT><TT>users</TT>
<DD>
This may be set to a list of names that should be completed whenever 
a username is needed. If it is not set or the string on the line
doesn't match any of the strings in this list, all usernames will be
completed.

<A NAME="IDX1246"></A>
<DT><TT>users-hosts</TT>
<DD>
The values of this style should be of the form
`<VAR>user</VAR><TT>@</TT><VAR>host</VAR>' or `<VAR>user</VAR><TT>:</TT><VAR>host</VAR>'. It is used for
commands that need pairs of
user- and hostnames.  For such commands, only the pairs from this style 
are used and if, for example, the username is already typed, then only 
the hostnames for which there is a pair with that username is defined.

If set for the <TT>my-accounts</TT> tag, this is used for commands such as
<TT>rlogin</TT> and <TT>ssh</TT>; in this case the style should contain the names of
the user's own accounts on remote hosts.  If set for the <TT>other-accounts</TT>
tag, it is used for commands such as <TT>talk</TT> and <TT>finger</TT> and should
contain other people's accounts.  Finally, it may also be used by some
commands with the <TT>accounts</TT> tag.

<A NAME="IDX1247"></A>
<DT><TT>users-hosts-ports</TT>
<DD>
Like <TT>users-hosts</TT> but used for commands like <TT>telnet</TT> and
containing strings of the form `<VAR>user</VAR><TT>@</TT><VAR>host</VAR><TT>:</TT><VAR>port</VAR>'.

<A NAME="IDX1248"></A>
<DT><TT>verbose</TT>
<DD>
This is used in several contexts to decide if only a simple or a
verbose list of matches should be generated. For example some commands 
show descriptions for option names if this style is `true'.

The default value for this style is `true'.

<A NAME="IDX1249"></A>
<DT><TT>word</TT>
<DD>
This is used by the <TT>_list</TT> completer, which prevents the insertion of
completions until a second completion attempt when the line has not
changed.  The normal way of finding out if the line has changed is to
compare its entire contents between the two occasions.  If this style is
true, the comparison is instead performed only on the current word.
Hence if completion is performed on another word with the same contents,
completion will not be delayed.

</DL>

<P>




<H2><A NAME="SEC115" HREF="zsh_toc.html#TOC115">Control Functions</A></H2>
<P>
<A NAME="IDX1250"></A>


<P>
The initialization script <TT>compinit</TT> redefines all the widgets
which perform completion to call the supplied widget function
<TT>_main_complete</TT>.  This function acts as a wrapper calling the
so-called `completer' functions that generate matches.  If
<TT>_main_complete</TT> is called with arguments, these are taken as the
names of completer functions to be called in the order given.  If no
arguments are given, the set of functions to try is taken from the
<TT>completer</TT> style.  For example, to use normal completion and
correction if that doesn't generate any matches:


<P>

<PRE>
zstyle ':completion:*' completer _complete _correct
</PRE>

<P>
after calling <TT>compinit</TT>. The default value for this style is
`<TT>_complete _ignored</TT>', i.e. normally only ordinary completion is tried,
first with the effect of the <TT>ignored-patterns</TT> style and then without
it.  The <TT>_main_complete</TT> function uses the return value of the completer
functions to decide if other completers should be called.  If the return
value is zero, no other completers are tried and the <TT>_main_complete</TT>
function returns.


<P>
If the first argument to <TT>_main_complete</TT> is a single hyphen, the
arguments will not be taken as names of completers. Instead, the
second argument gives a name to use in the <VAR>completer</VAR> field of the 
context and the other arguments give a command name and arguments to
call to generate the matches.


<P>
The following completer functions are contained in the distribution (users
may write their own):


<P>
<A NAME="IDX1251"></A>
<DL COMPACT>

<DT><TT>_all_matches</TT>
<DD>
<A NAME="IDX1252"></A>
 
This completer can be used to add a string consisting of all other
matches.  To ensure, that this string is always added, this completer
has to be used as the first completer in the list.  The
<TT>avoid-completer</TT> style is used to decide if the string should be
added.  This will only be done if the matches were generated by a
completer not named by one of the values of the style.

This function also uses the style <TT>old-matches</TT>.  If it is set to
`true' or to the string `<TT>only</TT>' and there is a list of matches from 
a previous completion, those matches will be inserted in the command
line.  If it is set to the the string `<TT>only</TT>', it will only insert
an old list and won't add the string for all matches of the list
currently being generated.

With the <TT>old-matches</TT> style set, this completer should probably not 
be called unconditionally.  Instead one could use the <TT>-e</TT> option of 
the <TT>zstyle</TT> builtin command to add a condition to the <TT>completer</TT> 
or to the <TT>old-matches</TT> style.  Alternatively, one could use the
<TT>_generic</TT> function to bind <TT>_all_matches</TT> to a separate key
binding, for example:


<PRE>
zle -C all-matches complete-word _generic
bindkey '^Xa' all-matches
zstyle ':completion:all-matches:*' old-matches only
zstyle ':completion:all-matches:*' completer _all_matches
</PRE>

<A NAME="IDX1253"></A>
<DT><TT>_approximate</TT>
<DD>
This completer function uses the <TT>_complete</TT> completer to generate
a list of strings for the context the cursor is currently in, allowing 
you to specify a maximum number of errors:  see the description of
approximate matching in
section <A HREF="zsh_13.html#SEC56">Filename Generation</A>
for how errors are counted.  The resulting list of corrected and completed
strings is then presented to the user.  The intended use of this completer
function is to try after the normal <TT>_complete</TT> completer by setting:


<PRE>
zstyle ':completion:*' completer _complete _approximate
</PRE>

This will give correcting completion if and only if
normal completion yields no possible completions.  When
corrected completions are found, the completer will normally start
menu completion allowing you to cycle through these strings.

This completer uses the tags <TT>corrections</TT> and <TT>original</TT> when
generating the possible corrections and the original string.  The
<TT>format</TT> style for the former may contain the additional sequences
`<TT>%e</TT>' and `<TT>%o</TT>' which will be replaced by the number of errors
accepted to generate the corrections and the original string,
respectively.

As with all completers, <TT>_approximate</TT> uses its name without the
underscore in the <VAR>completer</VAR> field of the context name.  Once it
has started trying to generate matches, it will append a minus sign
and the number of errors accepted to its name.  <TT>_approximate</TT> will
first look for completions with one error, then two, and on so up to the
limit on the number of errors set by the <TT>max-errors</TT> style.
Hence on the first try the completer field of the context contains
`<TT>approximate-1</TT>', on the second try `<TT>approximate-2</TT>', and so on.

When <TT>_approximate</TT> is called from another function, the number of
errors to accept may be given with the <TT>-a</TT> option.  Its argument
should be the same as the value of the <TT>max-errors</TT> style, all in one
string.

Note that this completer (and the <TT>_correct</TT> completer mentioned
below) can be quite expensive to call, especially when a large number
of errors are allowed.  One way to avoid this is to set up the
<TT>completer</TT> style using the <TT>-e</TT> option to zstyle so that some
completers are only used when completion is attempted a second time on 
the same string, e.g.:


<PRE>
zstyle ':completion:*' completer '
  if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]]; then
    _last_try="$HISTNO$BUFFER$CURSOR"
    reply=(_complete _match _prefix)
  else
    reply=(_ignored _correct _approximate)
  fi'
</PRE>

This uses the <TT>HISTNO</TT> parameter and the <TT>BUFFER</TT> and <TT>CURSOR</TT>
special parameters that are available inside zle and completion
widgets to find out if the command line hasn't changed since the last
time completion was tried.  Only then are the <TT>_ignored</TT>,
<TT>_correct</TT> and <TT>_approximate</TT> completers called.

<A NAME="IDX1254"></A>
<DT><TT>_complete</TT>
<DD>
This completer generates all possible completions in a context-sensitive
manner, i.e. using the settings defined with the <TT>compdef</TT> function
explained above and the current settings of all special parameters.
This gives the normal completion behaviour.

To complete arguments of commands, <TT>_complete</TT> uses the utility function
<TT>_normal</TT>, which is in turn responsible for finding the particular
function; it is described below.  Various contexts of the form
<TT>-</TT><VAR>context</VAR><TT>-</TT>, as mentioned above for the <TT>#compdef</TT> tag, are
handled specially.  These are:

<DL COMPACT>

<DT><TT>-array-value-</TT>
<DD>
<A NAME="IDX1255"></A>
 
for completion on the right hand side of an array-assignment
(`<TT>foo=(...)</TT>').

<A NAME="IDX1256"></A>
<DT><TT>-brace-parameter-</TT>
<DD>
for completing the name of a parameter expansion within braces
(`<TT>${...}</TT>').

<A NAME="IDX1257"></A>
<DT><TT>-command-</TT>
<DD>
for completing in a command position.

<A NAME="IDX1258"></A>
<DT><TT>-condition-</TT>
<DD>
for completion inside conditions (`<TT>[[...]]</TT>').

<A NAME="IDX1259"></A>
<DT><TT>-default-</TT>
<DD>
for generating completions when no special completion function is used.

<A NAME="IDX1260"></A>
<DT><TT>-equal-</TT>
<DD>
for completion of words beginning with an equals sign

<A NAME="IDX1261"></A>
<DT><TT>-first-</TT>
<DD>
for adding completions before any other completion functions are
tried; if this
function sets the <TT>_compskip</TT> parameter to <TT>all</TT>, no other
completion functions will be called, if it is set to a string
containing the substring <TT>patterns</TT>, no pattern completion functions
will be called, and if it is set to a string containing <TT>default</TT>
the function for the `<TT>-default-</TT>' context will not be called, but
functions defined for commands will.

<A NAME="IDX1262"></A>
<DT><TT>-math-</TT>
<DD>
for completion inside mathematical contexts, such as
`<TT>((</TT>...<TT>))</TT>'.

<A NAME="IDX1263"></A>
<DT><TT>-parameter-</TT>
<DD>
for completing the name of a parameter expansion (`<TT>$...</TT>').

<A NAME="IDX1264"></A>
<DT><TT>-redirect-</TT>
<DD>
for completion after a redirection operator.

<A NAME="IDX1265"></A>
<DT><TT>-subscript-</TT>
<DD>
for completion inside subscripts.

<A NAME="IDX1266"></A>
<DT><TT>-tilde-</TT>
<DD>
for completion after a tilde (`<TT>~</TT>') character, but before a slash.

<A NAME="IDX1267"></A>
<DT><TT>-value-</TT>
<DD>
for completion on the right hand side of an assignment.

</DL>

Default implementations are supplied for each of these
contexts, in most cases named after the context itself
(e.g. completion for the `<TT>-tilde-</TT>' context is done by the function 
named `<TT>_tilde</TT>').

Before trying to find a function for a specific context, <TT>_complete</TT> 
checks if the parameter `<TT>compcontext</TT>' is set.  If it is set to an
array, the elements are taken to be the possible matches which will be
completed using the tag `<TT>values</TT>' and the description
`<TT>value</TT>'.   If it is set to an associative array, the keys are used
as the possible completions and the values (if non-empty) are used as
descriptions for the matches.  If `<TT>compcontext</TT>' is set to a string
containing colons, it should be of
the form `<VAR>tag</VAR><TT>:</TT><VAR>descr</VAR><TT>:</TT><VAR>action</VAR>'.  In this case the
<VAR>tag</VAR> and <VAR>descr</VAR> give the tag and description to use and the
<VAR>action</VAR> says what should be completed in one of the forms
described for the <TT>_arguments</TT> utility function below.

Finally, if `<TT>compcontext</TT>' is set to a string without colons, the
value is taken as the name of the context to use and the function
defined for that context will be called.  For this purpose, there is a
special context named <TT>-command-line-</TT> that completes whole command
lines (commands and their arguments) and is not used by the completion
system itself, but has a function handling completion for it.

<A NAME="IDX1268"></A>
<DT><TT>_correct</TT>
<DD>
Generate corrections, but not completions, for the current word; this is
similar to <TT>_approximate</TT> but will not allow any number of extra
characters at the cursor as that completer does, hence this is
similar to spell-checking.  It calls <TT>_approximate</TT> but uses a
different <VAR>completer</VAR> field in the context name.

For example, with:


<PRE>
zstyle ':completion:::::' completer _complete _correct _approximate
zstyle ':completion:*:correct:::' max-errors 2 not-numeric
zstyle ':completion:*:approximate:::' max-errors 3 numeric
</PRE>

correction will accept up to two errors.  If a numeric argument is
given, correction will not be performed, but correcting completion
will be, and will accept as many errors as given by the numeric
argument.  Without a numeric argument, first correction and then
correcting completion will be tried, with the first one accepting two
errors and the second one accepting three errors.

When <TT>_correct</TT> is called as a function, the number of errors to accept
may be given following the <TT>-a</TT> option.  The argument should be the same
as the value of the <TT>accept</TT> style, all in one string.

This completer function is intended to be used without the
<TT>_approximate</TT> completer or, as in the example, just before
it.  Using it after the <TT>_approximate</TT> completer is useless since
<TT>_approximate</TT> will at least generate the corrected strings
generated by the <TT>_correct</TT> completer -- and probably more.

<A NAME="IDX1269"></A>
<DT><TT>_expand</TT>
<DD>
This completer function does not really do completion, but instead
checks if the word on the command line is eligible for expansion and,
if it is, gives detailed control over how this expansion is done.  When
using this, one should not use the <TT>expand-or-complete</TT> widget, but
instead use <TT>complete-word</TT>, as <TT>expand-or-complete</TT>
will expand the string on the line before the completion widget is
called.  Also, this completer should be called before the <TT>_complete</TT> 
completer function.

The tags used when generating expansions are <TT>all-expansions</TT> for
the string containing all possible expansions, <TT>expansions</TT> when
adding the possible expansions as single matches and <TT>original</TT> when 
adding the original string from the line.  In which order these strings 
are generated and which of these strings are generated at all can be
controlled by using the <TT>group-order</TT> style and by modifying the
<TT>tag-order</TT> style, as usual.

The format string for <TT>all-expansions</TT> and for <TT>expansions</TT> may
contain the sequence `<TT>%o</TT>' which will be replaced by the original
string from the line.

Which kind of expansion is tried is controlled by the <TT>substitute</TT>,
<TT>glob</TT> and <TT>subst-globs-only</TT> styles.

When <TT>_expand</TT> is called as a function, the different modes may be
selected with options.  The <TT>-s</TT> to <TT>substitute</TT>, <TT>-g</TT> to
<TT>glob</TT> and <TT>-o</TT> to <TT>subst-globs-only</TT>.

<A NAME="IDX1270"></A>
<DT><TT>_expand_alias</TT>
<DD>
If the word the cursor is on is an alias, it is expanded and no other
completers are called.  The types of aliases which are to be expanded can
be controlled with the <TT>regular</TT>, <TT>global</TT> and <TT>disabled</TT>
styles.

This function is also a bindable command, see
section <A HREF="zsh_19.html#SEC116">Bindable Commands</A>.

<A NAME="IDX1271"></A>
<DT><TT>_history</TT>
<DD>
Complete words from the shell's command  history.  This completer 
uses the <TT>remove-all-dups</TT>, and <TT>sort</TT> styles also used by the
<TT>_history_complete_word</TT> bindable command, see
section <A HREF="zsh_19.html#SEC116">Bindable Commands</A>
and
section <A HREF="zsh_19.html#SEC111">Completion System Configuration</A>.

<A NAME="IDX1272"></A>
<DT><TT>_ignored</TT>
<DD>
The <TT>ignored-patterns</TT> style can be set to a list of patterns which are
compared against possible completions; matching ones are removed.
With this completer those matches can be reinstated, as
if no <TT>ignored-patterns</TT> style were set.  The completer actually
generates its own list of matches; which completers are used
for this is determined in the same way as for the <TT>_prefix</TT>
completer.

The <TT>single-ignored</TT> style is used if only one
match could be generated.  It can be set to <TT>show</TT> to prevent that match 
from being displayed or inserted into the line, or it can be set to
<TT>menu</TT>, in which case the single match and the original string from the
line will be offered in a menu completion.

<A NAME="IDX1273"></A>
<DT><TT>_list</TT>
<DD>
This completer allows one to delay the insertion of matches until
completion is attempted a second time without the word on the line
being changed.  On the first attempt, only the list of matches will be
shown.  It is affected by the styles <TT>condition</TT> and <TT>word</TT>, see
section <A HREF="zsh_19.html#SEC111">Completion System Configuration</A>.

<A NAME="IDX1274"></A>
<DT><TT>_match</TT>
<DD>
This completer is intended to be used after the <TT>_complete</TT>
completer. It allows one to give patterns on the command line and
to complete all strings matching these patterns from the set of
possible completions for the context the cursor is in, without having
to set the <TT>GLOB_COMPLETE</TT> option.

Normally this will be done by taking the pattern from the line,
inserting a `<TT>*</TT>' at the cursor position and comparing the resulting
pattern with the possible completions generated.  However, if the
<TT>match-original</TT> style has a value of <TT>only</TT>, no `<TT>*</TT>' will be
inserted.  If <TT>match-original</TT> has any other non-empty string as its
value, this completer will first try to generate matches without, then
with a `<TT>*</TT>' inserted at the cursor position.

The generated matches will be offered in a menu completion unless the
<TT>insert-unambiguous</TT> style is set to `true'.  In
this case menu completion will only be started if no unambiguous string
could be generated that is at least as long as the original string.
The style may also be set to the string `<TT>pattern</TT>'.  This will keep 
the pattern on the line intact as long as there isn't an unambiguous
completion with which it could be replaced.

Note that the matcher specifications defined globally or used by the
completion functions will not be used.

<A NAME="IDX1275"></A>
<DT><TT>_menu</TT>
<DD>
This completer is a simple example function implemented to show how
menu completion can be done in shell code.  It should be used as the
first completer and has the effect of making the code perform
menu completion.  Note that this is independent of the setting of the
<TT>MENU_COMPLETE</TT> option and does not work with the other
menu completion widgets such as <TT>reverse-menu-complete</TT>, or
<TT>accept-and-menu-complete</TT>.

<A NAME="IDX1276"></A>
<DT><TT>_oldlist</TT>
<DD>
This completer controls how the standard completion widgets behave
when there is an existing list of completions which may have been
generated by a special completion (i.e. a separately-bound completion
command).  It allows the ordinary completion keys to continue to use the
list of completions thus generated, instead of producing a new list of
ordinary contextual completions.
It should appear in the list of completers before any of
the widgets which generate matches.  It uses two styles: <TT>old-list</TT> and
<TT>old-menu</TT>, see
section <A HREF="zsh_19.html#SEC111">Completion System Configuration</A>.

<A NAME="IDX1277"></A>
<DT><TT>_prefix</TT>
<DD>
This completer can be used to try completion with the suffix (everything
after the cursor) ignored.  In other words, the suffix will not be
considered to be
part of the word to complete and hence does not need to be matched.  It
uses the <TT>completer</TT> style to decide which other completers to call to
try to generate matches.  If this style is unset, the list of completers
set for the current context is used -- except, of course,
the <TT>_prefix</TT> completer itself.  Furthermore, if this completer appears
more than once in the list of completers only those completers not
already tried by the last invocation of <TT>_prefix</TT> will be
called.

For example, consider this global <TT>completer</TT> style:


<PRE>
zstyle ':completion:*' completer \ 
    _complete _prefix _correct _prefix:foo
</PRE>

Here, the <TT>_prefix</TT> completer tries normal completion but ignoring the
suffix.  If that doesn't generate any matches, and neither does
the call to the <TT>_correct</TT> completer after it, <TT>_prefix</TT> will 
be called a second time and, now only trying correction with the
suffix ignored.  If you want to use <TT>_prefix</TT> as the last resort and
try only normal completion, you can use:


<PRE>
zstyle ':completion:*' completer _complete ... _prefix
zstyle ':completion::prefix:*' completer _complete
</PRE>

The <TT>add-space</TT> style is also used.  If it is set to `true' then
<TT>_prefix</TT> will insert a space between the matches generated (if any) 
and the suffix.

Note that this completer is only useful if the
<TT>COMPLETE_IN_WORD</TT> option is set; otherwise, the cursor will
be moved to the end of the current word before the completion code is
called and hence there will be no suffix.

</DL>

<P>




<H2><A NAME="SEC116" HREF="zsh_toc.html#TOC116">Bindable Commands</A></H2>
<P>
<A NAME="IDX1278"></A>


<P>
In addition to the context-dependent completions provided, which are
expected to work in an intuitively obvious way, there are a few widgets
implementing special behaviour which can be bound separately to keys.  The
following is a list of these and their default bindings.


<P>
<DL COMPACT>

<DT><TT>_bash_completions</TT>
<DD>
<A NAME="IDX1279"></A>
 
This function is used by two widgets, <TT>_bash_complete-word</TT> and
<TT>_bash_list-choices</TT>.  It exists to provide compatibility with
completion bindings in bash.  The last character of the binding determines
what is completed: `<TT>!</TT>', command names; `<TT>$</TT>', environment variables;
`<TT>@</TT>', host names; `<TT>/</TT>', file names; `<TT>~</TT>' user names.  In bash, the
binding preceded by `<TT>\e</TT>' gives completion, and preceded by `<TT>^X</TT>'
lists options.  As some of these bindings clash with standard zsh
bindings, only `<TT>\e~</TT>' and `<TT>^X~</TT>' are bound by default.  To add the
rest, the following should be added to <TT>.zshrc</TT> after <TT>compinit</TT> has
been run:


<PRE>
for key in '!' '$' '@' '/' '~'; do
  bindkey "\e$key" _bash_complete-word
  bindkey "^X$key" _bash_list-choices
done
</PRE>

This includes the bindings for `<TT>~</TT>' in case they were already bound to
something else; the completion code does not override user bindings.

<A NAME="IDX1280"></A>
<DT><TT>_correct_filename (^XC)</TT>
<DD>
Correct the filename path at the cursor position.  Allows up to six errors
in the name.  Can also be called with an argument to correct
a filename path, independently of zle; the correction is printed on
standard output.

<A NAME="IDX1281"></A>
<DT><TT>_correct_word</TT> (^Xc)
<DD>
Performs correction of the current argument using the usual contextual
completions as possible choices. This stores the string
`<TT>correct-word</TT>' in the <VAR>function</VAR> field of the context name and
then calls the <TT>_correct</TT> completer.

<A NAME="IDX1282"></A>
<DT><TT>_expand_alias (^Xa)</TT>
<DD>
This function can be used as a completer and as a bindable command.
It expands the word the cursor is on if it is an alias.  The types of
aliases expanded can be controlled with the <TT>regular</TT>, <TT>global</TT> and
<TT>disabled</TT> styles.

When used as a bindable command there is one additional feature that
can be selected by setting the <TT>complete</TT> style to `true'.  In this
case, if the word isn't the name of an alias, <TT>_expand_alias</TT> tries
to complete the word to a full alias name without expanding it (but
leaving the cursor directly after the completed word so that invoking
<TT>_expand_alias</TT> once more will expand the now-complete alias name).

<A NAME="IDX1283"></A>
<DT><TT>_expand_word (^Xe)</TT>
<DD>
Performs expansion on the current word:  equivalent to the standard
<TT>expand-word</TT> command, but using the <TT>_expand</TT> completer.  Before
calling it, the <VAR>function</VAR> field is set to `<TT>expand-word</TT>'.

<A NAME="IDX1284"></A>
<DT><TT>_generic</TT>
<DD>
This function is not defined as a widget and not bound by
default. However, it can be used to define a widget and will then
store the name of the widget in the <VAR>function</VAR> field of the context 
and call the completion system. This allows custom completion widgets
with their own set of style settings to be easily defined. For example, 
to define a widget that does normal completion and starts
menu selection, one could do:


<PRE>
zle -C foo complete-word _generic
bindkey '...' foo
zstyle ':completion:foo:*' menu yes select=1
</PRE>

<A NAME="IDX1285"></A>
<DT><TT>_history_complete_word</TT> (\e/)
<DD>
Complete words from the shell's command history. This uses the
<TT>list</TT>, <TT>remove-all-dups</TT>, <TT>sort</TT>, and <TT>stop</TT> styles.

<A NAME="IDX1286"></A>
<DT><TT>_most_recent_file (^Xm)</TT>
<DD>
Complete the name of the most recently modified file matching the pattern
on the command line (which may be blank).  If given a numeric argument
<VAR>N</VAR>, complete the <VAR>N</VAR>th most recently modified file.  Note the
completion, if any, is always unique.

<A NAME="IDX1287"></A>
<DT><TT>_next_tags</TT> (^Xn)
<DD>
This command alters the set of matches used to that for the next tag, or
set of tags, either as given by the <TT>tag-order</TT> style or as set by
default; these matches would otherwise not be available.
Successive invocations of the command cycle through all possible sets of
tags.

<A NAME="IDX1288"></A>
<DT><TT>_read_comp (^X^R)</TT>
<DD>
Prompt the user for a string, and use that to perform completion on the
current word.  There are two possibilities for the string.  First, it can
be a set of words beginning `<TT>_</TT>', for example `<TT>_files -/</TT>', in which
case the function with any arguments will be called to generate the
completions.  Unambiguous parts of the function name will be completed
automatically (normal completion is not available at this point) until a
space is typed.

Second, any other string will be passed as a set of arguments to
<TT>compadd</TT> and should hence be an expression specifying what should
be completed.

A very restricted set of editing commands is available when reading the
string:  `<TT>DEL</TT>' and `<TT>^H</TT>' delete the last character; `<TT>^U</TT>' deletes
the line, and `<TT>^C</TT>' and `<TT>^G</TT>' abort the function, while `<TT>RET</TT>'
accepts the completion.  Note the string is used verbatim as a command
line, so arguments must be quoted in accordance with standard shell rules.

Once a string has been read, the next call to <TT>_read_comp</TT> will use the
existing string instead of reading a new one.  To force a new string to be
read, call <TT>_read_comp</TT> with a numeric argument.

<A NAME="IDX1289"></A>
<DT><TT>_complete_debug (^X?)</TT>
<DD>
This widget performs ordinary completion, but captures in a temporary file
a trace of the shell commands executed by the completion system.  Each
completion attempt gets its own file.  A command to view each of these
files is pushed onto the editor buffer stack.

<A NAME="IDX1290"></A>
<DT><TT>_complete_help (^Xh)</TT>
<DD>
This widget displays information about the context names, 
the tags, and the completion functions used 
when completing at the current cursor position. If given a numeric
argument other than <TT>1</TT> (as in `<TT>ESC-2 ^Xh</TT>'), then the styles
used and the contexts for which they are used will be shown, too.

Note that the information about styles may be incomplete; it depends on the
information available from the completion functions called, which in turn
is determined by the user's own styles and other settings.

<A NAME="IDX1291"></A>
<DT><TT>_complete_tag (^Xt)</TT>
<DD>
This widget completes symbol tags created by the <TT>etags</TT> or <TT>ctags</TT>
programmes (note there is no connection with the completion system's tags)
stored in a file <TT>TAGS</TT>, in the format used by <TT>etags</TT>, or <TT>tags</TT>, in the
format created by <TT>ctags</TT>.  It will look back up the path hierarchy for
the first occurrence of either file; if both exist, the file <TT>TAGS</TT> is
preferred.  You can specify the full path to a <TT>TAGS</TT> or <TT>tags</TT> file by
setting the parameter <TT>$TAGSFILE</TT> or <TT>$tagsfile</TT> respectively.
The corresponding completion tags used are <TT>etags</TT> and <TT>vtags</TT>, after
emacs and vi respectively.

</DL>

<P>




<H2><A NAME="SEC117" HREF="zsh_toc.html#TOC117">Utility Functions</A></H2>
<P>
<A NAME="IDX1292"></A>


<P>
Descriptions follow for utility functions that may be
useful when writing completion functions.  Most of these reside in the
<TT>Base</TT> subdirectory. Like the example 
functions for commands in the distribution, the utility functions
generating matches all follow the convention of returning zero if they
generated completions and non-zero if no matching completions could be 
added.


<P>
When writing completion functions or other ZLE widgets that call
completion, it might be interesting to know about two more features
offered by the <TT>_main_complete</TT> function. The arrays
<TT>compprefuncs</TT> and <TT>comppostfuncs</TT> may be set to contain names of
functions that are to be called immediately before or after completion 
has been tried. The functions will only be called once, unless they
put themselves into the arrays again.


<P>
<DL COMPACT>

<DT><TT>_all_labels</TT> [ <TT>-12VJ</TT> ] <VAR>tag</VAR> <VAR>name</VAR> <VAR>descr</VAR> [ <VAR>command</VAR> <VAR>args</VAR> ... ]
<DD>
<A NAME="IDX1293"></A>
 
This is a convenient interface to the <TT>_next_label</TT> function below,
implementing the loop shown in the <TT>_next_label</TT> example.  The
<VAR>command</VAR> is the one that should be called to generate the matches. The
options stored in the parameter <VAR>name</VAR> will automatically be inserted
into the <VAR>args</VAR> given to the <VAR>command</VAR>.  Normally, they are put
directly after the <VAR>command</VAR>, but if one of the <VAR>args</VAR> is a single
hyphen, they are inserted directly before that. If the hyphen is the last
argument, that will be removed from the argument list before the
<VAR>command</VAR> is called. This allows <TT>_all_labels</TT> to be used in almost all
cases where the matches can be generated by a single call to the
<TT>compadd</TT> builtin command or by a call to one of the utility functions.

For example:


<PRE>
local expl
...
if _requested foo; then
  ...
  _all_labels foo expl '...' compadd ... - $matches
fi
</PRE>

Will complete the strings from the <TT>matches</TT> parameter, using
<TT>compadd</TT> with additional options which will take precedence over
those generated by <TT>_all_labels</TT>.

<A NAME="IDX1294"></A>
<DT><TT>_alternative</TT> [ <TT>-C</TT> <VAR>name</VAR> ] <VAR>specs</VAR> ...
<DD>
This function is useful in simple cases where multiple tags are available.
Essentially, it implements a loop like the one described for the <TT>_tags</TT>
function above.

The tags to use and the action to perform if a tag is requested are
described using the <VAR>specs</VAR> which are of the form:
`<VAR>tag</VAR><TT>:</TT><VAR>descr</VAR><TT>:</TT><VAR>action</VAR>'. The <VAR>tag</VAR>s are offered using
<TT>_tags</TT> and if the tag is requested, the <VAR>action</VAR> is executed with the
given description <VAR>descr</VAR>.  The <VAR>action</VAR>s supported are those used
by the <TT>_arguments</TT> function (described below), without the
`<TT>-&#62;</TT><VAR>state</VAR>' and `<TT>=</TT><VAR>...</VAR>' forms.

For example, the <VAR>action</VAR> may be a simple function call. With that
one could do:


<PRE>
_alternative \ 
    'users:user:_users' \ 
    'hosts:host:_hosts'
</PRE>

to offer usernames and hostnames as possible matches (which are
generated by the <TT>_users</TT> and <TT>_hosts</TT> functions respectively).

Note that, like <TT>_arguments</TT> this will also use <TT>_all_labels</TT> to execute 
the actions, so one doesn't need to call that explicitly unless
another tag is to be used, for example in a function called from
<TT>_alternative</TT>.

Like <TT>_tags</TT> this function supports the <TT>-C</TT> option to give a
different name for the argument context field.

<A NAME="IDX1295"></A>
<DT><TT>_arguments</TT> <VAR>spec</VAR> ...
<DD>
This function can be used to complete words on the line by describing the
options and arguments which may be passed to the command for which
completion is being performed.  The description is given as arguments to
this function, with each <VAR>spec</VAR> describing one option or normal
argument of the command.  The forms of <VAR>spec</VAR> understood are:

<DL COMPACT>

<DT><VAR>n</VAR><TT>:</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
<DT><VAR>n</VAR><TT>::</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
This describes the <VAR>n</VAR>'th normal argument.  The <VAR>message</VAR> will be 
printed above the matches generated and the <VAR>action</VAR> says what can
be completed in this position (see below).  If there are two colons
before the <VAR>message</VAR>, this describes an optional argument.  If the
<VAR>message</VAR> contains only white space, nothing will be printed above
the matches unless the action adds an explanation string itself.

<DT><TT>:</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
<DT><TT>::</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
Like the previous one, but describing the <EM>next</EM> argument. I.e. if
you want to describe all arguments a command can get, you can leave
out the numbers in the description and just use this form to describe
them one after another in the order they have to appear on the line.

<DT><TT>*:</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
<DT><TT>*::</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
<DT><TT>*:::</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
This describes how arguments (usually non-option arguments, those not
beginning with <TT>-</TT> or <TT>+</TT>) are to be completed when no description
with one of the first two forms was given. This also means that any number
of arguments can be completed.

With two colons before the <VAR>message</VAR>, the <TT>words</TT> special array and
the <TT>CURRENT</TT> special parameter are modified to refer only to the
normal arguments when the <VAR>action</VAR> is executed or evaluated.  With
three colons before the <VAR>message</VAR> they are modified to refer only to
the normal arguments covered by this description.

<DT><VAR>optspec</VAR>[<VAR>description</VAR> ...]
<DD>
This describes an option and (if <VAR>description</VAR> is given) the arguments
that have to come after the option.  If no <VAR>description</VAR> is given, this
means to offer only the option name as a possible completion in the right
places.  (Note that the brackets, above, around <VAR>description</VAR>, indicate
that zero or more <VAR>description</VAR>s may appear; but the brackets are not
themselves part of this format.  If brackets are used, they are part of
the <VAR>optspec</VAR>; see below.)

In the descriptions below, the option names represented by <VAR>optname</VAR>
are normally taken to be multi-character names, and a word from the line
is considered to contain only one option (or none).  By giving the <TT>-s</TT>
option to <TT>_arguments</TT> before the first <VAR>spec</VAR>, each <VAR>optname</VAR> is
considered to be a single character and each word from the line may
contain more than one such option letter.  However, words beginning with
two hyphens (like `<TT>-</TT><TT>-prefix</TT>') are still considered to contain only
one option name.  This allows the use of the `<TT>-s</TT>' option to describe
single-letter options together with such long option names.

The <TT>-s</TT> option may be combined with the option <TT>-w</TT> to say that more
option characters are to be expected even after an option that takes an
argument.  For example, if a command takes the options `<TT>a</TT>' and `<TT>b</TT>',
where `<TT>a</TT>' takes an argument in the next word, <TT>_arguments</TT> would
normally not complete the other option directly after `<TT>-a</TT>', but it would
allow that if given the <TT>-w</TT> option.

Similarly, the option <TT>-W</TT> may be given together with <TT>-s</TT> to force
completion of single-letter options even after options that get an
argument in the same word.  For example, if a command takes the options
`<TT>a</TT>' and `<TT>b</TT>', where `<TT>a</TT>' needs an argument in the same word,
directly after the option character, <TT>_arguments</TT> would normally only
execute the action for that argument and not offer other single-letter
options as possible completions.  If given the <TT>-W</TT> option, it will
offer other options as possible completions after executing the action
for the argument.  Note that, depending on the action, this may mean
that the other options can't really be completed, but at least they will
be listed.  For more control, use an utility function like <TT>_guard</TT> in
the argument's action.

The forms of <VAR>optspec</VAR> are:

<DL COMPACT>

<DT><TT>*</TT><VAR>optspec</VAR>
<DD>
If the option may be given more than once, a star (`<TT>*</TT>') must be
added in front of one of the following forms of <VAR>optspec</VAR>.  Otherwise,
if the option is already on the line and to the left of the cursor, it
is not offered as a possible completion again.

<DT><TT>-</TT><VAR>optname</VAR>
<DD>
<DT><TT>+</TT><VAR>optname</VAR>
<DD>
In the simplest form the <VAR>optspec</VAR> is just the option name beginning
with a minus or a plus sign, such as `<TT>-foo</TT>'.  The first argument for
the option (if any) must follow as a <EM>separate</EM> word directly after the
option.

If the command accepts the option with either a leading minus or a leading
plus sign, use either `<TT>-+</TT><VAR>optname</VAR>' or `<TT>+-</TT><VAR>optname</VAR>' to
define both variants at once.

In all the following forms, the leading `<TT>-</TT>' may be replaced or paired
with `<TT>+</TT>' in this way.

<DT><TT>-</TT><VAR>optname</VAR><TT>-</TT>
<DD>
The first argument of the option must come directly after the option name
<EM>in the same word</EM>, as in `<TT>-foo-:</TT><VAR>...</VAR>'.

<DT><TT>-</TT><VAR>optname</VAR><TT>+</TT>
<DD>
The first argument may appear immediately after <VAR>optname</VAR> in the same
word, or may instead appear as a separate word after the option.

<DT><TT>-</TT><VAR>optname</VAR><TT>=</TT>
<DD>
The argument may appear as the next word, or in same word as the option
name provided that it is separated from it by an equals sign.

<DT><TT>-</TT><VAR>optname</VAR><TT>=-</TT>
<DD>
The argument to the option must appear after an equals sign in the same
word, and may not be given in the next argument.

<DT><VAR>optspec</VAR><TT>[</TT><VAR>explanation</VAR><TT>]</TT>
<DD>
An explanation string may be appended to any of the preceding forms of
<VAR>optspec</VAR> by enclosing it in brackets, as in `<TT>-q[query operation]</TT>'.

The <TT>verbose</TT> style is used to decide if these explanation strings
should be displayed with the option in a completion listing.

If no bracketed explanation string is given but the <TT>auto-description</TT>
style is set and only one argument is described for this <VAR>optspec</VAR>, the
value of the style is displayed, with any appearance of the sequence
`<TT>%d</TT>' in it replaced by the <VAR>message</VAR> of the first <VAR>description</VAR>
that follows the <VAR>optspec</VAR>; see below.

</DL>

Note that the special meaning of a leading or trailing <TT>-</TT> or <TT>+</TT> in
<VAR>optspec</VAR> means that when the command to be completed accepts options
like `<TT>-+</TT>' or `<TT>-=</TT>', the second character has to be quoted with a
backslash, as in `<TT>-\+</TT>'.

Each <VAR>description</VAR> following an <VAR>optspec</VAR> must take one of the
following forms:

<DL COMPACT>

<DT><TT>:</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
<DT><TT>::</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
Describes a mandatory argument with one colon, or an optional argument
with two colons.  As in other forms of <VAR>spec</VAR>, the <VAR>message</VAR> will be
printed above the matches generated (unless it contains only white
space, see above) and the <VAR>action</VAR> says what can be
completed in this position.

<DT><TT>:*</TT><VAR>pattern</VAR><TT>:</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
<DT><TT>:*</TT><VAR>pattern</VAR><TT>::</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
<DT><TT>:*</TT><VAR>pattern</VAR><TT>:::</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>
<DD>
This describes multiple arguments.  Only the <EM>last</EM> description may be
given in this form.  If the <VAR>pattern</VAR> is empty (i.e., <TT>:*:</TT>), all
following words on the line are to be completed as described by the
<VAR>action</VAR>; otherwise, all words up to a word matching the <VAR>pattern</VAR>
are to be completed using the <VAR>action</VAR>.

When the <VAR>message</VAR> is preceded by two colons, the <TT>words</TT> special
array and the <TT>CURRENT</TT> special parameter are modified during the
execution or evaluation of the <VAR>action</VAR> to refer only to the words
after the option.  When preceded by three colons, they are modified to
refer only to the words covered by this description.

Note that only one such `<TT>:*</TT>'-specification is useful
and no other argument specification may be given after it.

</DL>

</DL>

To include a colon in any <VAR>optname</VAR>, <VAR>message</VAR>, or <VAR>action</VAR>
anywhere above, it has to be preceded by a backslash, as `<TT>\:</TT>'.

Each of the six forms of <VAR>spec</VAR> (yes, there are six, keep track of
the nestings) may be preceded by a list
of option names and argument numbers with which the option or argument
described is mutually exclusive.  This list is given in parentheses, as
in `<TT>(-two -three 1)-one:...</TT>' or `<TT>(-foo):...</TT>'.  In the first
example, the options `<TT>-two</TT>' and `<TT>-three</TT>' and the first
argument will not be offered as possible completions if the option
`<TT>-one</TT>' is on the line before the cursor, and in the second example
the option `<TT>-foo</TT>' will not be offered if the argument described by
the specification is on the line.

The list may also contain a single star (<TT>*</TT>) as one of its elements to
specify that the description for the rest arguments (i.e. a specification
of the form `<TT>*:...</TT>') should not be used, a colon (<TT>:</TT>) to specify
that the descriptions for all normal (non-option-) arguments should not be
used and a hyphen (<TT>-</TT>) to specify that the descriptions for all options
should not be used.  This paragraph desperately needs rewriting.

To simplify writing writing functions that call <TT>_arguments</TT> more
than once, the <VAR>specs</VAR> may also start with the character `<TT>!</TT>'
(exclamation mark) to make the spec <EM>not</EM> be completed.  However, if
this is used with one of the forms describing options, the option (and 
its arguments, if it takes any) will be understood and skipped if they 
appear on the command line.  It's just that the option itself will not
be completed. This is intended to be used with an array containing the 
options used in the first call to <TT>arguments</TT>.  The second call can
then use `<TT>\!${^global_options}</TT>' to ignore those options and
complete only the ones understood in the current context.

In every case above, the <VAR>action</VAR> determines how the possible
completions should be generated.  In places where no sensible matches can
be generated, the action should consist of only a space. This will make
the <VAR>message</VAR> be displayed but no possible completions listed. Note
that even in this case the colon at the end of the <VAR>message</VAR> is
needed. The only case where it can be left is when neither a <VAR>message</VAR>,
nor a <VAR>action</VAR> is given.

Except for the `<TT>-&#62;</TT><VAR>string</VAR>' form below, the <VAR>action</VAR> will be
executed by calling the <TT>_all_labels</TT> function to process all tag labels,
so one doesn't need to call that explicitly unless another tag is to
be used, for example in a function called in the <VAR>action</VAR>.

When only one of a fixed set of strings can be completed, the <VAR>action</VAR>
can consist of these strings as a list in parentheses, as in:


<PRE>
<TT>:foo:(foo bar baz</TT><TT>)</TT>
</PRE>

Such a list in doubled parentheses should contain strings consisting of
the string to complete followed by `<TT>\:</TT>' and a description, as in:


<PRE>
<TT>:foo:((a\:bar b\:baz</TT><TT>))</TT>
</PRE>

The matches will be listed together with their descriptions if the
<TT>description</TT> style for the <TT>values</TT> tag is set.

<A NAME="IDX1296"></A>
<A NAME="IDX1297"></A>
<A NAME="IDX1298"></A>
An <VAR>action</VAR> of the form `<TT>-&#62;</TT><VAR>string</VAR>' is used by functions
that implement a state machine. In this case, the `<VAR>string</VAR>'s (with
all leading and trailing spaces and tabs removed) of all actions that
have to be used will be stored in the global array <TT>state</TT>.  The
function returns with a non-zero return value if the cursor is not in
a position where options can be completed or if the current word could 
not be completed to an option.  But if the <TT>-R</TT> option is given to
<TT>_arguments</TT>, the function will instead return with a return
value of 300 (to make it distinguishable from other return values)
after setting the global `<TT>context</TT>', `<TT>line</TT>' and `<TT>opt_args</TT>'
parameters as described below, and without resetting any changes made
to the special parameters such as <TT>PREFIX</TT> and <TT>words</TT>.  This
enables wrapper functions around <TT>_arguments</TT> to be able to find out
if they have to make sure that the special completion parameters are
not reset when they return.

Note that this means that a function calling <TT>_arguments</TT> with at least
one action containing such a `<TT>-&#62;</TT><VAR>string</VAR>' has to declare
appropriate local parameters as in:


<PRE>
local context state line
typeset -A opt_args
</PRE>

This will ensure that <TT>_arguments</TT> does not create unused global
parameters.

<A NAME="IDX1299"></A>
A string in braces is evaluated to generate the matches and if the
<VAR>action</VAR> does not begin with an opening parentheses or brace, it
is also split into separate words and executed. If the <VAR>action</VAR>
starts with a space, this list of words will be invoked unchanged,
otherwise it will be invoked with some extra strings placed after the
first word which can be given as arguments to the <TT>compadd</TT> builtin
command and which make sure that the <VAR>message</VAR> given
in the description will be shown above the matches. These arguments
are taken from the array parameter `<TT>expl</TT>' which will be set up
before executing the <VAR>action</VAR> and hence may be used in it (normally 
in an expansion like `<TT>$expl[@]</TT>').

If the <VAR>action</VAR> starts with `<TT>= </TT>' (an equals sign followed by a
space), <TT>_arguments</TT> will insert the contents of the <VAR>argument</VAR>
field of the current context as the new first element in the <TT>words</TT> 
special array and increments the value of the <TT>CURRENT</TT> special
parameter. In other words, it inserts a dummy element in the <TT>words</TT> 
array and makes <TT>CURRENT</TT> still point to the word in that array
where the cursor is. This is only really useful when used with one of
the forms that make <TT>_arguments</TT> modify the <TT>words</TT> array to
contain only some of the words from the line, i.e. one of the argument 
description forms where the <VAR>message</VAR> is preceded by two or three
colons. For example, when the function called in the action for such
an argument itself uses <TT>_arguments</TT>, the dummy element is needed to 
make that second call to <TT>_arguments</TT> use all words from the
restricted range for argument parsing. Without the inserted dummy
element, the first word in the range would be taken (by the second
<TT>_arguments</TT>) to be the command name and hence ignored.

During the evaluation or execution of the action the array `<TT>line</TT>'
will be set to the command name and normal arguments from the command
line, i.e. to the words from the command line excluding all options
and their arguments. These are stored in the associative array
`<TT>opt_args</TT>', using the option names as keys and their arguments as
the values. For options that have more than one argument these are
given as one string, separated by colons. All colons in the original
arguments are preceded with backslashes.

The parameter `<TT>context</TT>' (set only in the calling function when
using an action of the form `<TT>-&#62;</TT><VAR>string</VAR>', not during the
evaluation of other <VAR>action</VAR>s) is set to the automatically
created context names. These are either strings of the form
`<TT>option</TT><VAR>-opt</VAR><TT>-</TT><VAR>n</VAR>' for the <VAR>n</VAR>'th argument of the
option <VAR>-opt</VAR>, or strings of the form `<TT>argument-</TT><VAR>n</VAR>' for
the <VAR>n</VAR>'th argument (for rest arguments the <VAR>n</VAR> is the string
`<TT>rest</TT>'). For example, when completing the argument of the <TT>-o</TT>
option, the name is `<TT>option-o-1</TT>' and for the second normal
(non-option-) argument it is `<TT>argument-2</TT>'.

Also, during the evaluation of the <VAR>action</VAR>, the context name in
the <TT>curcontext</TT> parameter is changed by appending the same
string that is stored in the <TT>context</TT> parameter.

It is also possible to specify multiple sets of options and
arguments with the sets separated by single hyphens.  The specifications
before the first hyphen are shared by all sets given after the first
hyphen.  The first word in every other set gives the name of the
set. This name may appear in exclusion lists in the specifications,
either alone or before one of the possible values described above
(with a `<TT>-</TT>' between the name and the rest).

For example:


<PRE>
_arguments \ 
    -a \ 
  - set1 \ 
    -c \ 
  - set2 \ 
    -d \ 
    ':arg:(x2 y2)'
</PRE>

This defines two sets. When the command line contains the option
`<TT>-c</TT>', the `<TT>-d</TT>' option and the argument will not be considered
possible completions. When it contains `<TT>-d</TT>' or an argument, the
option `<TT>-c</TT>' will not be completed any more, but if `<TT>-a</TT>' is
given, both sets will still be considered valid, because it appears
before the first hyphen, so both sets contain this option.

If the name-string is of the form `<TT>(</TT><VAR>name</VAR><TT>)</TT>' then 
all specifications in the set have an implicit exclusion list
containing the name of the set, i.e. all specifications are mutual
exclusive with all other specifications in the same set. This is
useful for defining multiple sets of options which are mutually
exclusive and in which the options are aliases for each other. E.g.:


<PRE>
_arguments \ 
    -a -b \ 
  - '(compress)' \ 
    {-c,--compress}'[compress]' \ 
  - '(uncompress)' \ 
    {-d,--decompress}'[decompress]'
</PRE>

Note that using multiple sets will be slower than using only one set
because the completion code has to parse the command line once for
every set. So more than one set should only be used if the command
syntax is too complicated. Note also that an option specification with
rest-arguments (as in `<TT>-foo:*:...</TT>') often allows the use of
multiple sets to be avoided.

To simplify the specifications for commands with standard option
parsing, the options <TT>-S</TT> and <TT>-A</TT> may be given.  With <TT>-S</TT>, no
option will be completed after a `<TT>-</TT><TT>-</TT>' on the line and this
argument will otherwise be ignored. With <TT>-A</TT>, no options will be
completed after the first non-option argument on the line.  The <TT>-A</TT> 
has to be followed by a pattern matching all strings which are not to
be taken as arguments. For example, to make <TT>_arguments</TT> stop
completing options after the first normal argument, but ignoring all
strings starting with a hyphen even if they are not described by one
of the <VAR>optspec</VAR>s, one would use: `<TT>-A "-*"</TT>'.

Another option supported is `<TT>-O</TT> <VAR>name</VAR>'. The <VAR>name</VAR> will be
taken as the name of an array and its elements will be given to
functions called to generate matches when executing the
<VAR>actions</VAR>. For example, this allows one to give options for the
<TT>compadd</TT> builtin that should be used for all <VAR>action</VAR>s.

Also, the <TT>-M</TT> option followed by a string may be given before the
first description. The string will be used as the match specification
when completing option names and values instead of the default
`<TT>r:|[_-]=* r:|=*</TT>'. 

Finally, the option <TT>-C</TT> can be given to make <TT>_arguments</TT> modify
the <TT>curcontext</TT> parameter when an action of the form
`<TT>-&#62;</TT><VAR>state</VAR>' is used. This parameter is used to keep track of
the current context and in this case it (and not the parameter
<TT>context</TT> as explained above) has to be made local to make sure that 
calling functions don't use the modified value. Also, the local
version of <TT>curcontext</TT> has to be initialised with the old value as
in:


<PRE>
local curcontext="$curcontext"
</PRE>

The function can also be made to automatically complete long options
for commands that support the `<TT>-</TT><TT>-help</TT>' option as, for example,
most of the GNU commands do. For this, the string `<TT>-</TT><TT>-</TT>' must be
given as one argument and if it is, the command from the line is
invoked with the `<TT>-</TT><TT>-help</TT>' option and its output is parsed to find
possible option names. Note that this means that you should be careful
to make sure that this feature is not used for a command that does not
support this option.

For such automatically found options that get an argument after an
`<TT>=</TT>', the function also tries
to automatically find out what should be completed as the argument.
The possible completions for option-arguments can be described with
the arguments after the `<TT>-</TT><TT>-</TT>' (which are not used as described
above). Each argument contains one description of the form
`<VAR>pattern</VAR><TT>:</TT><VAR>message</VAR><TT>:</TT><VAR>action</VAR>'. The <VAR>message</VAR> and
the <VAR>action</VAR> have the same format as for the normal option
descriptions described above. The <VAR>action</VAR> will be executed to
complete arguments of options whose description in the output of the
command from the line with the `<TT>-</TT><TT>-help</TT>' option matches the
<VAR>pattern</VAR>. For example:


<PRE>
_arguments -- '*\*:toggle:(yes no)' \ 
              '*=FILE*:file:_files' \ 
              '*=DIR*:directory:_files -/'
</PRE>

Here, `<TT>yes</TT>' and `<TT>no</TT>' will be completed as the argument of
options whose description ends in a star, file names for options that
contain the substring `<TT>=FILE</TT>' in the description, and paths for
options whose description contains `<TT>=DIR</TT>'. In fact, the last two
patterns are not needed since this function always completes files
for option descriptions containing `<TT>=FILE</TT>' and paths for option
descriptions that contain `<TT>=DIR</TT>' or `<TT>=PATH</TT>'. These builtin
patterns can be overridden by patterns given as arguments, however.

Note also that <TT>_arguments</TT> tries to find out automatically if the
argument for an option is optional. If it fails to automatically
detect this, the colon before the <VAR>message</VAR> can be doubled to tell
it about this as described for the normal option descriptions above.

If the <VAR>pattern</VAR> ends in `<TT>(-)</TT>', this will removed from the
pattern and the <VAR>action</VAR> will be used only directly after the
`<TT>=</TT>', not in the next word. I.e., this is like a normal
specification as described above using `<TT>=-</TT>'.

The option `<TT>-i</TT> <VAR>patterns</VAR>' (which must be given after the
`<TT>-</TT><TT>-</TT>') can be used to give patterns for options which should not be
completed. The patterns can be given as the name of an array parameter
or as a literal list in parentheses. E.g. `<TT>-i
"(-</TT><TT>-(en|dis)able-FEATURE*)"</TT>' will make the options
`<TT>-</TT><TT>-enable-FEATURE</TT>' and `<TT>-</TT><TT>-disable-FEATURE</TT>' be ignored. The
option `<TT>-s</TT> <VAR>pairs</VAR>' (again, after the `<TT>-</TT><TT>-</TT>') can be used to
describe option aliases. Each <VAR>pair</VAR> consists of a pattern and a
replacement. E.g. some <TT>configure</TT>-scripts describe options only as
`<TT>-</TT><TT>-enable-foo</TT>', but also accept `<TT>-</TT><TT>-disable-foo</TT>'. To allow
completion of the second form, one would use `<TT>-s "(#-</TT><TT>-enable-
-</TT><TT>-disable-)"</TT>'.

Example:


<PRE>
_arguments '-l+:left border:' \ 
           '-format:paper size:(letter A4)' \ 
           '*-copy:output file:_files::resolution:(300 600)' \ 
           ':postscript file:_files -g \*.\(ps\|eps\)' \ 
           '*:page number:'
</PRE>

This describes three options: `<TT>-l</TT>', `<TT>-format</TT>', and
`<TT>-copy</TT>'. The first one gets one argument described as `<VAR>left
border</VAR>' for which no completion will be offered because of the empty
action. The argument may come directly after the `<TT>-l</TT>' or it may be 
given as the next word on the line. The `<TT>-format</TT>' option gets one
argument (in the next word) described as `<VAR>paper size</VAR>' for which
only the strings `<TT>letter</TT>' and `<TT>A4</TT>' will be completed. The
`<TT>-copy</TT>' option differs from the first two in that it may appear
more than once on the command line and in that it accepts two
arguments. The first one is mandatory and will be completed as a
filename. The second one is optional (because of the second colon
before the description `<VAR>resolution</VAR>') and will be completed from
the strings `<TT>300</TT>' and `<TT>600</TT>'.

The last two descriptions say what should be completed as
arguments. The first one describes the first argument as a
`<VAR>postscript file</VAR>' and makes files ending in `<TT>ps</TT>' or `<TT>eps</TT>' 
be completed. The last description says that all other arguments are
`<VAR>page numbers</VAR>' but does not give possible completions.

<A NAME="IDX1300"></A>
<DT><TT>_cache_invalid</TT> <VAR>cache_identifier</VAR>
<DD>
This function returns 0 if the completions cache corresponding to the
given cache identifier needs rebuilding.  It determines this by
looking up the <TT>cache-policy</TT> style for the current context, and
if it exists, runs the function of the same name, supplying the full
path to the relevant cache file as the only argument.

Example:


<PRE>
_example_caching_policy () {
    # rebuild if cache is more than a week old
    oldp=( "$1"(Nmw+1) )
    (( $#oldp ))
}
</PRE>

<A NAME="IDX1301"></A>
<DT><TT>_call_function</TT> <VAR>return</VAR> <VAR>name</VAR> [ <VAR>args</VAR> ... ]
<DD>
If a function <VAR>name</VAR> exists, it is called with the arguments
<VAR>args</VAR>. Unless it is the empty string or a single hyphen,
<VAR>return</VAR> is taken as the name of a parameter and the return status
from the called function is stored in it.
The return value of <TT>_call_function</TT> itself is zero if the function
<VAR>name</VAR> exists and was called and non-zero otherwise.

<A NAME="IDX1302"></A>
<DT><TT>_call_program</TT> <VAR>tag</VAR> <VAR>string</VAR> ...
<DD>
This function is used in places where a command is called, making it
possible for the user to override the default command call.  It looks up
the <TT>command</TT> style with the supplied <VAR>tag</VAR>.  If the style is set, its
value is used as the command to execute.

In any case, the <VAR>string</VAR>s from the call to <TT>_call_program</TT> or from the
style are concatenated with spaces between them and the resulting
string is evaluated.  The return value is the return value of the
command called.

<A NAME="IDX1303"></A>
<DT><TT>_combination</TT> [ <TT>-s</TT> <VAR>pattern</VAR> ] <VAR>tag</VAR> <VAR>style</VAR> <VAR>specs</VAR> ... <VAR>field</VAR> <VAR>opts</VAR> ...
<DD>
This function is used to complete combinations of values such as pairs 
of hostnames and usernames.  The possible values will be taken from the 
<VAR>style</VAR> whose name is given as the second argument.  The first argument
is the <VAR>tag</VAR> to use to do the lookup.

The style name should consist of multiple parts separated by
hyphens which are then used as field names.  Known values for such
fields can be given after the second argument in arguments of the form 
`<VAR>field</VAR><TT>=</TT><VAR>pattern</VAR>'.  The first argument without an equals sign 
is taken as the name of the field for which completions should be
generated.

The matches generated will be taken from the value of the style.  These 
values should contain the possible values for the combinations where
the values for the different fields are separated by colons or
characters matching the pattern given after the <TT>-s</TT> option to
<TT>_combination</TT>; normally this is used to define character classes
like the `<TT>-s "[:@]"</TT>' used for the <TT>users-hosts</TT> style.

Only the values for the requested fields for which the patterns given
in the `<VAR>field</VAR><TT>=</TT><VAR>pattern</VAR>' match the respective fields in
the strings from the style value are generated as possible matches.

If no style with the given name is defined for the given tag but a
function named with the name of the requested field preceded by an
underscore is defined, that function will be called to generate the
matches.  This is also done if none of the strings in the value of the
style match all the patterns given as arguments.

If the same name is used for more than one field, in both the
`<VAR>field</VAR><TT>=</TT><VAR>pattern</VAR>' and the argument that gives the field
name to complete for, the number of the field (starting with one) may
be given after the fieldname, separated from it by a colon.

All arguments after the requested field name are passed to
<TT>compadd</TT> when generating matches from the style value, or to 
the functions for the fields if they are called.

<A NAME="IDX1304"></A>
<DT><TT>_contexts</TT> <VAR>names</VAR> ...
<DD>
This function looks up the definitions for the context and command
names given as arguments and calls the handler functions for them if
there is a definition (given with the <TT>compdef</TT> function).  For
example, the function completing inside subscripts might use
`<TT>_contexts -math-</TT>' to include the completions generated for
mathematical environments.

<A NAME="IDX1305"></A>
<DT><TT>_describe</TT> [ <TT>-o</TT> ] <VAR>descr</VAR> <VAR>name1</VAR> [ <VAR>name2</VAR> ] <VAR>opts</VAR> ... <TT>-</TT><TT>-</TT> ...
<DD>
This function is useful for preparing a list of command options or
arguments, together with their descriptions <VAR>descr</VAR>, as matches.
Multiple groups separated by <TT>-</TT><TT>-</TT> can be supplied, potentially with
different completion options <VAR>opts</VAR>.

The <VAR>descr</VAR> is taken as a string to display above the matches if the
<TT>format</TT> style for the <TT>descriptions</TT> tag is set.  After this come one
or two names of arrays followed by options to pass to <TT>compadd</TT>.  The
first array contains the possible completions with their descriptions in
the form `<VAR>completion</VAR><TT>:</TT><VAR>description</VAR>'.  If a second array is
given, it should have the same number of elements as the first one and the
corresponding elements are added as possible completions instead of the
<VAR>completion</VAR> strings from the first array.  The completion list will
retain the descriptions from the first array.  Finally, a set of completion
options can appear.

If the option `<TT>-o</TT>' appears before the first argument, the matches added
will be treated as option names (typically following a `<TT>-</TT>',
`<TT>-</TT><TT>-</TT>' or `<TT>+</TT>' on the command line).  This makes <TT>_describe</TT> use
the <TT>prefix-hidden</TT>, <TT>prefix-needed</TT> and <TT>verbose</TT> styles to find out
if the strings should be added at all and if the descriptions should be
shown.  Without the `<TT>-o</TT>' option, only the <TT>verbose</TT> style is used.

<TT>_describe</TT> uses the <TT>_all_labels</TT> function to generate the matches, so
it does not need to appear inside a loop over tag labels.

<A NAME="IDX1306"></A>
<DT><TT>_description</TT> [ <TT>-12VJ</TT> ] <VAR>tag</VAR> <VAR>name</VAR> <VAR>descr</VAR> [ <VAR>specs</VAR> ... ]
<DD>
This function is called before completions are added (typically by a call
to <TT>compadd</TT>); it tests various styles and arranges for any necessary
options to be passed on to <TT>compadd</TT>.  The styles are tested in the
current context using the given <VAR>tag</VAR>; options are put into the array
called <VAR>name</VAR> for passing on to <TT>compadd</TT>; the description for the
current set of matches is passed in <VAR>descr</VAR>.  The styles tested are:
<TT>format</TT> (which is first tested for the given <VAR>tag</VAR> and then for the
<TT>descriptions</TT> tag if that isn't defined), <TT>hidden</TT>, <TT>matcher</TT>,
<TT>ignored-patterns</TT> and <TT>group-name</TT> (the last are tested only for the
tag given as the first argument).  This function also calls the <TT>_setup</TT>
function which tests some more styles.

The string returned by the <TT>format</TT> style (if any) will be modified so
that the sequence `<TT>%d</TT>' is replaced by the <VAR>descr</VAR> given as the third
argument without any leading or trailing white space.  If, after
removing the white space, the <VAR>descr</VAR> is the empty string, the format
style will not be used and the options put into the <VAR>name</VAR> array will
not contain an explanation string to be displayed above the matches.  If
<TT>_description</TT> is called with more than three arguments,
the additional <VAR>specs</VAR> should be of the form `<VAR>char</VAR><TT>:</TT><VAR>str</VAR>'
and every appearance of `<TT>%</TT><VAR>char</VAR>' in the format string will be
replaced by <VAR>string</VAR>.

The options placed in the array will also make sure that the matches
are placed in a separate group, depending on the value of the
<TT>group-name</TT> style.  Normally a sorted group will be used for this
(with the `<TT>-J</TT>' option), but if an option starting with `<TT>-V</TT>',
`<TT>-J</TT>', `<TT>-1</TT>', or `<TT>-2</TT>' is given, that option will be included
in the array, so that it is possible to make the group unsorted by
giving the option `<TT>-V</TT>', `<TT>-1V</TT>', or `<TT>-2V</TT>'. 

In most cases, the function will be used like this:


<PRE>
local expl
_description files expl file
compadd "$expl[@]" - "$files[@]"
</PRE>

Note the use of the parameter <TT>expl</TT>, the hyphen, and the list of
matches.  Almost all calls to <TT>compadd</TT> within the completion system use
a similar format; this ensures that user-specified styles are correctly
passed down to the builtins which implement the internals of completion.

<A NAME="IDX1307"></A>
<DT><TT>_files</TT>
<DD>
The function <TT>_files</TT> uses the <TT>file-patterns</TT> style and calls
<TT>_path_files</TT> with all the arguments it was passed except for <TT>-g</TT> 
and <TT>-/</TT>.  These two options are used depending on the setting of the 
<TT>file-patterns</TT> style.

See <TT>_path_files</TT> below for a description of the full set of options
accepted by <TT>_files</TT>.

<A NAME="IDX1308"></A>
<DT><TT>_gnu_generic</TT>
<DD>
This function is a simple wrapper around the <TT>_arguments</TT> function
described above.  It can be used to automatically complete long
options for commands that understand the `<TT>-</TT><TT>-help</TT>' option.
It is not intended to be used from completion functions but as a
top-level completion function in its own right.  For example, to
enable option completion for the commands <TT>foo</TT> and <TT>bar</TT>, one
would call:


<PRE>
compdef _gnu_generic foo bar
</PRE>

in one of the initialization files after the call to <TT>compinit</TT>.

The default installation uses this function only to generate
completions for some GNU-commands because to complete the options, the 
command has to be called and hence it shouldn't be used if one can't
be sure that the command understands the `<TT>-</TT><TT>-help</TT>' option.

<A NAME="IDX1309"></A>
<DT><TT>_guard</TT> [ <VAR>options</VAR> ] <VAR>pattern</VAR> [ <VAR>descr</VAR> ]
<DD>
This function is intended to be used in an action of functions like
<TT>_arguments</TT>.  It returns immediately with a non-zero return value if
the string to be completed does not match the <VAR>pattern</VAR>.  If the
pattern matches, the <VAR>descr</VAR> is displayed and the function returns
zero if the word to complete is not empty and non-zero otherwise.

The <VAR>pattern</VAR> may be preceded by those options understood by
<TT>compadd</TT> that are passed down from <TT>_description</TT>, namely <TT>-M</TT>,
<TT>-J</TT>, <TT>-V</TT>, <TT>-1</TT>, <TT>-2</TT>, <TT>-n</TT>, <TT>-F</TT> and <TT>-X</TT>.  All of these
options, except <TT>-X</TT>, will be ignored.  If the <TT>-X</TT> option appears,
the description following it will be used as the string to display if
the <VAR>pattern</VAR> matches, unless the option <VAR>descr</VAR> is given to
<TT>_guard</TT> itself, which will then take precedence.

As an example, consider a command taking the options <TT>-n</TT> and
<TT>-none</TT>, where <TT>-n</TT> has to be followed by a numeric value in the
same word.  By using either of:


<PRE>
_argument '-n-:numeric value:_guard "[0-9]#"' '-none'
</PRE>

or


<PRE>
_argument '-n-: :_guard "[0-9]#" "numeric value"' '-none'
</PRE>

<TT>_arguments</TT> can be made to both display the message `<TT>numeric
value</TT>' and complete options after `<TT>-n&#60;TAB&#62;</TT>'.  If the `<TT>-n</TT>' is
already followed by one or more digits (matching the pattern given to
<TT>_guard</TT>), only the message will be displayed and if the `<TT>-n</TT>' is
followed by another character, only options are completed.

<A NAME="IDX1310"></A>
<DT><TT>_message</TT> [ -r ] <VAR>descr</VAR>
<DD>
The <VAR>descr</VAR> is used like the third
argument to the <TT>_description</TT> function. However, the resulting
string will always be shown whether or not matches were
generated. This is useful to display help texts in places where no
completions can be generated automatically.

This function also uses the <TT>format</TT> style for the <TT>messages</TT> tag in
preference to the <TT>format</TT> style for the <TT>descriptions</TT> tag. The
latter is used only if the former is unset.

If the <TT>-r</TT> option is given, no style is used and the <VAR>descr</VAR> is
used literally as the string to display. This is only used in cases
where that string is taken from some pre-processed argument list
containing an expanded description.

<A NAME="IDX1311"></A>
<DT><TT>_multi_parts</TT> <VAR>sep</VAR> <VAR>array</VAR>
<DD>
This function receives two arguments: a separator character and an
array.  As usual, the <VAR>array</VAR> may be either the
name of an array parameter or a literal array in the form
`<TT>(foo bar</TT><TT>)</TT>' (i.e. a list of words separated by white 
space in parentheses).  With these arguments, this function will
complete to strings from the array where the parts separated by the
separator character are completed independently.  For example, the
<TT>_tar</TT> function from the distribution caches the pathnames from the
tar file in an array, and then calls this function to complete these
names in the way normal filenames are completed by the
<TT>_path_files</TT> function, by using `<TT>_multi_parts</TT> <TT>/</TT>
<VAR>patharray</VAR>'.

If the <TT>-i</TT> option is present, then any time there is a unique match it
will immediately be inserted even if that requires additional separators to
be inserted as well.  When completing from a fixed set of possible
completions which are really words, this is often the expected behaviour;
however, if <TT>_multi_parts</TT> should behave like completing pathnames, the
<TT>-i</TT> option should not be used.

Like other utility functions, this function accepts the `<TT>-V</TT>',
`<TT>-J</TT>', `<TT>-1</TT>', `<TT>-2</TT>', `<TT>-n</TT>', `<TT>-f</TT>', `<TT>-X</TT>', `<TT>-M</TT>',
`<TT>-P</TT>', `<TT>-S</TT>', `<TT>-r</TT>', `<TT>-R</TT>', and `<TT>-q</TT>' options and passes
them to the <TT>compadd</TT> builtin.

<A NAME="IDX1312"></A>
<DT><TT>_next_label</TT> [ <TT>-12VJ</TT> ] <VAR>tag</VAR> <VAR>name</VAR> <VAR>descr</VAR> [ <VAR>options</VAR> ... ]
<DD>
This function should be called repeatedly to generate the tag
labels. On each call it will check if another tag label is to be used 
and, if there is at least one, zero is returned. If no more tag
labels are to be used, a non-zero status is returned.

The <TT>-12JV</TT> options and the first three arguments are given to the
<TT>_description</TT> function using the tag label instead of the first
argument as appropriate. The <VAR>options</VAR> given after the <VAR>descr</VAR>
should be other options to be used for <TT>compadd</TT> or whatever
function is to be called to add the matches. <TT>_next_label</TT> will store these 
<VAR>options</VAR> in the parameter whose <VAR>name</VAR> is given as the second
argument. This is done in such a way that the description given by the 
user to the <TT>tag-order</TT> style is preferred over the one given to
<TT>_next_label</TT>.

Note that this function must not be called without a previous call to
<TT>_tags</TT> or <TT>_requested</TT> because it uses the tag label
for the current tag found by these functions.

A normal use of this function for the tag labels of the tag <TT>foo</TT>
looks like this:


<PRE>
local expl ret=1
...
if _requested foo; then
  ...
  while _next_label foo expl '...'; do
    compadd "$expl[@]" ... &#38;&#38; ret=0
  done
  ...
fi
return ret

</PRE>

<A NAME="IDX1313"></A>
<DT><TT>_normal</TT>
<DD>
This function is used for normal command completion.  It has two tasks:
completing the first word on the command line as the name of a command, and
completing the arguments to this command.  In the second case, the name of
the command is looked up to see if special completions exists, including
completions defined for patterns which match the name.  If none is found,
completion is performed for the context <TT>-default-</TT>.

The function can also be called by other completion functions which need to
treat a range of words as a command line.  For example, the function to
complete after the pre-command specifiers such as <TT>nohup</TT> removes the
first word from the <TT>words</TT> array, decrements the <TT>CURRENT</TT> parameter,
then calls <TT>_normal</TT> again, with the effect that `<TT>nohup</TT> <VAR>cmd ...</VAR>'
is treated the same way was `<VAR>cmd ...</VAR>'.

If the command name matches a pattern, the parameter <TT>_compskip</TT> is
checked after the call to the corresponding completion function.  This has
the same effect here as in the <TT>-first-</TT> context: if it is set, no more
completion functions are called even if there are no matches so far.

<A NAME="IDX1314"></A>
<DT><TT>_options</TT>
<DD>
This can be used to complete option names.  It uses a matching
specification that ignores a leading `<TT>no</TT>', ignores underscores and 
allows the user to type upper-case letters which will match their
lower-case counterparts.  All arguments passed to this function are
propagated unchanged to the <TT>compadd</TT> builtin.

<A NAME="IDX1315"></A>
<A NAME="IDX1316"></A>
<DT><TT>_options_set</TT> and <TT>_options_unset</TT>
<DD>
These functions complete only set or unset options, with the same
matching specification used in the <TT>_options</TT> function.

Note that you need to uncomment a few lines in the <TT>_main_complete</TT>
function for these functions to work properly.  The lines in question
are used to store the option settings in effect before the completion
widget locally sets the options it needs.  Hence these options are not
generally used by the completion system.

<A NAME="IDX1317"></A>
<DT><TT>_parameters</TT>
<DD>
This should be used to complete parameter names.  <TT>_parameters</TT> can
take a <TT>-g <VAR>pattern</VAR></TT> option which specifies that only parameters
whose type matches the <VAR>pattern</VAR> should be completed.  Strings of
the same form as those returned by the <TT>t</TT> parameter expansion flag
are used here when matching the type.  All other arguments are passed
unchanged to the <TT>compadd</TT> builtin.

<A NAME="IDX1318"></A>
<DT><TT>_path_files</TT>
<DD>
The function <TT>_path_files</TT> is used throughout the completion system
to complete filenames.  It allows completion of partial paths.  For
example, the string `<TT>/u/i/s/sig</TT>' may be completed to
`<TT>/usr/include/sys/signal.h</TT>'.

The options accepted by both <TT>_path_files</TT> and <TT>_files</TT> are:

<DL COMPACT>

<DT><TT>-f</TT>
<DD>
Complete all filenames.  This is the default.

<DT><TT>-/</TT>
<DD>
Specifies that only directories should be completed.

<DT><TT>-g</TT> <VAR>pattern</VAR>
<DD>
Specifies that only files matching the <VAR>pattern</VAR> should be completed.

<DT><TT>-W</TT> <VAR>paths</VAR>
<DD>
Specifies path prefixes that are to be prepended to the string from the
line to generate the filenames but that should not be inserted in the line
or shown in a completion listing.  Here, <VAR>paths</VAR> may be the name of an
array parameter, a literal list of paths enclosed in parentheses or an
absolute pathname.

<DT><TT>-F</TT>
<DD>
This option from the <TT>compadd</TT> builtin gives direct control over which
filenames should be ignored.  If the option is not present, the
<TT>ignored-patterns</TT> style is used.

</DL>

These functions also accept the `<TT>-J</TT>', `<TT>-V</TT>', `<TT>-1</TT>',
`<TT>-2</TT>', `<TT>-n</TT>', `<TT>-X</TT>', `<TT>-M</TT>', `<TT>-P</TT>', `<TT>-S</TT>', `<TT>-q</TT>',
`<TT>-r</TT>', and `<TT>-R</TT>' options from the <TT>compadd</TT> builtin.

Finally, the <TT>_path_files</TT> function  uses the styles <TT>expand</TT>,
<TT>ambiguous</TT>, <TT>special-dirs</TT>, <TT>list-suffixes</TT> and <TT>file-sort</TT>.

<A NAME="IDX1319"></A>
<DT><TT>_regex_arguments</TT> <VAR>name</VAR> <VAR>specs</VAR> ...
<DD>
This function is a compiler to generate a completion function.  The
first argument specifies the name of the generated function while the
remaining arguments specify a completion as a set of regular
expressions with actions.  The generated function has the structure of a
finite-state machine whose states correspond to the state (i.e. the
context) of the completion. This state machine uses a command line,
which comes from the concatenation of the <TT>words</TT> array up to the
current cursor position using null characters as separators with no extra
quotation.  This is analysed and at the end the appropriate action is
executed.

Specification arguments take one of following forms, in which
metacharacters such as `<TT>(</TT>', `<TT>)</TT>', `<TT>#</TT>' and `<TT>|</TT>'
should be quoted.

<DL COMPACT>

<DT><TT>/</TT><VAR>pattern</VAR><TT>/</TT> [<TT>%</TT><VAR>lookahead</VAR><TT>%</TT>] [<TT>-</TT><VAR>guard</VAR>] [<TT>:</TT><VAR>tag</VAR><TT>:</TT><VAR>descr</VAR><TT>:</TT><VAR>action</VAR>]
<DD>
This is a primitive element, corresponding to one
state of the compiled state machine.  The state is entered if
`<TT>(#b)((#B)</TT><VAR>pattern</VAR><TT>)(#B)</TT><VAR>lookahead</VAR><TT>*</TT>' matches
the command line string.  If it matches, `<VAR>guard</VAR>' is evaluated and
its return status is examined; if this is successful, the state is entered,
otherwise the test fails and other candidates are tried.  The <VAR>pattern</VAR>
string `<TT>[]</TT>' is guaranteed never to match.

If the test succeeds and the state is entered, the left part of the
command line string matched as <VAR>pattern</VAR> is removed and the 
next state is tried, proceeding from inside to outside and from left to
right.

If no test succeeds and the remaining command line string contains no null
character, the completion target is restricted to the remainder of the
command line string and <VAR>action</VAR>s for the target are executed.
In this case, nothing is actually removed from the command line string
so that any previous or neighbouring state may also have <VAR>actions</VAR>s.
<VAR>actions</VAR>s evaluation are ordered by the <TT>tag-order</TT> style and specified
<VAR>tag</VAR> by <TT>_alternative</TT>.  So, the various formats supported by
<TT>_alternative</TT> can be used in <VAR>action</VAR>.  <VAR>descr</VAR> is used for
setting up the array parameter <TT>expl</TT>.

<DT><TT>/</TT><VAR>pattern</VAR><TT>/+</TT> [<TT>%</TT><VAR>lookahead</VAR><TT>%</TT>] [<TT>-</TT><VAR>guard</VAR>] [<TT>:</TT><VAR>tag</VAR><TT>:</TT><VAR>descr</VAR><TT>:</TT><VAR>action</VAR>]
<DD>
This is similar to `<TT>/</TT><VAR>pattern</VAR><TT>/</TT> ...' but the left part of the
command line string is also considered as part of the completion target.

<DT><TT>/</TT><VAR>pattern</VAR><TT>/-</TT> [<TT>%</TT><VAR>lookahead</VAR><TT>%</TT>] [<TT>-</TT><VAR>guard</VAR>] [<TT>:</TT><VAR>tag</VAR><TT>:</TT><VAR>descr</VAR><TT>:</TT><VAR>action</VAR>]
<DD>
This is similar to `<TT>/</TT><VAR>pattern</VAR><TT>/</TT> ...' but the <VAR>action</VAR>s of the
current and previous states are ignored even if the following state's
`<VAR>pattern</VAR>' matches the empty string.

<DT><TT>(</TT> <VAR>spec</VAR> <TT>)</TT>
<DD>
This groups <VAR>spec</VAR>s.

<DT><VAR>spec</VAR> <TT>#</TT>
<DD>
This allows any number of repetitions of <VAR>spec</VAR>.

<DT><VAR>spec</VAR> <VAR>spec</VAR>
<DD>
This represents the concatenation of two <VAR>spec</VAR>s.

<DT><VAR>spec</VAR> <TT>|</TT> <VAR>spec</VAR>
<DD>
Either of the two <VAR>spec</VAR>s can be matched.

</DL>

<A NAME="IDX1320"></A>
<DT><TT>_requested</TT> [ <TT>-12VJ</TT> ] <VAR>tag</VAR> [ <VAR>name</VAR> <VAR>descr</VAR> [ <VAR>command</VAR> <VAR>args</VAR> ... ] ]
<DD>
This function is called to decide whether a tag already registered by a
call to <TT>_tags</TT> (see below) is requested and hence completion should be
performed for it; it returns status zero if the tag is requested and
non-zero otherwise.  This will usually be done in a loop such as the
following:


<PRE>
_tags foo bar baz
while _tags; do
  if _requested foo; then
    ... # perform completion for foo
  fi
  ... # test the tags bar and baz in the same way
  ... # exit loop if matches were generated
done
</PRE>

Note that the test for whether matches were generated is not performed
until the end of the <TT>_tags</TT> loop.  This is so that the user can specify
a set of tags to be tested at the same time in the <TT>tag-order</TT>
parameter.

If the <VAR>name</VAR> and the <VAR>descr</VAR> are given, <TT>_requested</TT> calls the
<TT>_description</TT> function with these arguments, including the options.

If the <VAR>command</VAR> is given, the <TT>_all_labels</TT> function will be called
immediately with the same arguments.  This is often useful to do both the
testing of the tag, getting the description for the matches and adding the
matches at once.  For example:


<PRE>
local expl ret=1
_tags foo bar baz
while _tags; do
  _requested foo expl 'description' \ 
      compadd foobar foobaz &#38;&#38; ret=0
  ...
  (( ret )) || break
done
</PRE>

Note that this means that the <VAR>command</VAR> has to accept the options
that have to be passed down to <TT>compadd</TT>.

<A NAME="IDX1321"></A>
<DT><TT>_retrieve_cache</TT> <VAR>cache_identifier</VAR>
<DD>
This function retrieves completion information from the file given by
<VAR>cache_identifier</VAR>, stored in a directory specified by the
<TT>cache-path</TT> style (defaults to <TT>~/.zsh/cache</TT>).  The return value
is zero if retrieval was successful.  It will only attempt retrieval
if the <TT>use-cache</TT> style is set, so you can call this function
without worrying about whether the user wanted to use the caching
layer.

See <TT>_store_cache</TT> below for more details.

<A NAME="IDX1322"></A>
<DT><TT>_sep_parts</TT>
<DD>
This function is passed alternating arrays and separators as arguments.
The arrays specify completions for parts of strings to be separated by the
separators.  The arrays may be the names of array parameters or
a quoted list of words in parentheses.  For example, with the array
`<TT>hosts=(ftp news)</TT>' the call `<TT>_sep_parts '(foo bar)' @ hosts</TT>' will
complete the string  `<TT>f</TT>' to `<TT>foo</TT>' and the string `<TT>b@n</TT>' to
`<TT>bar@news</TT>'.

This function passes the `<TT>-V</TT>', `<TT>-J</TT>', `<TT>-1</TT>', `<TT>-2</TT>',
`<TT>-n</TT>', `<TT>-X</TT>', `<TT>-M</TT>', `<TT>-P</TT>', `<TT>-S</TT>', `<TT>-r</TT>', `<TT>-R</TT>',
and `<TT>-q</TT>' options and their arguments to the <TT>compadd</TT> builtin
used to add the matches.

<A NAME="IDX1323"></A>
<DT><TT>_setup</TT> <VAR>tag</VAR> [ <VAR>group</VAR> ]
<DD>
This function expects a tag as its argument and sets up the special
parameters used by the completion system appropriately for the tag,
using styles such as <TT>list-colors</TT> and <TT>last-prompt</TT>.

The optional <VAR>group</VAR> gives the name of the group in which the
matches will be placed. If it is not given, the <VAR>tag</VAR> is used as
the group name.

Note that this function is called automatically from <TT>_description</TT>
so that one normally doesn't have to call it explicitly.

<A NAME="IDX1324"></A>
<DT><TT>_store_cache</TT> <VAR>cache_identifier</VAR> <VAR>vars</VAR> ...
<DD>
This function, when combined with <TT>_retrieve_cache</TT> and
<TT>_cache_invalid</TT>, makes it easy to implement a caching layer for
your completion functions.  If a completion function needs to perform
a costly operation in order to generate data which is used to
calculate completions, you can store that data in variables, and use
this function to dump the values of those variables to a file.  Then,
if they are needed in subsequent shell invocations, they can be
retrieved quickly from that file via <TT>_retrieve_cache</TT>, avoiding the
needly for repeating the costly operation.

The <VAR>cache_identifier</VAR> specifies the file which the data should be
dumped to, and is stored in a directory specified by the
<TT>cache-path</TT> style (defaults to <TT>~/.zsh/cache</TT>).  The remaining
<VAR>vars</VAR> arguments are the variables to dump to the file.

The return value is zero if storage was successful.  The function will
only attempt storage if the <TT>use-cache</TT> style is set, so you can
call this function without worrying about whether the user wanted to
use the caching layer.

If your completion function avoids calling _retrieve_cache when it
already has the completion data in the environment, it should probably
at least call <TT>_cache_invalid</TT> to check whether this data and the
data cached on disk is still valid.

See the _perl_modules completion function for a simple example of
usage of this caching layer.

<A NAME="IDX1325"></A>
<DT><TT>_tags</TT> [ <TT>-C</TT> <VAR>name</VAR> [ <VAR>tags</VAR> ... ] ]
<DD>
If called with arguments, these are taken as the names of the tags for 
the types of matches the calling completion function can generate in
the current context.  These tags are stored internally and sorted by
using the <TT>tag-order</TT> style.  Following calls to this function
without arguments from the same function will then select the first,
second, etc. set of tags requested by the user.  To test if a certain
tag should be tried, the <TT>_requested</TT> function has to be called (see 
above).

The return value is zero if at least one of the tags is requested and
non-zero otherwise. 

This function also accepts the <TT>-C</TT> option followed by a
<VAR>name</VAR>. This name is temporarily (i.e. not visible outside
<TT>_tags</TT>) stored in the argument field of the context name in the
<TT>curcontext</TT> parameter. This allows <TT>_tags</TT> to be made to use a more
specific context name without having to change and reset the
<TT>curcontext</TT> parameter (which would otherwise have the same effect).

<A NAME="IDX1326"></A>
<DT><TT>_values</TT> <VAR>specs</VAR> ...
<DD>
This is used to complete values (strings) and their arguments or
lists of such values.  It can be used in two ways.

If the first argument is the option `<TT>-O</TT> <VAR>name</VAR>', this will be used
in the same way as by the <TT>_arguments</TT> function, in other words the
elements of the <VAR>name</VAR> array will be given to calls to <TT>compadd</TT>
and when executing an action.

Otherwise, if the first argument (or the first argument after the
`<TT>-O</TT> <VAR>name</VAR>' option if that is used) is the option `<TT>-s</TT>', the
next argument is used as the character that separates multiple values.
Thus the values completed appear in the same word on the command line,
unlike completion using <TT>_arguments</TT>.

The first argument (after the options and separator character if they
are given) is used as a string to print as a description before
listing the values.

All other arguments describe the possible values and their
arguments in the same format used for the description of options by
the <TT>_arguments</TT> function (see above).  The only differences are that
no minus or plus sign is required at the beginning, that
values can have only one argument and that those forms of actions
beginning with an equal sign are not supported.

The character separating a value from its argument can be set using the
option <TT>-S</TT> (like <TT>-s</TT>, followed by the character to use as the
separator in the next argument).  If this option is not used, the equal
sign will be used as the separator.

Example:


<PRE>
_values -s , 'description' \ 
        '*foo[bar]' \ 
        '(two)*one[number]:first count:' \ 
        'two[another number]::second count:(1 2 3)'
</PRE>

This describes three possible values: `<TT>foo</TT>', `<TT>one</TT>', and
`<TT>two</TT>'.  The first is described as `<TT>bar</TT>', takes no argument 
and may appear more than once.  The second is described as
`<TT>number</TT>', may appear more than once, and takes one mandatory
argument described as `<TT>first count</TT>' for which no action is
specified so that it will not be completed automatically.  The
`<TT>(two)</TT>' at the beginning says that if the value `<TT>one</TT>' is on
the line, the value `<TT>two</TT>' will not be considered to be a possible
completion anymore.  Finally, the last value (`<TT>two</TT>') is described
as `<TT>another number</TT>' and takes an optional argument described as
`<TT>second count</TT>' which will be completed from the strings `<TT>1</TT>',
`<TT>2</TT>', and `<TT>3</TT>'. The <TT>_values</TT> function will complete lists of
these values separated by commas.

Like <TT>_arguments</TT> this function temporarily adds another context
name component to the current context name while executing the
<VAR>action</VAR>.  Here this name is just the name of the value for which
the argument is completed.

To decide if the descriptions for the values (not those for the
arguments) should be printed, the style <TT>verbose</TT> is used.

One last difference from <TT>_arguments</TT> is that this function uses the
associative array
<TT>val_args</TT> to report values and their arguments, although otherwise this
is the same as the <TT>opt_args</TT> association used by
<TT>_arguments</TT>.  This also means that the function calling <TT>_values</TT> 
should declare the <TT>state</TT>, <TT>line</TT>, <TT>context</TT> and <TT>val_args</TT>
parameters as in:


<PRE>
local context state line
typeset -A val_args
</PRE>

when using an action of the form `<TT>-&#62;</TT><VAR>string</VAR>'.  With this
function the <TT>context</TT> parameter will be set to the name of the
value whose argument is to be completed.

Note also that <TT>_values</TT> normally adds the character used as the
separator between values as a auto-removable suffix so that users don't
have to type it themselves.  But when using a `<TT>-&#62;</TT><VAR>string</VAR>' action
<TT>_values</TT> can't do that because the matches for the argument will be
generated by the calling function.  To get the usual behaviour, the
implementor of the calling function has to add the suffix directly by
passing the options `<TT>-qS</TT> <VAR>x</VAR>' (where <VAR>x</VAR> is the separator
character specified with the <TT>-s</TT> option of <TT>_values</TT>) to the
function generating the matches or to the <TT>compadd</TT> builtin.

Like <TT>_arguments</TT>, <TT>_values</TT> supports the <TT>-C</TT> option in
which case you have to make the parameter <TT>curcontext</TT> local instead 
of <TT>context</TT> (as described above).

<A NAME="IDX1327"></A>
<DT><TT>_wanted</TT> [ <TT>-C</TT> <VAR>name</VAR> ]  [ <TT>-12VJ</TT> ] <VAR>tag</VAR> <VAR>name</VAR> <VAR>descr</VAR> <VAR>command</VAR> <VAR>args</VAR> ...
<DD>
In many contexts, completion will generate one particular set of
matches (usually corresponding to a single tag); however, it is
still necessary to decide whether the user requires matches of this type.
This function is useful in such a case.

Like <TT>_requested</TT>, it should be passed arguments as for <TT>_description</TT>.
It calls <TT>_tags</TT> with the given <VAR>tag</VAR> and if that returns zero 
(so that the <VAR>tag</VAR> is requested by the user) it calls
<TT>_description</TT>.  Hence to offer only one tag and immediately
use the description generated:


<PRE>
_wanted tag expl 'description' \ 
    compadd matches...
</PRE>

Unlike <TT>_requested</TT>, however, <TT>_wanted</TT> cannot be called without
the <VAR>command</VAR>.  This is because <TT>_wanted</TT> also implements the loop
over the tags, not just the one for the labels; conversely, it should not
be called in the middle of a <TT>_tags</TT> loop.

Note that, as for <TT>_requested</TT>, the <VAR>command</VAR> has to accept the options
that have to be passed down to <TT>compadd</TT>.

Like <TT>_tags</TT> this function supports the <TT>-C</TT> option to give a
different name for the argument context field.

</DL>

<P>




<H2><A NAME="SEC118" HREF="zsh_toc.html#TOC118">Completion Directories</A></H2>
<P>
<A NAME="IDX1328"></A>


<P>
In the source distribution, the files are contained in various
subdirectories of the <TT>Completion</TT> directory.  They may have been
installed in the same structure, or into one single function directory.
The following is a description of the files found in the original directory
structure.  If you wish to alter an installed file, you will need to copy
it to some directory which appears earlier in your <TT>fpath</TT> than the
standard directory where it appears.


<P>
<DL COMPACT>

<DT><TT>Base</TT>
<DD>
The core functions and special completion widgets automatically bound
to keys.  You will certainly need most of these, though will
probably not need to alter them.  Many of these are documented above.

<DT><TT>Zsh</TT>
<DD>
Functions for completing arguments of shell builtin commands and
utility functions for this.  Some of these are also used by functions from
the <TT>Unix</TT> directory.

<DT><TT>Unix</TT>
<DD>
Functions for completing arguments of external commands and suites of
commands.  They may need modifying for your system, although in many cases
some attempt is made to decide which version of a command is present.  For
example, completion for the <TT>mount</TT> command tries to determine the system
it is running on, while completion for many other utilities try to decide
whether the GNU version of the command is in use, and hence whether the
<TT>--help</TT> option is supported..

<DT><TT>X</TT>, <TT>AIX</TT>, <TT>BSD</TT>, ...
<DD>
Completion and utility function for commands available only on some systems.

</DL>

<P><HR><P>
Go to the <A HREF="zsh_1.html">first</A>, <A HREF="zsh_18.html">previous</A>, <A HREF="zsh_20.html">next</A>, <A HREF="zsh_29.html">last</A> section, <A HREF="zsh_toc.html">table of contents</A>.
</BODY>
</HTML>