Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > 7375059bba0ac8f9cc2547cb76737a3a > files > 111

zsh-doc-5.5-1.1.mga6.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>zsh: 20 Completion System</title>

<meta name="description" content="zsh: 20 Completion System">
<meta name="keywords" content="zsh: 20 Completion System">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2any">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Completion-System"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Completion-Widgets.html#Completion-Widgets" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Widgets.html#Completion-Widget-Example" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Description-3" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Completion-System-1"></a>
<h1 class="chapter">20 Completion System</h1>
<a name="index-completion-system"></a>
<a name="index-completion_002c-programmable-1"></a>
<a name="index-completion_002c-controlling-1"></a>

<hr>
<a name="Description-3"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Initialization" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">20.1 Description</h2>

<p>This describes the shell code for the &lsquo;new&rsquo; completion system, referred
to as <tt>compsys</tt>.  It is written in shell functions based on the
features described in
the previous chapter, <a href="Completion-Widgets.html#Completion-Widgets">Completion Widgets</a>.
</p>
<p>The features are contextual, sensitive to the point at which completion is
started.  Many completions are already provided.
For this reason, a user can perform a great many tasks without
knowing any details beyond how to initialize the system, which is
described
in <a href="#Initialization">Initialization</a>.
</p>
<p>The context that decides what completion is to be performed may be
</p><ul>
<li> an argument or option position: these describe the position on the
command line at which completion is requested.  For example &lsquo;first argument
to rmdir, the word being completed names a directory&rsquo;;

</li><li> a special context, denoting an element in the shell&rsquo;s syntax.  For example
&lsquo;a word in command position&rsquo; or &lsquo;an array subscript&rsquo;.

</li></ul>

<p>A full context specification contains other elements, as we shall describe.
</p>
<p>Besides commands names and contexts, the system employs two more
concepts, <em>styles</em> and <em>tags</em>.  These provide ways for the user
to configure the system&rsquo;s behaviour.
</p>
<p>Tags play a dual role.  They serve as a classification system for
the matches, typically indicating a class of object that the user
may need to distinguish.  For example, when completing arguments of the
<tt>ls</tt> command the user may prefer to try <tt>files</tt> before <tt>directories</tt>,
so both of these are tags.  They also appear as the rightmost
element in a context specification.
</p>
<p>Styles modify various operations of the completion system, such as
output formatting, but also what kinds of completers are used (and in
what order), or which tags are examined.  Styles may accept arguments
and are manipulated using the <tt>zstyle</tt> command described in
<a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil Module</a>.
</p>
<p>In summary, tags describe <em>what</em> the completion objects are, and style
<tt>how</tt> they are to be completed.  At various points of execution, the
completion system checks what styles and/or tags are defined for the
current context, and uses that to modify its behavior.  The full
description of context handling, which determines how tags and other
elements of the context influence the behaviour of styles, is described
in <a href="#Completion-System-Configuration">Completion System Configuration</a>.
</p>
<p>When a completion is requested, a dispatcher function is called;
see the description of <tt>_main_complete</tt> in the list of control functions
below. This dispatcher decides which function should
be called to produce the completions, and calls it. The result is
passed to one or more <em>completers</em>, functions that implement
individual completion strategies: simple completion, error correction,
completion with error correction, menu selection, etc.
</p>
<p>More generally, the shell functions contained in the completion system are
of two types:
</p><ul>
<li> those beginning &lsquo;<tt>comp</tt>&rsquo; are to be called directly; there are only
a few of these;

</li><li> those beginning &lsquo;<tt>_</tt>&rsquo; are called by the
completion code.  The shell functions of this set, which implement
completion behaviour and may be bound to keystrokes, are referred to
as &lsquo;widgets&rsquo;.  These proliferate as new completions are required.

</li></ul>

<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Initialization">20.2 Initialization</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-System-Configuration">20.3 Completion System Configuration</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Control-Functions">20.4 Control Functions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Bindable-Commands">20.5 Bindable Commands</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Functions">20.6 Utility Functions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Directories">20.8 Completion Directories</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-System-Variables">20.7 Completion System Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>

<hr>
<a name="Initialization"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Description-3" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Use-of-compinit" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Initialization-1"></a>
<h2 class="section">20.2 Initialization</h2>
<a name="index-compinstall"></a>
<a name="index-completion-system_002c-installing"></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>
<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&rsquo;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 &lsquo;<tt>zstyle</tt>&rsquo; should be gracefully handled.
</p>
<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>
<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
(&lsquo;<tt>autoload -U compinstall</tt>&rsquo; 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>

<hr>
<a name="Use-of-compinit"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Initialization" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Initialization" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Autoloaded-files" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">20.2.1 Use of compinit</h3>
<a name="index-compinit"></a>
<a name="index-completion-system_002c-initializing"></a>

<p>This section describes the use of <tt>compinit</tt> to initialize completion for
the current session when called directly; if you have run
<tt>compinstall</tt> it will be called automatically from your <tt>.zshrc</tt>.
</p>
<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
(&lsquo;<tt>autoload -U compinit</tt>&rsquo; is recommended), and then run simply as
&lsquo;<tt>compinit</tt>&rsquo;.  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>
<p>Should you need to use the original completion commands, you can still
bind keys to the old widgets by putting a &lsquo;<tt>.</tt>&rsquo; in front of the
widget name, e.g. &lsquo;<tt>.expand-or-complete</tt>&rsquo;.
</p>
<p>To speed up the running of <tt>compinit</tt>, it can be made to produce a dumped
configuration that will be read in on future invocations; this is the
default, but 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 &lsquo;<tt>compinit -d</tt>
<var>dumpfile</var>&rsquo;.  The next invocation of <tt>compinit</tt> will read the dumped
file instead of performing a full initialization.
</p>
<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&rsquo;t one already.
</p>
<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>
<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>
<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="index-compaudit"></a>
<p>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>
<a name="index-bashcompinit"></a>
<p>The function <tt>bashcompinit</tt> provides compatibility with bash&rsquo;s programmable
completion system.  When run it will define the functions, <tt>compgen</tt> and
<tt>complete</tt> which correspond to the bash builtins with the same names.
It will then be possible to use completion specifications and functions
written for bash.
</p>

<hr>
<a name="Autoloaded-files"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Use-of-compinit" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Initialization" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Functions-2" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">20.2.2 Autoloaded files</h3>
<a name="index-completion-system_002c-autoloaded-functions"></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>
<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 to the path: this allows
the functions to be in the same format as in the <tt>zsh</tt> source
distribution.
</p>
<a name="index-compdef_002c-use-of-by-compinit"></a>
<p>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>
<p>The tags are:
</p>
<dl compact="compact">
<dt><tt>#compdef</tt> <var>name</var> ... [ <tt>-</tt>{<tt>p</tt>|<tt>P</tt>} <var>pattern</var> ... [ <tt>-N</tt> <var>name</var> ... ] ]</dt>
<dd><p>The file will be made autoloadable and the function defined 
in it will be called when completing <var>name</var>s, 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.
</p>
<p>Each <var>name</var> may also be of the form &lsquo;<var>cmd</var><tt>=</tt><var>service</var>&rsquo;.
When completing the command <var>cmd</var>, the function typically behaves as
if the command (or special context) <var>service</var> was being completed
instead.  This provides a way of altering the behaviour of functions
that can perform many different completions.  It is implemented
by setting the parameter <tt>$service</tt> when calling the function;
the function may choose to interpret this how it wishes, and simpler
functions will probably ignore it.
</p>
<p>If the <tt>#compdef</tt> line contains one of the options <tt>-p</tt> or <tt>-P</tt>,
the words following are taken to be patterns.  The function will be
called when completion is attempted for a command or context that matches
one of the patterns.  The options <tt>-p</tt> and <tt>-P</tt> are used to specify
patterns to be tried before or after other completions respectively.
Hence <tt>-P</tt> may be used to specify default actions.
</p>
<p>The option <tt>-N</tt> is used after a list following <tt>-p</tt> or <tt>-P</tt>; it
specifies that remaining words no longer define patterns.  It is
possible to toggle between the three options as many times as necessary.
</p>
</dd>
<dt><tt>#compdef -k</tt> <var>style key-sequence</var> ...</dt>
<dd><p>This option creates a widget behaving like the
builtin widget <var>style</var> and binds it to the given <var>key-sequence</var>s,
if any.  The <var>style</var> must be one of the builtin widgets 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
<a href="Zsh-Modules.html#The-zsh_002fcomplist-Module">The zsh/complist Module</a>) the widget <tt>menu-select</tt> is also available.
</p>
<p>When one of the <var>key-sequence</var>s is typed, the function in the file will
be invoked to generate the matches.  Note that a key will not be re-bound
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.
</p>
</dd>
<dt><tt>#compdef -K</tt> <var>widget-name</var> <var>style</var> <var>key-sequence</var> [ <var>name</var> <var>style</var> <var>seq</var> ... ]</dt>
<dd><p>This is similar to <tt>-k</tt> except that only one <var>key-sequence</var>
argument may be given for each <var>widget-name</var> <var>style</var> pair.
However, the entire set of three arguments may be repeated with a
different set of arguments.  Note in particular that the
<var>widget-name</var> must be distinct in each set.  If it does not begin with
&lsquo;<tt>_</tt>&rsquo; this will be added.  The <var>widget-name</var> should not clash with
the name of any existing widget: names based on the name of the function
are most useful.  For example,
</p>
<div class="example">
<pre class="example">#compdef -K _foo_complete complete-word &quot;^X^C&quot; \ 
  _foo_list list-choices &quot;^X^D&quot;
</pre></div>

<p>(all on one line) defines a widget <tt>_foo_complete</tt> for completion, bound
to &lsquo;<tt>^X^C</tt>&rsquo;, and a widget <tt>_foo_list</tt> for listing, bound to &lsquo;<tt>^X^D</tt>&rsquo;.
</p>
</dd>
<dt><tt>#autoload</tt> [ <var>options</var> ]</dt>
<dd><p>Functions with the <tt>#autoload</tt> tag are marked for autoloading but
are not otherwise treated specially.  Typically they are to be called
from within one of the completion functions.  Any <var>options</var> supplied
will be passed to the <tt>autoload</tt> builtin; a typical use is <tt>+X</tt> to
force the function to be loaded immediately.  Note that the <tt>-U</tt> and
<tt>-z</tt> flags are always added implicitly.
</p>
</dd>
</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>
<p>The special contexts for which completion functions can be defined are:
</p>
<dl compact="compact">
<dd><a name="index-_002darray_002dvalue_002d_002c-completion-context"></a>
</dd>
<dt><tt>-array-value-</tt></dt>
<dd><p>The right hand side of an array-assignment
(&lsquo;<var>name</var><tt>=(</tt><var>...</var><tt>)</tt>&rsquo;)
</p>
<a name="index-_002dbrace_002dparameter_002d_002c-completion-context"></a>
</dd>
<dt><tt>-brace-parameter-</tt></dt>
<dd><p>The name of a parameter expansion within braces (&lsquo;<tt>${</tt><var>...</var><tt>}</tt>&rsquo;)
</p>
<a name="index-_002dassign_002dparameter_002d_002c-completion-context"></a>
</dd>
<dt><tt>-assign-parameter-</tt></dt>
<dd><p>The name of a parameter in an assignment, i.e. on the left hand side of
an &lsquo;<tt>=</tt>&rsquo;
</p>
<a name="index-_002dcommand_002d_002c-completion-context"></a>
</dd>
<dt><tt>-command-</tt></dt>
<dd><p>A word in command position
</p>
<a name="index-_002dcondition_002d_002c-completion-context"></a>
</dd>
<dt><tt>-condition-</tt></dt>
<dd><p>A word inside a condition (&lsquo;<tt>[[</tt><var>...</var><tt>]]</tt>&rsquo;)
</p>
<a name="index-_002ddefault_002d_002c-completion-context"></a>
</dd>
<dt><tt>-default-</tt></dt>
<dd><p>Any word for which no other completion is defined
</p>
<a name="index-_002dequal_002d_002c-completion-context"></a>
</dd>
<dt><tt>-equal-</tt></dt>
<dd><p>A word beginning with an equals sign
</p>
<a name="index-_002dfirst_002d_002c-completion-context"></a>
</dd>
<dt><tt>-first-</tt></dt>
<dd><p>This is tried before any other completion function.  The function called
may set the <tt>_compskip</tt> parameter to one of various values: 
<tt>all</tt>: no further completion is attempted; a string
containing the substring <tt>patterns</tt>: no pattern completion functions
will be called; a string containing <tt>default</tt>: the
function for the &lsquo;<tt>-default-</tt>&rsquo; context will not be called, but
functions defined for commands will be.
</p>
<a name="index-_002dmath_002d_002c-completion-context"></a>
</dd>
<dt><tt>-math-</tt></dt>
<dd><p>Inside mathematical contexts, such as
&lsquo;<tt>((</tt><var>...</var><tt>))</tt>&rsquo;
</p>
<a name="index-_002dparameter_002d_002c-completion-context"></a>
</dd>
<dt><tt>-parameter-</tt></dt>
<dd><p>The name of a parameter expansion (&lsquo;<tt>$</tt><var>...</var>&rsquo;)
</p>
<a name="index-_002dredirect_002d_002c-completion-context"></a>
</dd>
<dt><tt>-redirect-</tt></dt>
<dd><p>The word after a redirection operator.
</p>
<a name="index-_002dsubscript_002d_002c-completion-context"></a>
</dd>
<dt><tt>-subscript-</tt></dt>
<dd><p>The contents of a parameter subscript.
</p>
<a name="index-_002dtilde_002d_002c-completion-context"></a>
</dd>
<dt><tt>-tilde-</tt></dt>
<dd><p>After an initial tilde (&lsquo;<tt>~</tt>&rsquo;), but before the first slash
in the word.
</p>
<a name="index-_002dvalue_002d_002c-completion-context"></a>
</dd>
<dt><tt>-value-</tt></dt>
<dd><p>On the right hand side of an assignment.
</p>
</dd>
</dl>

<p>Default implementations are supplied for each of these
contexts.  In most cases the context <tt>-</tt><var>context</var><tt>-</tt> is
implemented by a corresponding function <tt>_</tt><var>context</var>, for example
the context &lsquo;<tt>-tilde-</tt>&rsquo; and the function &lsquo;<tt>_tilde</tt>&rsquo;).
</p>
<p>The contexts <tt>-redirect-</tt> and <tt>-value-</tt> allow extra context-specific
information.  (Internally, this is handled by the functions for each
context calling the function <tt>_dispatch</tt>.)  The extra
information is added separated by commas.
</p>
<p>For the <tt>-redirect-</tt> context, the extra information is in the form
&lsquo;<tt>-redirect-,</tt><var>op</var><tt>,</tt><var>command</var>&rsquo;, where <var>op</var> is the
redirection operator and <var>command</var> is the name of the command on
the line.  If there is no command on the line yet, the <var>command</var>
field will be empty.
</p>
<p>For the <tt>-value-</tt> context, the form is
&lsquo;<tt>-value-,</tt><var>name</var><tt>,</tt><var>command</var>&rsquo;, where <var>name</var> is the name of
the parameter on the left hand side of the assignment.
In the case of elements of an associative array, for
example &lsquo;<tt>assoc=(key &lt;TAB&gt;</tt>&rsquo;, <var>name</var> is expanded to
&lsquo;<var>name</var><tt>-</tt><var>key</var>&rsquo;.  In certain special contexts, such as
completing after &lsquo;<tt>make CFLAGS=</tt>&rsquo;, the <var>command</var> part gives the
name of the command, here <tt>make</tt>; otherwise it is empty.
</p>
<p>It is not necessary to define fully specific completions as the
functions provided will try to generate completions by progressively
replacing the elements with &lsquo;<tt>-default-</tt>&rsquo;.  For example, when
completing after &lsquo;<tt>foo=&lt;TAB&gt;</tt>&rsquo;, <tt>_value</tt> will try the names
&lsquo;<tt>-value-,foo,</tt>&rsquo; (note the empty <var>command</var> part),
&lsquo;<tt>-value-,foo,-default-</tt>&rsquo; and&lsquo;<tt>-value-,-default-,-default-</tt>&rsquo;, in
that order, until it finds a function to handle the context.
</p>
<p>As an example:
</p>
<div class="example">
<pre class="example">compdef '_files -g &quot;*.log&quot;' '-redirect-,2&gt;,-default-'
</pre></div>

<p>completes files matching &lsquo;<tt>*.log</tt>&rsquo; after &lsquo;<tt>2&gt; &lt;TAB&gt;</tt>&rsquo; for any
command with no more specific handler defined.
</p>
<p>Also:
</p>
<div class="example">
<pre class="example">compdef _foo -value-,-default-,-default-
</pre></div>

<p>specifies that <tt>_foo</tt> provides completions for the values of
parameters for which no special function has been defined.  This is
usually handled by the function <tt>_value</tt> itself.
</p>
<p>The same lookup rules are used when looking up styles (as described
below); for example
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:*:-redirect-,2&gt;,*:*' file-patterns '*.log'
</pre></div>

<p>is another way to make completion after &lsquo;<tt>2&gt; &lt;TAB&gt;</tt>&rsquo; complete files
matching &lsquo;<tt>*.log</tt>&rsquo;.
</p>

<hr>
<a name="Functions-2"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Autoloaded-files" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Initialization" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System-Configuration" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">20.2.3 Functions</h3>

<p>The following function is defined by <tt>compinit</tt> and may be called
directly.
</p>
<a name="index-compdef"></a>
<a name="index-completion-system_002c-adding-definitions"></a>
<dl compact="compact">
<dt><tt>compdef</tt> [ <tt>-ane</tt> ] <var>function name</var> ... [ <tt>-</tt>{<tt>p</tt>|<tt>P</tt>} <var>pattern</var> ... [ <tt>-N</tt> <var>name</var> ...]]</dt>
<dt><tt>compdef -d</tt> <var>name</var> ...</dt>
<dt><tt>compdef -k</tt> [ <tt>-an</tt> ] <var>function style key-sequence</var> [ <var>key-sequence</var> ... ]</dt>
<dt><tt>compdef -K</tt> [ <tt>-an</tt> ] <var>function name style key-seq</var> [ <var>name style seq</var> ... ]</dt>
<dd><p>The first form defines the <var>function</var> to call for completion in the
given contexts as described for the <tt>#compdef</tt> tag above.
</p>
<p>Alternatively, all the arguments may have the form
&lsquo;<var>cmd</var><tt>=</tt><var>service</var>&rsquo;.  Here <var>service</var> should already have been
defined by &lsquo;<var>cmd1</var><tt>=</tt><var>service</var>&rsquo; lines in <tt>#compdef</tt> files, as
described above.  The argument for <var>cmd</var> will be completed in the
same way as <var>service</var>.
</p>
<p>The <var>function</var> argument may alternatively be a string containing
almost any shell code.  If the string contains an equal sign, the above
will take precedence.  The option <tt>-e</tt> may be used to specify the first
argument is to be evaluated as shell code even if it contains an equal
sign.  The string will be executed using the <tt>eval</tt> builtin command to
generate completions.  This provides a way of avoiding having to define
a new completion function.  For example, to complete files ending in
&lsquo;<tt>.h</tt>&rsquo; as arguments to the command <tt>foo</tt>:
</p>
<div class="example">
<pre class="example">compdef '_files -g &quot;*.h&quot;' foo
</pre></div>

<p>The option <tt>-n</tt> prevents any completions already defined for the
command or context from being overwritten.
</p>
<p>The option <tt>-d</tt> deletes any completion defined for the command or
contexts listed.
</p>
<p>The <var>name</var>s may also contain <tt>-p</tt>, <tt>-P</tt> and <tt>-N</tt> options as
described for the <tt>#compdef</tt> tag.  The effect on the argument list is
identical, switching between definitions of patterns tried initially,
patterns tried finally, and normal commands and contexts.
</p>
<p>The parameter <tt>$_compskip</tt> may be set by any function defined for a
pattern context.  If it is set to a value containing the substring
&lsquo;<tt>patterns</tt>&rsquo; none of the pattern-functions will be called; if it is
set to a value containing the substring &lsquo;<tt>all</tt>&rsquo;, no other function
will be called.
</p>
<p>The form with <tt>-k</tt> defines a widget with the same name as the <var>function</var>
that will be called for each of the <var>key-sequence</var>s; 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>.
</p>
<p>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-seq</var>uence, where the latter two are as
for <tt>-k</tt> and the first must be a unique widget name beginning with an
underscore.
</p>
<p>Wherever applicable, the <tt>-a</tt> option makes the <var>function</var>
autoloadable, equivalent to <tt>autoload -U </tt><var>function</var>.
</p>
</dd>
</dl>

<p>The function <tt>compdef</tt> can be used to associate existing completion
functions with new commands.  For example,
</p>
<div class="example">
<pre class="example">compdef _pids foo
</pre></div>

<p>uses the function <tt>_pids</tt> to complete process IDs for the command <tt>foo</tt>.
</p>
<p>Note also the <tt>_gnu_generic</tt> function described below, which can be
used to complete options for commands that understand the
&lsquo;<tt>-</tt><tt>-help</tt>&rsquo; option.
</p>
<hr>
<a name="Completion-System-Configuration"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Functions-2" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Overview-2" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Completion-System-Configuration-1"></a>
<h2 class="section">20.3 Completion System Configuration</h2>
<a name="index-completion-system_002c-configuration"></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>

<hr>
<a name="Overview-2"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System-Configuration" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System-Configuration" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Standard-Tags" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">20.3.1 Overview</h3>

<p>When completion is attempted somewhere on the command line the
completion system begins building the context.  The context represents
everything that the shell knows about the meaning of the command line
and the significance of the cursor position.  This takes account of a
number of things including the command word (such as &lsquo;<tt>grep</tt>&rsquo; or
&lsquo;<tt>zsh</tt>&rsquo;) and options to which the current word may be an argument
(such as the &lsquo;<tt>-o</tt>&rsquo; option to <tt>zsh</tt> which takes a shell option as an
argument).
</p>
<p>The context starts out very generic (&quot;we are beginning a completion&quot;)
and becomes more specific as more is learned (&quot;the current word is in a
position that is usually a command name&quot; or &quot;the current word might be a
variable name&quot; and so on).  Therefore the context will vary during the
same call to the completion system.
</p>
<p>This context information is condensed into a string consisting of multiple
fields separated by colons, referred to simply as &lsquo;the context&rsquo; in the
remainder of the documentation.  Note that a user of the completion system
rarely needs to compose a context string, unless for example a new
function is being written to perform completion for a new command.  What a
user may need to do is compose a <em>style</em> pattern, which is matched
against a context when needed to look up context-sensitive options that
configure the completion system.
</p>
<p>The next few paragraphs explain how a context is composed within the
completion function suite.  Following that is discussion of how <em>styles</em>
are defined.  Styles determine such things as how the matches are
generated, similarly to shell options but with much more control.  They
are defined with the <tt>zstyle</tt> builtin command (<a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil Module</a>).
</p>
<p>The context string always consists of a fixed set of fields, separated
by colons and with a leading colon before the first.  Fields which are
not yet known are left empty, but the surrounding colons appear anyway.
The fields are always in the order
<tt>:completion:</tt><var>function</var><tt>:</tt><var>completer</var><tt>:</tt><var>command</var><tt>:</tt><var>argument</var><tt>:</tt><var>tag</var>.  These have the following meaning:
</p>
<ul>
<li> The literal string <tt>completion</tt>, saying that this style is used by
the completion system.  This distinguishes the context from those used
by, for example, zle widgets and ZFTP functions.

</li><li> The <var>function</var>, if completion is called from a named widget rather
than through the normal completion system.  Typically this is blank, but
it is set by special widgets such as <tt>predict-on</tt> and the various
functions in the <tt>Widget</tt> directory of the distribution to the name of
that function, often in an abbreviated form.

</li><li> The <var>completer</var> currently active, the name of the function without the
leading underscore and with other underscores converted to hyphens.  A
&lsquo;completer&rsquo; is in overall control of how completion is to be performed;
&lsquo;<tt>complete</tt>&rsquo; is the simplest, but other completers exist to perform
related tasks such as correction, or to modify the behaviour of a later
completer.  See
<a href="#Control-Functions">Control Functions</a> 
for more information.  

</li><li> The <var>command</var> or a special <tt>-</tt><var>context</var><tt>-</tt>, just at it appears
following the <tt>#compdef</tt> tag or the <tt>compdef</tt> function.  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.  For example, the completion function for the <tt>cvs</tt>
command sets this field to <tt>cvs-add</tt> when completing arguments to
the <tt>add</tt> subcommand.

</li><li> The <var>argument</var>; this indicates which command line or option argument
we are completing.  For command arguments this generally takes the form
<tt>argument-</tt><var>n</var>, where <var>n</var> is the number of the argument,
and for arguments to options the form <tt>option-</tt><var>opt</var><tt>-</tt><var>n</var>
where <var>n</var> is the number of the argument to option <var>opt</var>.  However,
this is only the case if the command line is parsed with standard
UNIX-style options and arguments, so many completions do not set this.

</li><li> The <var>tag</var>.  As described previously, tags are used to discriminate between
the types of matches a completion function can generate in a certain context.
Any completion function may use any tag name it likes, but a list of the
more common ones is given below.

</li></ul>

<p>The context is gradually put together as the functions are executed, starting
with the main entry point, which adds <tt>:completion:</tt> and the <var>function</var>
element if necessary.  The completer then adds the <var>completer</var> element.
The contextual completion adds the <var>command</var> and <var>argument</var> options.
Finally, the <var>tag</var> is added when the types of completion are known.
For example, the context name
</p>
<div class="example">
<pre class="example"><tt>:completion::complete:dvips:option-o-1:files</tt>
</pre></div>

<p>says that normal completion was attempted as the first argument to the
option <tt>-o</tt> of the command <tt>dvips</tt>:
</p>
<div class="example">
<pre class="example"><tt>dvips -o ...</tt>
</pre></div>

<p>and the completion function will generate filenames.
</p>
<p>Usually completion will be tried for all possible tags in an order given
by the completion function.  However, this can be altered by using the
<tt>tag-order</tt> style.  Completion is then restricted to the list of given
tags in the given order.
</p>
<p>The <tt>_complete_help</tt> bindable command shows all the contexts and tags
available for completion at a particular point.  This provides an easy
way of finding information for <tt>tag-order</tt> and other styles.  It is
described in
<a href="#Bindable-Commands">Bindable Commands</a>.
</p>
<p>When looking up styles the completion system uses full context names,
including the tag.  Looking up the value of a style therefore consists of
two things: the context, which is matched to the most specific (best
fitting) style pattern, and the name of the style itself, which must be
matched exactly.  The following examples demonstrate that style patterns
may be loosely defined for styles that apply broadly, or as tightly
defined as desired for styles that apply in narrower circumstances.
</p>
<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>
<div class="example">
<pre class="example">zstyle ':completion:*' verbose yes
</pre></div>

<p>in a startup file (probably <tt>.zshrc</tt>).
This gives the <tt>verbose</tt> style the value <tt>yes</tt> in every
context inside the completion system, unless that context has a more
specific definition.  It is best to avoid giving the context as &lsquo;<tt>*</tt>&rsquo;
in case the style has some meaning outside the completion system.
</p>
<p>Many such general purpose styles can be configured simply by using the
<tt>compinstall</tt> function.
</p>
<p>A more specific example of the use of the <tt>verbose</tt> style is by the
completion for the <tt>kill</tt> builtin.  If the style is set, the builtin
lists full job texts and process command lines; otherwise it shows the
bare job numbers and PIDs.  To turn the style off for this use only:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:*:kill:*:*' verbose no
</pre></div>

<p>For even more control, the style can use one of the tags &lsquo;<tt>jobs</tt>&rsquo; or
&lsquo;<tt>processes</tt>&rsquo;.  To turn off verbose display only for jobs:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:*:kill:*:jobs' verbose no
</pre></div>

<p>The <tt>-e</tt> option to <tt>zstyle</tt> even allows completion function code to
appear as the argument to a style; this requires some understanding of
the internals of completion functions (see
<a href="Completion-Widgets.html#Completion-Widgets">Completion Widgets</a>)).  For example,
</p>
<div class="example">
<pre class="example"><tt>zstyle -e ':completion:*' hosts 'reply=($myhosts)'</tt>
</pre></div>

<p>This forces the value of the <tt>hosts</tt> style to be read from the
variable <tt>myhosts</tt> each time a host name is needed; this is useful
if the value of <tt>myhosts</tt> can change dynamically.
For another useful example, see the example in the description of the
<tt>file-list</tt> style below.  This form can be
slow and should be avoided for commonly examined styles such
as <tt>menu</tt> and <tt>list-rows-first</tt>.
</p>
<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, &lsquo;<tt>:completion::complete:::foo</tt>&rsquo; is
more specific than &lsquo;<tt>:completion::complete:::*'</tt>), and longer patterns are
preferred over shorter patterns.
</p>
<p>A good rule of thumb is that any completion style pattern that needs to
include more than one wildcard (<tt>*</tt>) and that does not end in a tag
name, should include all six colons (<tt>:</tt>), possibly surrounding
additional wildcards.
</p>
<p>Style names like those of tags are arbitrary and depend on the completion
function.  However, the following two sections list some of the most
common tags and styles.
</p>

<hr>
<a name="Standard-Tags"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Overview-2" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System-Configuration" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Standard-Styles" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">20.3.2 Standard Tags</h3>
<a name="index-completion-system_002c-tags"></a>

<p>Some of the following are only used when looking up particular styles
and do not refer to a type of match.
</p>
<dl compact="compact">
<dd><a name="index-accounts_002c-completion-tag"></a>
</dd>
<dt><tt>accounts</tt></dt>
<dd><p>used to look up the <tt>users-hosts</tt> style
</p>
<a name="index-all_002dexpansions_002c-completion-tag"></a>
</dd>
<dt><tt>all-expansions</tt></dt>
<dd><p>used by the <tt>_expand</tt> completer when adding the single string containing
all possible expansions
</p>
<a name="index-all_002dfiles_002c-completion-tag"></a>
</dd>
<dt><tt>all-files</tt></dt>
<dd><p>for the names of all files (as distinct from a particular subset, see the
<tt>globbed-files</tt> tag).
</p>
<a name="index-arguments_002c-completion-tag"></a>
</dd>
<dt><tt>arguments</tt></dt>
<dd><p>for arguments to a command
</p>
<a name="index-arrays_002c-completion-tag"></a>
</dd>
<dt><tt>arrays</tt></dt>
<dd><p>for names of array parameters
</p>
<a name="index-association_002dkeys_002c-completion-tag"></a>
</dd>
<dt><tt>association-keys</tt></dt>
<dd><p>for keys of associative arrays; used when completing inside a
subscript to a parameter of this type
</p>
<a name="index-bookmarks_002c-completion-tag"></a>
</dd>
<dt><tt>bookmarks</tt></dt>
<dd><p>when completing bookmarks (e.g. for URLs and the <tt>zftp</tt> function suite)
</p>
<a name="index-builtins_002c-completion-tag"></a>
</dd>
<dt><tt>builtins</tt></dt>
<dd><p>for names of builtin commands
</p>
<a name="index-characters_002c-completion-tag"></a>
</dd>
<dt><tt>characters</tt></dt>
<dd><p>for single characters in arguments of commands such as <tt>stty</tt>.   Also used
when completing character classes after an opening bracket
</p>
<a name="index-colormapids_002c-completion-tag"></a>
</dd>
<dt><tt>colormapids</tt></dt>
<dd><p>for X colormap ids
</p>
<a name="index-colors_002c-completion-tag"></a>
</dd>
<dt><tt>colors</tt></dt>
<dd><p>for color names
</p>
<a name="index-commands_002c-completion-tag"></a>
</dd>
<dt><tt>commands</tt></dt>
<dd><p>for names of external commands.  Also used by complex commands such as
<tt>cvs</tt> when completing names subcommands.
</p>
<a name="index-contexts_002c-completion-tag"></a>
</dd>
<dt><tt>contexts</tt></dt>
<dd><p>for contexts in arguments to the <tt>zstyle</tt> builtin command
</p>
<a name="index-corrections_002c-completion-tag"></a>
</dd>
<dt><tt>corrections</tt></dt>
<dd><p>used by the <tt>_approximate</tt> and <tt>_correct</tt> completers for possible
corrections
</p>
<a name="index-cursors_002c-completion-tag"></a>
</dd>
<dt><tt>cursors</tt></dt>
<dd><p>for cursor names used by X programs
</p>
<a name="index-default_002c-completion-tag"></a>
</dd>
<dt><tt>default</tt></dt>
<dd><p>used in some contexts to provide a way of supplying a default when more
specific tags are also valid.  Note that this tag is
used when only the <var>function</var> field of the context name is set
</p>
<a name="index-descriptions_002c-completion-tag"></a>
</dd>
<dt><tt>descriptions</tt></dt>
<dd><p>used when looking up the value of the <tt>format</tt> style to generate
descriptions for types of matches
</p>
<a name="index-devices_002c-completion-tag"></a>
</dd>
<dt><tt>devices</tt></dt>
<dd><p>for names of device special files
</p>
<a name="index-directories_002c-completion-tag"></a>
</dd>
<dt><tt>directories</tt></dt>
<dd><p>for names of directories &mdash; <tt>local-directories</tt> is used instead
when completing arguments of <tt>cd</tt> and related builtin commands when
the <tt>cdpath</tt> array is set
</p>
<a name="index-directory_002dstack_002c-completion-tag"></a>
</dd>
<dt><tt>directory-stack</tt></dt>
<dd><p>for entries in the directory stack
</p>
<a name="index-displays_002c-completion-tag"></a>
</dd>
<dt><tt>displays</tt></dt>
<dd><p>for X display names
</p>
<a name="index-domains_002c-completion-tag"></a>
</dd>
<dt><tt>domains</tt></dt>
<dd><p>for network domains
</p>
<a name="index-email_002d_002a_002c-completion-tag"></a>
</dd>
<dt><tt>email-</tt><var>plugin</var></dt>
<dd><p>for email addresses from the &lsquo;<tt>_email-</tt><var>plugin</var>&rsquo; backend of <tt>_email_addresses</tt>
</p>
<a name="index-expansions_002c-completion-tag"></a>
</dd>
<dt><tt>expansions</tt></dt>
<dd><p>used by the <tt>_expand</tt> completer for individual words (as opposed to
the complete set of expansions) resulting from the expansion of a word
on the command line
</p>
<a name="index-extensions_002c-completion-tag"></a>
</dd>
<dt><tt>extensions</tt></dt>
<dd><p>for X server extensions
</p>
<a name="index-file_002ddescriptors_002c-completion-tag"></a>
</dd>
<dt><tt>file-descriptors</tt></dt>
<dd><p>for numbers of open file descriptors
</p>
<a name="index-files_002c-completion-tag"></a>
</dd>
<dt><tt>files</tt></dt>
<dd><p>the generic file-matching tag used by functions completing filenames
</p>
<a name="index-fonts_002c-completion-tag"></a>
</dd>
<dt><tt>fonts</tt></dt>
<dd><p>for X font names
</p>
<a name="index-fstypes_002c-completion-tag"></a>
</dd>
<dt><tt>fstypes</tt></dt>
<dd><p>for file system types (e.g. for the <tt>mount</tt> command)
</p>
<a name="index-functions_002c-completion-tag"></a>
</dd>
<dt><tt>functions</tt></dt>
<dd><p>names of functions &mdash; normally shell functions, although certain
commands may understand other kinds of function
</p>
<a name="index-globbed_002dfiles_002c-completion-tag"></a>
</dd>
<dt><tt>globbed-files</tt></dt>
<dd><p>for filenames when the name has been generated by pattern matching
</p>
<a name="index-groups_002c-completion-tag"></a>
</dd>
<dt><tt>groups</tt></dt>
<dd><p>for names of user groups
</p>
<a name="index-history_002dwords_002c-completion-tag"></a>
</dd>
<dt><tt>history-words</tt></dt>
<dd><p>for words from the history
</p>
<a name="index-hosts_002c-completion-tag"></a>
</dd>
<dt><tt>hosts</tt></dt>
<dd><p>for hostnames
</p>
<a name="index-indexes_002c-completion-tag"></a>
</dd>
<dt><tt>indexes</tt></dt>
<dd><p>for array indexes
</p>
<a name="index-jobs_002c-completion-tag"></a>
</dd>
<dt><tt>jobs</tt></dt>
<dd><p>for jobs (as listed by the &lsquo;<tt>jobs</tt>&rsquo; builtin)
</p>
<a name="index-interfaces_002c-completion-tag"></a>
</dd>
<dt><tt>interfaces</tt></dt>
<dd><p>for network interfaces
</p>
<a name="index-keymaps_002c-completion-tag"></a>
</dd>
<dt><tt>keymaps</tt></dt>
<dd><p>for names of zsh keymaps
</p>
<a name="index-keysyms_002c-completion-tag"></a>
</dd>
<dt><tt>keysyms</tt></dt>
<dd><p>for names of X keysyms
</p>
<a name="index-libraries_002c-completion-tag"></a>
</dd>
<dt><tt>libraries</tt></dt>
<dd><p>for names of system libraries
</p>
<a name="index-limits_002c-completion-tag"></a>
</dd>
<dt><tt>limits</tt></dt>
<dd><p>for system limits
</p>
<a name="index-local_002ddirectories_002c-completion-tag"></a>
</dd>
<dt><tt>local-directories</tt></dt>
<dd><p>for names of directories that are subdirectories of the current working
directory when completing arguments of <tt>cd</tt> and related builtin
commands (compare <tt>path-directories</tt>) &mdash; when the <tt>cdpath</tt>
array is unset, <tt>directories</tt> is used instead
</p>
<a name="index-manuals_002c-completion-tag"></a>
</dd>
<dt><tt>manuals</tt></dt>
<dd><p>for names of manual pages
</p>
<a name="index-mailboxes_002c-completion-tag"></a>
</dd>
<dt><tt>mailboxes</tt></dt>
<dd><p>for e-mail folders
</p>
<a name="index-maps_002c-completion-tag"></a>
</dd>
<dt><tt>maps</tt></dt>
<dd><p>for map names (e.g. NIS maps)
</p>
<a name="index-messages_002c-completion-tag"></a>
</dd>
<dt><tt>messages</tt></dt>
<dd><p>used to look up the <tt>format</tt> style for messages
</p>
<a name="index-modifiers_002c-completion-tag"></a>
</dd>
<dt><tt>modifiers</tt></dt>
<dd><p>for names of X modifiers
</p>
<a name="index-modules_002c-completion-tag"></a>
</dd>
<dt><tt>modules</tt></dt>
<dd><p>for modules (e.g. <tt>zsh</tt> modules)
</p>
<a name="index-my_002daccounts_002c-completion-tag"></a>
</dd>
<dt><tt>my-accounts</tt></dt>
<dd><p>used to look up the <tt>users-hosts</tt> style
</p>
<a name="index-named_002ddirectories_002c-completion-tag"></a>
</dd>
<dt><tt>named-directories</tt></dt>
<dd><p>for named directories (you wouldn&rsquo;t have guessed that, would you?)
</p>
<a name="index-names_002c-completion-tag"></a>
</dd>
<dt><tt>names</tt></dt>
<dd><p>for all kinds of names
</p>
<a name="index-newsgroups_002c-completion-tag"></a>
</dd>
<dt><tt>newsgroups</tt></dt>
<dd><p>for USENET groups
</p>
<a name="index-nicknames_002c-completion-tag"></a>
</dd>
<dt><tt>nicknames</tt></dt>
<dd><p>for nicknames of NIS maps
</p>
<a name="index-options_002c-completion-tag"></a>
</dd>
<dt><tt>options</tt></dt>
<dd><p>for command options
</p>
<a name="index-original_002c-completion-tag"></a>
</dd>
<dt><tt>original</tt></dt>
<dd><p>used by the <tt>_approximate</tt>, <tt>_correct</tt> and <tt>_expand</tt> completers when
offering the original string as a match
</p>
<a name="index-other_002daccounts_002c-completion-tag"></a>
</dd>
<dt><tt>other-accounts</tt></dt>
<dd><p>used to look up the <tt>users-hosts</tt> style
</p>
<a name="index-other_002dfiles_002c-completion-tag"></a>
</dd>
<dt><tt>other-files</tt></dt>
<dd><p>for the names of any non-directory files.  This is used instead
of <tt>all-files</tt> when the <tt>list-dirs-first</tt> style is in effect.
</p>
<a name="index-packages_002c-completion-tag"></a>
</dd>
<dt><tt>packages</tt></dt>
<dd><p>for packages (e.g. <tt>rpm</tt> or installed <tt>Debian</tt> packages)
</p>
<a name="index-parameters_002c-completion-tag"></a>
</dd>
<dt><tt>parameters</tt></dt>
<dd><p>for names of parameters
</p>
<a name="index-path_002ddirectories_002c-completion-tag"></a>
</dd>
<dt><tt>path-directories</tt></dt>
<dd><p>for names of directories found by searching the <tt>cdpath</tt> array when
completing arguments of <tt>cd</tt> and related builtin commands (compare
<tt>local-directories</tt>)
</p>
<a name="index-paths_002c-completion-tag"></a>
</dd>
<dt><tt>paths</tt></dt>
<dd><p>used to look up the values of the <tt>expand</tt>, <tt>ambiguous</tt> and
<tt>special-dirs</tt> styles
</p>
<a name="index-pods_002c-completion-tag"></a>
</dd>
<dt><tt>pods</tt></dt>
<dd><p>for perl pods (documentation files)
</p>
<a name="index-ports_002c-completion-tag"></a>
</dd>
<dt><tt>ports</tt></dt>
<dd><p>for communication ports
</p>
<a name="index-prefixes_002c-completion-tag"></a>
</dd>
<dt><tt>prefixes</tt></dt>
<dd><p>for prefixes (like those of a URL)
</p>
<a name="index-printers_002c-completion-tag"></a>
</dd>
<dt><tt>printers</tt></dt>
<dd><p>for print queue names
</p>
<a name="index-processes_002c-completion-tag"></a>
</dd>
<dt><tt>processes</tt></dt>
<dd><p>for process identifiers
</p>
<a name="index-processes_002dnames_002c-completion-tag"></a>
</dd>
<dt><tt>processes-names</tt></dt>
<dd><p>used to look up the <tt>command</tt> style when generating the names of
processes for <tt>killall</tt>
</p>
<a name="index-sequences_002c-completion-tag"></a>
</dd>
<dt><tt>sequences</tt></dt>
<dd><p>for sequences (e.g. <tt>mh</tt> sequences)
</p>
<a name="index-sessions_002c-completion-tag"></a>
</dd>
<dt><tt>sessions</tt></dt>
<dd><p>for sessions in the <tt>zftp</tt> function suite
</p>
<a name="index-signals_002c-completion-tag"></a>
</dd>
<dt><tt>signals</tt></dt>
<dd><p>for signal names
</p>
<a name="index-strings_002c-completion-tag"></a>
</dd>
<dt><tt>strings</tt></dt>
<dd><p>for strings (e.g. the replacement strings for the <tt>cd</tt> builtin
command)
</p>
<a name="index-styles_002c-completion-tag"></a>
</dd>
<dt><tt>styles</tt></dt>
<dd><p>for styles used by the zstyle builtin command
</p>
<a name="index-suffixes_002c-completion-tag"></a>
</dd>
<dt><tt>suffixes</tt></dt>
<dd><p>for filename extensions
</p>
<a name="index-tags_002c-completion-tag"></a>
</dd>
<dt><tt>tags</tt></dt>
<dd><p>for tags (e.g. <tt>rpm</tt> tags)
</p>
<a name="index-targets_002c-completion-tag"></a>
</dd>
<dt><tt>targets</tt></dt>
<dd><p>for makefile targets
</p>
<a name="index-time_002dzones_002c-completion-tag"></a>
</dd>
<dt><tt>time-zones</tt></dt>
<dd><p>for time zones (e.g. when setting the <tt>TZ</tt> parameter)
</p>
<a name="index-types_002c-completion-tag"></a>
</dd>
<dt><tt>types</tt></dt>
<dd><p>for types of whatever (e.g. address types for the <tt>xhost</tt> command)
</p>
<a name="index-urls_002c-completion-tag"></a>
</dd>
<dt><tt>urls</tt></dt>
<dd><p>used to look up the <tt>urls</tt> and <tt>local</tt> styles when completing URLs
</p>
<a name="index-users_002c-completion-tag"></a>
</dd>
<dt><tt>users</tt></dt>
<dd><p>for usernames
</p>
<a name="index-values_002c-completion-tag"></a>
</dd>
<dt><tt>values</tt></dt>
<dd><p>for one of a set of values in certain lists
</p>
<a name="index-variant_002c-completion-tag"></a>
</dd>
<dt><tt>variant</tt></dt>
<dd><p>used by <tt>_pick_variant</tt> to look up the command to run when determining
what program is installed for a particular command name.
</p>
<a name="index-visuals_002c-completion-tag"></a>
</dd>
<dt><tt>visuals</tt></dt>
<dd><p>for X visuals
</p>
<a name="index-warnings_002c-completion-tag"></a>
</dd>
<dt><tt>warnings</tt></dt>
<dd><p>used to look up the <tt>format</tt> style for warnings
</p>
<a name="index-widgets_002c-completion-tag"></a>
</dd>
<dt><tt>widgets</tt></dt>
<dd><p>for zsh widget names
</p>
<a name="index-windows_002c-completion-tag"></a>
</dd>
<dt><tt>windows</tt></dt>
<dd><p>for IDs of X windows
</p>
<a name="index-zsh_002doptions_002c-completion-tag"></a>
</dd>
<dt><tt>zsh-options</tt></dt>
<dd><p>for shell options
</p>
</dd>
</dl>


<hr>
<a name="Standard-Styles"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Standard-Tags" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System-Configuration" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Control-Functions" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">20.3.3 Standard Styles</h3>
<a name="index-completion-system_002c-styles"></a>

<p>Note that the values of several of these styles represent boolean
values.  Any of the strings &lsquo;<tt>true</tt>&rsquo;, &lsquo;<tt>on</tt>&rsquo;,
&lsquo;<tt>yes</tt>&rsquo;, and &lsquo;<tt>1</tt>&rsquo; can be used for the value &lsquo;true&rsquo; and
any of the strings &lsquo;<tt>false</tt>&rsquo;, &lsquo;<tt>off</tt>&rsquo;, &lsquo;<tt>no</tt>&rsquo;, and &lsquo;<tt>0</tt>&rsquo; for
the value &lsquo;false&rsquo;.  The behavior for any other value is undefined 
except where explicitly mentioned.  The default value may
be either &lsquo;true&rsquo; or &lsquo;false&rsquo; if the style is not set.
</p>
<p>Some of these styles are tested first for every possible tag
corresponding to a type of match, and if no style was found, for the
<tt>default</tt> tag.  The most notable styles of this type are <tt>menu</tt>, 
<tt>list-colors</tt> and styles controlling completion listing such as 
<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 so that
a style using the <tt>default</tt> tag will normally be defined along the lines of:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:default' menu ...
</pre></div>

<dl compact="compact">
<dd><a name="index-accept_002dexact_002c-completion-style"></a>
</dd>
<dt><tt>accept-exact</tt></dt>
<dd><p>This is tested for the <tt>default</tt> tag in addition to the tags valid for
the current context.  If it is set to &lsquo;true&rsquo; and any of the trial
matches is the same as the string on the command line, this match will
immediately be accepted (even if it would otherwise be considered
ambiguous).
</p>
<p>When completing pathnames (where the tag used is &lsquo;<tt>paths</tt>&rsquo;)
this style accepts any number of patterns as the value in addition to
the boolean values.  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.
</p>
<p>This style is also used by the <tt>_expand</tt> completer to decide if
words beginning with a tilde or parameter expansion should be
expanded.  For example, if there are parameters
<tt>foo</tt> and <tt>foobar</tt>, the string &lsquo;<tt>$foo</tt>&rsquo; will only be expanded if 
<tt>accept-exact</tt> is set to &lsquo;true&rsquo;; otherwise the completion system will
be allowed to complete <tt>$foo</tt> to <tt>$foobar</tt>. If the style is set to
&lsquo;<tt>continue</tt>&rsquo;, <tt>_expand</tt> will add the expansion as a match and the completion
system will also be allowed to continue.
</p>
<a name="index-accept_002dexact_002ddirs_002c-completion-style"></a>
</dd>
<dt><tt>accept-exact-dirs</tt></dt>
<dd><p>This is used by filename completion.  Unlike <tt>accept-exact</tt> it is
a boolean.  By default, filename completion examines all components
of a path to see if there are completions of that component, even if
the component matches an existing directory.  For example, when
completion after <tt>/usr/bin/</tt>, the function examines possible
completions to <tt>/usr</tt>.
</p>
<p>When this style is &lsquo;true&rsquo;, any prefix of a path that matches an existing
directory is accepted without any attempt to complete it further.
Hence, in the given example, the path <tt>/usr/bin/</tt> is accepted
immediately and completion tried in that directory.
</p>
<p>This style is also useful when completing after directories that
magically appear when referenced, such as ZFS <tt>.zfs</tt> directories
or NetApp <tt>.snapshot</tt> directories.  When the style is set the
shell does not check for the existence of the directory within the
parent directory.
</p>
<p>If you wish to inhibit this behaviour entirely, set the <tt>path-completion</tt>
style (see below) to &lsquo;false&rsquo;.
</p>
<a name="index-add_002dspace_002c-completion-style"></a>
</dd>
<dt><tt>add-space</tt></dt>
<dd><p>This style is used by the <tt>_expand</tt> completer.  If it is &lsquo;true&rsquo; (the
default), a space will be inserted after all words resulting from the 
expansion, or a slash in the case of directory names.  If the value
is &lsquo;<tt>file</tt>&rsquo;, the completer will only add a space
to names of existing files.  Either a boolean &lsquo;true&rsquo; or the value
&lsquo;<tt>file</tt>&rsquo; may be combined with &lsquo;<tt>subst</tt>&rsquo;, in which case the completer
will not add a space to words generated from the expansion of a
substitution of the form &lsquo;<tt>$(</tt><var>...</var><tt>)</tt>&rsquo; or &lsquo;<tt>${</tt><var>...</var><tt>}</tt>&rsquo;.
</p>
<p>The <tt>_prefix</tt> completer uses this style as a simple boolean value
to decide if a space should be inserted before the suffix.
</p>
<a name="index-ambiguous_002c-completion-style"></a>
</dd>
<dt><tt>ambiguous</tt></dt>
<dd><p>This applies when completing non-final components of filename paths, in
other words those with a trailing slash.  If it is set, the cursor is
left after the first ambiguous component, even if menu completion is in
use.  The style is always tested with the <tt>paths</tt> tag.
</p>
<a name="index-assign_002dlist_002c-completion-style"></a>
</dd>
<dt><tt>assign-list</tt></dt>
<dd><p>When completing after an equals sign that is being treated as an
assignment, the completion system normally completes only one filename.
In some cases the value  may be a list of filenames separated by colons,
as with <tt>PATH</tt> and similar parameters.  This style can be set to a
list of patterns matching the names of such parameters.
</p>
<p>The default is to complete lists when the word on the line already
contains a colon.
</p>
<a name="index-auto_002ddescription_002c-completion-style"></a>
</dd>
<dt><tt>auto-description</tt></dt>
<dd><p>If set, this style&rsquo;s value will be used as the description for options that
are not described by the completion functions, but that have exactly
one argument.  The sequence &lsquo;<tt>%d</tt>&rsquo; 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 &lsquo;<tt>specify: %d</tt>&rsquo;. 
Note that this may not work for some commands.
</p>
<a name="index-avoid_002dcompleter_002c-completion-style"></a>
</dd>
<dt><tt>avoid-completer</tt></dt>
<dd><p>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.
</p>
<p>The default value for this style is &lsquo;<tt>_expand _old_list _correct
_approximate</tt>&rsquo;, i.e. it contains the completers for which a string
with all matches will almost never be wanted.
</p>
<a name="index-cache_002dpath_002c-completion-style"></a>
</dd>
<dt><tt>cache-path</tt></dt>
<dd><p>This style defines the path where any cache files containing dumped
completion data are stored.  It defaults to &lsquo;<tt>$ZDOTDIR/.zcompcache</tt>&rsquo;, or
&lsquo;<tt>$HOME/.zcompcache</tt>&rsquo; if <tt>$ZDOTDIR</tt> is not defined.  The completion
cache will not be used unless the <tt>use-cache</tt> style is set.
</p>
<a name="index-cache_002dpolicy_002c-completion-style"></a>
</dd>
<dt><tt>cache-policy</tt></dt>
<dd><p>This style defines the function that will be used to determine whether
a cache needs rebuilding.  See the section on the <tt>_cache_invalid</tt>
function below.
</p>
<a name="index-call_002dcommand_002c-completion-style"></a>
</dd>
<dt><tt>call-command</tt></dt>
<dd><p>This style is used in the function for commands such as <tt>make</tt> and
<tt>ant</tt> where calling the command directly to generate matches suffers
problems such as being slow or, as in the case of <tt>make</tt> can
potentially cause actions in the makefile to be executed. If it is set
to &lsquo;true&rsquo; the command is called to generate matches. The default value
of this style is &lsquo;false&rsquo;.
</p>
<a name="index-command_002c-completion-style"></a>
</dd>
<dt><tt>command</tt></dt>
<dd><p>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 that 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 &lsquo;<tt>builtin</tt>&rsquo; or &lsquo;<tt>command</tt>&rsquo; 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.
</p>
<p>As an example, the completion function for process IDs 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 &lsquo;true&rsquo;).
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 &lsquo;<tt>PID</tt>&rsquo; (or &lsquo;<tt>pid</tt>&rsquo;) to find the position of the
process IDs in the following lines.  If the line does not contain
&lsquo;<tt>PID</tt>&rsquo;, the first numbers in each of the other lines are taken as the 
process IDs to complete.
</p>
<p>Note that the completion function generally has to call the specified
command for each attempt to generate the completion list.  Hence
care should be taken to specify only commands that take a short
time to run, and in particular to avoid any that may never terminate.
</p>
<a name="index-command_002dpath_002c-completion-style"></a>
</dd>
<dt><tt>command-path</tt></dt>
<dd><p>This is a list of directories to search for commands to complete.  The
default for this style is the value of the special parameter <tt>path</tt>.
</p>
<a name="index-commands_002c-completion-style"></a>
</dd>
<dt><tt>commands</tt></dt>
<dd><p>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).  Its values give the default commands to
complete for those commands for which the completion function isn&rsquo;t
able to find them out automatically.  The default for this style are
the two strings &lsquo;<tt>start</tt>&rsquo; and &lsquo;<tt>stop</tt>&rsquo;.
</p>
<a name="index-complete_002c-completion-style"></a>
</dd>
<dt><tt>complete</tt></dt>
<dd><p>This is used by the <tt>_expand_alias</tt> function when invoked as a
bindable command.  If set to &lsquo;true&rsquo; and the word on the command
line is not the name of an alias, matching alias names will be
completed.
</p>
<a name="index-complete_002doptions_002c-completion-style"></a>
</dd>
<dt><tt>complete-options</tt></dt>
<dd><p>This is used by the completer for <tt>cd</tt>, <tt>chdir</tt> and <tt>pushd</tt>.
For these commands a <tt>-</tt> is used to introduce a directory stack entry
and completion of these is far more common than completing options.
Hence unless the value of this style is &lsquo;true&rsquo; options will not be
completed, even after an initial <tt>-</tt>.  If it is &lsquo;true&rsquo;, options will
be completed after an initial <tt>-</tt> unless there is a preceding
<tt>-</tt><tt>-</tt> on the command line.
</p>
<a name="index-completer_002c-completion-style"></a>
</dd>
<dt><tt>completer</tt></dt>
<dd><p>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
<a href="#Control-Functions">Control Functions</a>.
</p>
<p>Each string may be either the name of a completer function or a string
of the form &lsquo;<var>function</var><tt>:</tt><var>name</var>&rsquo;.  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 user-defined <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: 
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' completer _complete _complete:-foo
</pre></div>

<p>Here, completion will call the <tt>_complete</tt> completer twice, once
using &lsquo;<tt>complete</tt>&rsquo; and once using &lsquo;<tt>complete-foo</tt>&rsquo; in the
<var>completer</var> field of the context.  Normally, using the same
completer more than once only makes sense when used with the
&lsquo;<var>functions</var><tt>:</tt><var>name</var>&rsquo; 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.
</p>
<p>The default value for this style is &lsquo;<tt>_complete _ignored</tt>&rsquo;:
only completion will be done, first using the <tt>ignored-patterns</tt> style
and the <tt>$fignore</tt> array and then without ignoring matches.
</p>
<a name="index-condition_002c-completion-style"></a>
</dd>
<dt><tt>condition</tt></dt>
<dd><p>This style is used by the <tt>_list</tt> completer function to decide if
insertion of matches should be delayed unconditionally. The default is 
&lsquo;true&rsquo;.
</p>
<a name="index-delimiters_002c-completion-style"></a>
</dd>
<dt><tt>delimiters</tt></dt>
<dd><p>This style is used when adding a delimiter for use with history
modifiers or glob qualifiers that have delimited arguments.  It is
an array of preferred delimiters to add.  Non-special characters are
preferred as the completion system may otherwise become confused.
The default list is <tt>:</tt>, <tt>+</tt>, <tt>/</tt>, <tt>-</tt>, <tt>%</tt>.  The list
may be empty to force a delimiter to be typed.
</p>
<a name="index-disabled_002c-completion-style"></a>
</dd>
<dt><tt>disabled</tt></dt>
<dd><p>If this is set to &lsquo;true&rsquo;, the <tt>_expand_alias</tt> completer and bindable 
command will try to expand disabled aliases, too.  The default is
&lsquo;false&rsquo;.
</p>
<a name="index-domains_002c-completion-style"></a>
</dd>
<dt><tt>domains</tt></dt>
<dd><p>A list of names of network domains for completion.
If this is not set, domain names will be taken from
the file <tt>/etc/resolv.conf</tt>.
</p>
<a name="index-environ_002c-completion-style"></a>
</dd>
<dt><tt>environ</tt></dt>
<dd><p>The environ style is used when completing for &lsquo;<tt>sudo</tt>&rsquo;.  It is set to an
array of &lsquo;<var>VAR</var><tt>=</tt><var>value</var>&rsquo; assignments to be exported into the
local environment before the completion for the target command is invoked.
</p><div class="example">
<pre class="example">zstyle ':completion:*:sudo::' environ \ 
  PATH=&quot;/sbin:/usr/sbin:$PATH&quot; HOME=&quot;/root&quot;
</pre></div>

<a name="index-expand_002c-completion-style"></a>
</dd>
<dt><tt>expand</tt></dt>
<dd><p>This style is used when completing strings consisting of multiple
parts, such as path names.
</p>
<p>If one of its values is the string &lsquo;<tt>prefix</tt>&rsquo;, the partially typed
word from the line will be expanded as far as possible even if trailing
parts cannot be completed.
</p>
<p>If one of its values is the string &lsquo;<tt>suffix</tt>&rsquo;, 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.
However, menu completion can be used to cycle through all matches.
</p>
<a name="index-fake_002c-completion-style"></a>
</dd>
<dt><tt>fake</tt></dt>
<dd><p>This style may be set for any completion context.  It
specifies additional strings that will always be completed in that
context.  The form of each string is &lsquo;<var>value</var><tt>:</tt><var>description</var>&rsquo;; 
the colon and description may be omitted, but any literal colons in
<var>value</var> must be quoted with a backslash.  Any <var>description</var>
provided is shown alongside the value in completion listings.
</p>
<p>It is important to use a sufficiently restrictive context when specifying
fake strings.  Note that the styles <tt>fake-files</tt> and <tt>fake-parameters</tt>
provide additional features when completing files or parameters.
</p>
<a name="index-fake_002dalways_002c-completion-style"></a>
</dd>
<dt><tt>fake-always</tt></dt>
<dd><p>This works identically to the <tt>fake</tt> style except that
the <tt>ignored-patterns</tt> style is not applied to it.  This makes it
possible to override a set of matches completely by setting the
ignored patterns to &lsquo;<tt>*</tt>&rsquo;.
</p>
<p>The following shows a way of supplementing any tag with arbitrary data, but
having it behave for display purposes like a separate tag.  In this example
we use the features of the <tt>tag-order</tt> style to divide the
<tt>named-directories</tt> tag into two when performing completion with
the standard completer <tt>complete</tt> for arguments of <tt>cd</tt>.  The tag
<tt>named-directories-normal</tt> behaves as normal, but the tag
<tt>named-directories-mine</tt> contains a fixed set of directories.
This has the effect of adding the match group &lsquo;<tt>extra directories</tt>&rsquo; with
the given completions.
</p>
<div class="example">
<pre class="example">zstyle ':completion::complete:cd:*' tag-order \ 
  'named-directories:-mine:extra\ directories
  named-directories:-normal:named\ directories *'
zstyle ':completion::complete:cd:*:named-directories-mine' \ 
  fake-always mydir1 mydir2
zstyle ':completion::complete:cd:*:named-directories-mine' \ 
  ignored-patterns '*'
</pre></div>

<a name="index-fake_002dfiles_002c-completion-style"></a>
</dd>
<dt><tt>fake-files</tt></dt>
<dd><p>This style is used when completing files and looked up 
without a tag.  Its values are of the form
&lsquo;<var>dir</var><tt>:</tt><var>names...</var>&rsquo;.  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.  The dir may be a pattern; pattern characters
or colons in <var>dir</var> should be quoted with a backslash to be treated
literally.
</p>
<p>This can be useful on systems that support special file systems whose
top-level pathnames can not be listed or generated with glob patterns
(but see <tt>accept-exact-dirs</tt> for a more general way of dealing
with this problem).  It can also be used for directories for which one
does not have read permission.
</p>
<p>The pattern form can be used to add a certain &lsquo;magic&rsquo; entry
to all directories on a particular file system.
</p>
<a name="index-fake_002dparameters_002c-completion-style"></a>
</dd>
<dt><tt>fake-parameters</tt></dt>
<dd><p>This is used by the completion function for parameter names.
Its values are names of parameters that might not yet be
set but should be completed nonetheless.  Each name may also be 
followed by a colon and a string specifying the type of the parameter
(like &lsquo;<tt>scalar</tt>&rsquo;, &lsquo;<tt>array</tt>&rsquo; or &lsquo;<tt>integer</tt>&rsquo;).  If the type is
given, the name will only be completed if parameters of that type are
required in the particular context.  Names for which no type is
specified will always be completed.
</p>
<a name="index-file_002dlist_002c-completion-style"></a>
</dd>
<dt><tt>file-list</tt></dt>
<dd><p>This style controls whether files completed using the standard builtin
mechanism are to be listed with a long list similar to <tt>ls -l</tt>.
Note that this feature uses the shell module
<tt>zsh/stat</tt> for file information; this loads the builtin <tt>stat</tt>
which will replace any external <tt>stat</tt> executable.  To avoid
this the following code can be included in an initialization file:
</p>
<div class="example">
<pre class="example">zmodload -i zsh/stat
disable stat
</pre></div>

<p>The style may either be set to a &lsquo;true&rsquo; value (or &lsquo;<tt>all</tt>&rsquo;), or
one of the values &lsquo;<tt>insert</tt>&rsquo; or &lsquo;<tt>list</tt>&rsquo;, indicating that files
are to be listed in long format in all circumstances, or when
attempting to insert a file name, or when listing file names
without attempting to insert one.
</p>
<p>More generally, the value may be an array of any of the above values,
optionally followed by <tt>=</tt><var>num</var>.  If <var>num</var> is present it
gives the maximum number of matches for which long listing style
will be used.  For example,
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' file-list list=20 insert=10
</pre></div>

<p>specifies that long format will be used when listing up to 20 files
or inserting a file with up to 10 matches (assuming a listing
is to be shown at all, for example on an ambiguous completion), else short
format will be used.
</p>
<div class="example">
<pre class="example">zstyle -e ':completion:*' file-list \ 
       '(( ${+NUMERIC} )) &amp;&amp; reply=(true)'
</pre></div>

<p>specifies that long format will be used any time a numeric argument is
supplied, else short format.
</p>
<a name="index-file_002dpatterns_002c-completion-style"></a>
</dd>
<dt><tt>file-patterns</tt></dt>
<dd><p>This is used by the standard function for completing filenames,
<tt>_files</tt>.  If the style is unset up to three tags are offered,
&lsquo;<tt>globbed-files</tt>&rsquo;,&lsquo;<tt>directories</tt>&rsquo; and &lsquo;<tt>all-files</tt>&rsquo;, depending on
the types of files  expected by the caller of <tt>_files</tt>.  The first two
(&lsquo;<tt>globbed-files</tt>&rsquo; and &lsquo;<tt>directories</tt>&rsquo;) are normally offered
together to make it easier to complete files in sub-directories.
</p>
<p>The <tt>file-patterns</tt> style provides alternatives to the default tags,
which are not used.  Its value consists of elements of the form
&lsquo;<var>pattern</var><tt>:</tt><var>tag</var>&rsquo;; each string may contain any number of
such specifications separated by spaces.
</p>
<p>The <var>pattern</var> is a pattern that is to be used to generate filenames.
Any occurrence of the sequence &lsquo;<tt>%p</tt>&rsquo; is replaced by any
pattern(s)
passed by the function calling <tt>_files</tt>.  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.
</p>
<p>The <var>tag</var>s of all strings in the value will be offered by <tt>_files</tt>
and used when looking up other styles.  Any <var>tag</var>s in the same
word will be offered at the same time and before later words.
If no &lsquo;<tt>:</tt><var>tag</var>&rsquo; is given the &lsquo;<tt>files</tt>&rsquo; tag will be used.
</p>
<p>The <var>tag</var> may also be followed by an optional second colon and a
description, which will be used for the &lsquo;<tt>%d</tt>&rsquo; 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 &lsquo;<tt>%d</tt>&rsquo;, that is replaced with the
description supplied by the completion function.
</p>
<p>For example, to make the <tt>rm</tt> command first complete only names of
object files and then the names of all files if there is no matching
object file:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:*:rm:*:*' file-patterns \ 
    '*.o:object-files' '%p:all-files'
</pre></div>

<p>To alter the default behaviour of file completion &mdash; offer files
matching a pattern and directories on the first attempt, then all files
&mdash; to offer only matching files on the first attempt, then directories,
and finally all files:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' file-patterns \ 
    '%p:globbed-files' '*(-/):directories' '*:all-files'
</pre></div>

<p>This works even where there is no special pattern: <tt>_files</tt> matches
all files using the pattern &lsquo;<tt>*</tt>&rsquo; at the first step and stops when it
sees this pattern.  Note also it will never try a pattern more than once
for a single completion attempt.
</p>
<p>During the execution of completion functions, the <tt>EXTENDED_GLOB</tt>
option is in effect, so the characters &lsquo;<tt>#</tt>&rsquo;, &lsquo;<tt>~</tt>&rsquo; and &lsquo;<tt>^</tt>&rsquo; have
special meanings in the patterns.
</p>
<a name="index-file_002dsort_002c-completion-style"></a>
</dd>
<dt><tt>file-sort</tt></dt>
<dd><p>The standard filename completion function uses this style without a tag
to determine in which order the names should be listed; menu completion
will cycle through them in the same order.  The possible
values are: &lsquo;<tt>size</tt>&rsquo; to sort by the size of the file;
&lsquo;<tt>links</tt>&rsquo; to sort by the number of links to the file;
&lsquo;<tt>modification</tt>&rsquo; (or &lsquo;<tt>time</tt>&rsquo; or &lsquo;<tt>date</tt>&rsquo;) to sort by the last
modification time; &lsquo;<tt>access</tt>&rsquo; to sort by the last access time; and
&lsquo;<tt>inode</tt>&rsquo; (or &lsquo;<tt>change</tt>&rsquo;) to sort 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
&lsquo;<tt>reverse</tt>&rsquo;, sorting is done in the opposite order.  If the value
contains the string &lsquo;<tt>follow</tt>&rsquo;, timestamps are associated with the
targets of symbolic links; the default is to use the timestamps
of the links themselves.
</p>
<a name="index-filter_002c-completion-style"></a>
</dd>
<dt><tt>filter</tt></dt>
<dd><p>The <tt>ldap</tt> plugin of email address completion (see <tt>_email_addresses</tt>) uses
this style to specify
the attributes to match against when filtering entries.  So for example, if
the style is set to &lsquo;<tt>sn</tt>&rsquo;, matching is done against surnames.  Standard
LDAP filtering is used so normal completion matching is bypassed.  If this
style is not set, the LDAP plugin is skipped.  You may also need to set the
<tt>command</tt> style to specify how to connect to your LDAP server.
</p>
<a name="index-force_002dlist_002c-completion-style"></a>
</dd>
<dt><tt>force-list</tt></dt>
<dd><p>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
&lsquo;<tt>always</tt>&rsquo;, the list will always be shown, even if there is only a
single match that will immediately be 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.
</p>
<p>This style is tested for the default tag as well as for each tag valid
for the current completion.  Hence the listing can be forced only for
certain types of match.
</p>
<a name="index-format_002c-completion-style"></a>
</dd>
<dt><tt>format</tt></dt>
<dd><p>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
&lsquo;<tt>%d</tt>&rsquo; in this string will be replaced with a short description of
what these matches are.  This string may also contain the following
sequences to specify output attributes
(see <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt Expansion</a>):
&lsquo;<tt>%B</tt>&rsquo;, &lsquo;<tt>%S</tt>&rsquo;, &lsquo;<tt>%U</tt>&rsquo;, &lsquo;<tt>%F</tt>&rsquo;, &lsquo;<tt>%K</tt>&rsquo; and their lower case
counterparts, as well as &lsquo;<tt>%{</tt>...<tt>%}</tt>&rsquo;.  &lsquo;<tt>%F</tt>&rsquo;, &lsquo;<tt>%K</tt>&rsquo; and
&lsquo;<tt>%{</tt>...<tt>%}</tt>&rsquo; take arguments in the same form as prompt
expansion.  Note that the sequence &lsquo;<tt>%G</tt>&rsquo; is not available; an argument
to &lsquo;<tt>%{</tt>&rsquo; should be used instead.
</p>
<p>The style is tested with each tag valid for the current completion
before it is tested for the <tt>descriptions</tt> tag.  Hence different format 
strings can be defined for different types of match.
</p>
<p>Note also that some completer functions define additional
&lsquo;<tt>%</tt>&rsquo;-sequences.  These are described for the completer functions that 
make use of them.
</p>
<p>Some completion functions display messages that may be customised by
setting this style for the <tt>messages</tt> tag.  Here, the &lsquo;<tt>%d</tt>&rsquo; is
replaced with a message given by the completion function.
</p>
<p>Finally, the format string is looked up with the <tt>warnings</tt> tag, 
for use when no matches could be generated at all.  In this case the
&lsquo;<tt>%d</tt>&rsquo; is replaced with the descriptions for the matches that were
expected separated by spaces.  The sequence &lsquo;<tt>%D</tt>&rsquo; is replaced with
the same descriptions separated by newlines.
</p>
<p>It is possible to use printf-style field width specifiers with &lsquo;<tt>%d</tt>&rsquo;
and similar escape sequences.  This is handled by the <tt>zformat</tt>
builtin command from the <tt>zsh/zutil</tt> module, see
<a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil Module</a>.
</p>
<a name="index-glob_002c-completion-style"></a>
</dd>
<dt><tt>glob</tt></dt>
<dd><p>This is used by the <tt>_expand</tt> completer.  If
it is set to &lsquo;true&rsquo; (the default), globbing will be attempted on the
words resulting from a previous substitution (see the <tt>substitute</tt>
style) or else the original string from the line.
</p>
<a name="index-global_002c-completion-style"></a>
</dd>
<dt><tt>global</tt></dt>
<dd><p>If this is set to &lsquo;true&rsquo; (the default), the <tt>_expand_alias</tt>
completer and bindable command will try to expand global aliases.
</p>
<a name="index-group_002dname_002c-completion-style"></a>
</dd>
<dt><tt>group-name</tt></dt>
<dd><p>The completion system can group different types of matches, which appear
in separate lists.  This style can be used to give the names of 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:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:*:-command-:*:commands' \ 
       group-name commands
zstyle ':completion:*:*:-command-:*:functions' \ 
       group-name functions
</pre></div>

<p>As a consequence, any match with the same tag will be displayed in the
same group.
</p>
<p>If the name given is the empty string 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:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' group-name ''
</pre></div>

<p>All matches for which no group name is defined will be put in a group
named <tt>-default-</tt>.
</p>
<a name="index-group_002dorder_002c-completion-style"></a>
</dd>
<dt><tt>group-order</tt></dt>
<dd><p>This style is additional to the <tt>group-name</tt> style to specify the
order for display of the groups defined by that style (compare <tt>tag-order</tt>,
which determines which completions appear at all).  The groups named
are shown in the given order; any other groups
are shown in the order defined by the completion function.
</p>
<p>For example, to have names of builtin commands, shell functions and
external commands appear in that order when completing in command
position:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:*:-command-:*:*' group-order \ 
       builtins functions commands
</pre></div>

<a name="index-groups_002c-completion-style"></a>
</dd>
<dt><tt>groups</tt></dt>
<dd><p>A list of names of UNIX groups.  If this is not set,
group names are taken from the YP database or the file &lsquo;<tt>/etc/group</tt>&rsquo;.
</p>
<a name="index-hidden_002c-completion-style"></a>
</dd>
<dt><tt>hidden</tt></dt>
<dd><p>If this is set to &lsquo;true&rsquo;, matches for the given context
will not be listed, although
any description for the matches set with the <tt>format</tt> style will be
shown.  If it is set to &lsquo;<tt>all</tt>&rsquo;, not even the description will be
displayed.
</p>
<p>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.
</p>
<a name="index-hosts_002c-completion-style"></a>
</dd>
<dt><tt>hosts</tt></dt>
<dd><p>A list of names of hosts that should be completed.  If this is not set,
hostnames are taken from the file &lsquo;<tt>/etc/hosts</tt>&rsquo;.
</p>
<a name="index-hosts_002dports_002c-completion-style"></a>
</dd>
<dt><tt>hosts-ports</tt></dt>
<dd><p>This style is used by commands that need or accept hostnames and
network ports.  The strings in the value should be of the form
&lsquo;<var>host</var><tt>:</tt><var>port</var>&rsquo;.  Valid ports are determined by the presence
of hostnames; multiple ports for the same host may appear.
</p>
<a name="index-ignore_002dline_002c-completion-style"></a>
</dd>
<dt><tt>ignore-line</tt></dt>
<dd><p>This is tested for each tag valid for the current completion.  If
it is set to &lsquo;true&rsquo;, none of the words that are already on the line
will be considered as possible completions.  If it is set to
&lsquo;<tt>current</tt>&rsquo;, the word the cursor is on will not be considered as a
possible completion.  The value &lsquo;<tt>current-shown</tt>&rsquo; is similar but only
applies if the list of completions is currently shown on the screen.
Finally, if the style is set to &lsquo;<tt>other</tt>&rsquo;, all words on the line except
for the current one will be excluded from the possible completions.
</p>
<p>The values &lsquo;<tt>current</tt>&rsquo; and &lsquo;<tt>current-shown</tt>&rsquo; are a bit like the
opposite of the <tt>accept-exact</tt> style:  only strings with
missing characters will be completed.
</p>
<p>Note that you almost certainly don&rsquo;t want to set this to &lsquo;true&rsquo; or
&lsquo;<tt>other</tt>&rsquo; for a general
context such as &lsquo;<tt>:completion:*</tt>&rsquo;.  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.
</p>
<a name="index-ignore_002dparents_002c-completion-style"></a>
</dd>
<dt><tt>ignore-parents</tt></dt>
<dd><p>The style is tested without a tag by the function completing pathnames
in order 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:
</p>
<dl compact="compact">
<dt><tt>parent</tt></dt>
<dd><p>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.
</p>
</dd>
<dt><tt>pwd</tt></dt>
<dd><p>The name of the current working directory will not be completed; hence,
for example, completion after <tt>../</tt> will not use the name of the current
directory.
</p>
</dd>
</dl>

<p>In addition, the value may include one or both of:
</p>
<dl compact="compact">
<dt><tt>..</tt></dt>
<dd><p>Ignore the specified directories only when the word on the line contains
the substring &lsquo;<tt>../</tt>&rsquo;.
</p>
</dd>
<dt><tt>directory</tt></dt>
<dd><p>Ignore the specified directories only when names of directories are
completed, not when completing names of files.
</p>
</dd>
</dl>

<p>Excluded values act in a similar fashion to values of the
<tt>ignored-patterns</tt> style, so they can be restored to consideration by
the <tt>_ignored</tt> completer.
</p>
<a name="index-extra_002dverbose_002c-completion-style"></a>
</dd>
<dt><tt>extra-verbose</tt></dt>
<dd><p>If set, the completion listing is more verbose at the cost of
a probable decrease in completion speed.  Completion performance
will suffer if this style is set to &lsquo;true&rsquo;.
</p>
<a name="index-ignored_002dpatterns_002c-completion-style"></a>
</dd>
<dt><tt>ignored-patterns</tt></dt>
<dd><p>A list of patterns; any trial completion matching one of the patterns
will be excluded from consideration.  The
<tt>_ignored</tt> completer can appear in the list of completers to
restore the ignored matches.  This is a more configurable
version of the shell parameter <tt>$fignore</tt>.
</p>
<p>Note that the
<tt>EXTENDED_GLOB</tt> option is set during the execution of completion
functions, so the characters &lsquo;<tt>#</tt>&rsquo;, &lsquo;<tt>~</tt>&rsquo; and &lsquo;<tt>^</tt>&rsquo; have special
meanings in the patterns.
</p>
<a name="index-insert_002c-completion-style"></a>
</dd>
<dt><tt>insert</tt></dt>
<dd><p>This style is used by the <tt>_all_matches</tt> completer to decide whether to
insert the list of all matches unconditionally instead of adding the
list as another match.
</p>
<a name="index-insert_002dids_002c-completion-style"></a>
</dd>
<dt><tt>insert-ids</tt></dt>
<dd><p>When completing process IDs, for example as arguments to the <tt>kill</tt> and
<tt>wait</tt> builtins the name of a
command may 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 &lsquo;<tt>menu</tt>&rsquo;) the name will be converted
immediately to a set of possible IDs, and menu completion will be started
to cycle through them.
</p>
<p>If the value of the style is &lsquo;<tt>single</tt>&rsquo;,
the shell will wait until the user has typed enough to make the command
unique before converting the name to an ID; attempts at completion will
be unsuccessful until that point.  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 to the corresponding IDs.
</p>
<a name="index-insert_002dtab_002c-completion-style"></a>
</dd>
<dt><tt>insert-tab</tt></dt>
<dd><p>If this is set to &lsquo;true&rsquo;, the completion system will
insert a TAB character (assuming that was used to start completion) instead
of performing completion when there is no non-blank character to the left
of the cursor.  If it is set to &lsquo;false&rsquo;, completion will be done even there.
</p>
<p>The value may also contain the substrings &lsquo;<tt>pending</tt>&rsquo; or
&lsquo;<tt>pending=</tt><var>val</var>&rsquo;.  In this case, the typed character will be
inserted instead of starting completion when there is unprocessed input
pending.  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 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.
</p>
<p>The default value of this style is &lsquo;true&rsquo; except for completion within
<tt>vared</tt> builtin command where it is &lsquo;false&rsquo;.
</p>
<a name="index-insert_002dunambiguous_002c-completion-style"></a>
</dd>
<dt><tt>insert-unambiguous</tt></dt>
<dd><p>This is used by the <tt>_match</tt> and <tt>_approximate</tt> completers.
These completers are often used with menu completion since the word typed
may bear little resemblance to the final completion.
However, if this style is &lsquo;true&rsquo;, the completer will start menu
completion only if it could find no unambiguous initial string at
least as long as the original string typed by the user.
</p>
<p>In the case of the <tt>_approximate</tt> completer, the completer
field in the context will already have been set 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.
</p>
<p>In the case of the <tt>_match</tt> completer, the style may also be set to
the string &lsquo;<tt>pattern</tt>&rsquo;.  Then the pattern on the line is left
unchanged if it does not match unambiguously.
</p>
<a name="index-gain_002dprivileges_002c-completion-style"></a>
</dd>
<dt><tt>gain-privileges</tt></dt>
<dd><p>If set to <tt>true</tt>, this style enables the use of commands like <tt>sudo</tt>
or <tt>doas</tt> to gain extra privileges when retrieving information for
completion. This is only done when a command such as <tt>sudo</tt> appears on
the command-line. To force the use of, e.g. <tt>sudo</tt> or to override any
prefix that might be added due to <tt>gain-privileges</tt>, the <tt>command</tt>
style can be used with a value that begins with a hyphen.
</p>
<a name="index-keep_002dprefix_002c-completion-style"></a>
</dd>
<dt><tt>keep-prefix</tt></dt>
<dd><p>This style is used by the <tt>_expand</tt> completer.  If it is &lsquo;true&rsquo;, the
completer will try to keep a prefix containing a tilde or parameter
expansion.  Hence, for example, the string &lsquo;<tt>~/f*</tt>&rsquo; would be expanded to
&lsquo;<tt>~/foo</tt>&rsquo; instead of &lsquo;<tt>/home/user/foo</tt>&rsquo;.  If the style is set to
&lsquo;<tt>changed</tt>&rsquo; (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 forces the prefix to be
expanded unconditionally.
</p>
<p>The behaviour of <tt>_expand</tt> when this style is &lsquo;true&rsquo; is to cause <tt>_expand</tt>
to give up when a single expansion with the restored prefix is the same
as the original; hence any remaining completers may be called.
</p>
<a name="index-last_002dprompt_002c-completion-style"></a>
</dd>
<dt><tt>last-prompt</tt></dt>
<dd><p>This is a more flexible form of the <tt>ALWAYS_LAST_PROMPT</tt> option.
If it is &lsquo;true&rsquo;, the completion system will try to return the cursor to
the previous command line after displaying a completion list.  It is
tested for all tags valid for the current completion, then the
<tt>default</tt> tag.  The cursor will be moved back to the
previous line if this style is &lsquo;true&rsquo; for all types of match.  Note
that unlike the <tt>ALWAYS_LAST_PROMPT</tt> option this is independent of the
numeric argument.
</p>
<a name="index-known_002dhosts_002dfiles"></a>
</dd>
<dt><tt>known-hosts-files</tt></dt>
<dd><p>This style should contain a list of files to search for host names and
(if the <tt>use-ip</tt> style is set) IP addresses in a format compatible with
ssh <tt>known_hosts</tt> files.  If it is not set, the files
<tt>/etc/ssh/ssh_known_hosts</tt> and <tt>~/.ssh/known_hosts</tt> are used.
</p>
<a name="index-list_002c-completion-style"></a>
</dd>
<dt><tt>list</tt></dt>
<dd><p>This style is used by the <tt>_history_complete_word</tt> bindable command.
If it is set to &lsquo;true&rsquo; it has no effect.  If it is set to &lsquo;false&rsquo;
matches will not be listed.  This overrides the setting of the options
controlling listing behaviour, in particular <tt>AUTO_LIST</tt>.  The context
always starts with &lsquo;<tt>:completion:history-words</tt>&rsquo;.
</p>
<a name="index-list_002dcolors_002c-completion-style"></a>
</dd>
<dt><tt>list-colors</tt></dt>
<dd><p>If the <tt>zsh/complist</tt> module is loaded, this style can be used to set
color specifications.  This mechanism replaces the use of the
<tt>ZLS_COLORS</tt> and <tt>ZLS_COLOURS</tt> parameters described in
<a href="Zsh-Modules.html#The-zsh_002fcomplist-Module">The zsh/complist Module</a>, but the syntax is the same.
</p>
<p>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.  
</p>
<p>In addition to setting styles for specific tags, it is also possible to
use group names specified explicitly by the <tt>group-name</tt> tag together
with the &lsquo;<tt>(group)</tt>&rsquo; syntax allowed by the <tt>ZLS_COLORS</tt> and
<tt>ZLS_COLOURS</tt> parameters and simply using the <tt>default</tt> tag.
</p>
<p>It is possible to use any color specifications already set up for the GNU
version of the <tt>ls</tt> command:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:default' list-colors \ 
       ${(s.:.)LS_COLORS}
</pre></div>

<p>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>).
</p>
<a name="index-list_002ddirs_002dfirst_002c-completion-style"></a>
</dd>
<dt><tt>list-dirs-first</tt></dt>
<dd><p>This is used by file completion.  If set, directories to be completed
are listed separately from and before completion for other files,
regardless of tag ordering.  In addition, the tag <tt>other-files</tt>
is used in place of <tt>all-files</tt> for the remaining files, to indicate
that no directories are presented with that tag.
</p>
<a name="index-list_002dgrouped_002c-completion-style"></a>
</dd>
<dt><tt>list-grouped</tt></dt>
<dd><p>If this style is &lsquo;true&rsquo; (the default), the completion system will try to
make certain completion listings more compact by grouping matches.
For example, options for commands that have the same description (shown
when the <tt>verbose</tt> style is set to &lsquo;true&rsquo;) will appear as a single
entry.  However, menu selection can be used to cycle through all the
matches.
</p>
<a name="index-list_002dpacked_002c-completion-style"></a>
</dd>
<dt><tt>list-packed</tt></dt>
<dd><p>This is tested for each tag valid in the current context as well as the
<tt>default</tt> tag.  If it is set to &lsquo;true&rsquo;, the corresponding matches
appear in listings as if the <tt>LIST_PACKED</tt> option were set.  If it is
set to &lsquo;false&rsquo;, they are listed normally.
</p>
<a name="index-list_002dprompt_002c-completion-style"></a>
</dd>
<dt><tt>list-prompt</tt></dt>
<dd><p>If this style is set for the <tt>default</tt> tag,
completion lists that don&rsquo;t fit on the screen can be scrolled (see
<a href="Zsh-Modules.html#The-zsh_002fcomplist-Module">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.
</p>
<p>The value may contain the escape sequences:
&lsquo;<tt>%l</tt>&rsquo; or &lsquo;<tt>%L</tt>&rsquo;, which will be replaced by the number of the last line
displayed and the total number of lines; &lsquo;<tt>%m</tt>&rsquo; or &lsquo;<tt>%M</tt>&rsquo;, 
the number of the  last match shown and the total number of
matches; and &lsquo;<tt>%p</tt>&rsquo; and &lsquo;<tt>%P</tt>&rsquo;, &lsquo;<tt>Top</tt>&rsquo;
when at the beginning of the list, &lsquo;<tt>Bottom</tt>&rsquo; when at the end and the
position shown as a percentage of the total length otherwise.  In each
case the form with the uppercase letter will be replaced by a string of fixed
width, padded to the  right with spaces, while the lowercase form will
be replaced by a variable width string.  As in other prompt strings, the
escape sequences &lsquo;<tt>%S</tt>&rsquo;, &lsquo;<tt>%s</tt>&rsquo;, &lsquo;<tt>%B</tt>&rsquo;, &lsquo;<tt>%b</tt>&rsquo;, &lsquo;<tt>%U</tt>&rsquo;,
&lsquo;<tt>%u</tt>&rsquo; for entering and leaving the display modes
standout, bold and underline, and &lsquo;<tt>%F</tt>&rsquo;, &lsquo;<tt>%f</tt>&rsquo;, &lsquo;<tt>%K</tt>&rsquo;, &lsquo;<tt>%k</tt>&rsquo; for
changing the foreground background colour, are also available, as is the form
&lsquo;<tt>%{</tt>...<tt>%}</tt>&rsquo; for enclosing escape sequences which display with zero
(or, with a numeric argument, some other) width.
</p>
<p>After deleting this prompt the variable <tt>LISTPROMPT</tt> should be unset for
the removal to take effect.
</p>
<a name="index-list_002drows_002dfirst_002c-completion-style"></a>
</dd>
<dt><tt>list-rows-first</tt></dt>
<dd><p>This style is tested in the same way as the <tt>list-packed</tt> style and
determines whether matches are to be listed in a rows-first fashion as
if the <tt>LIST_ROWS_FIRST</tt> option were set.
</p>
<a name="index-list_002dsuffixes_002c-completion-style"></a>
</dd>
<dt><tt>list-suffixes</tt></dt>
<dd><p>This style is used by the function that completes filenames.  If it is
&lsquo;true&rsquo;, and completion is attempted on a string containing multiple partially
typed pathname components, all ambiguous components will be shown.
Otherwise, completion stops at the first ambiguous component.
</p>
<a name="index-list_002dseparator_002c-completion-style"></a>
</dd>
<dt><tt>list-separator</tt></dt>
<dd><p>The value of this style is used in completion listing to separate the
string to complete from a description when possible (e.g. when
completing options).  It defaults to &lsquo;<tt>-</tt><tt>-</tt>&rsquo; (two hyphens).
</p>
<a name="index-local_002c-completion-style"></a>
</dd>
<dt><tt>local</tt></dt>
<dd><p>This is for use with functions that complete URLs for which the
corresponding files are available directly from the 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.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' local toast \ 
    /var/http/public/toast public_html
</pre></div>

<p>Completion after &lsquo;<tt>http://toast/stuff/</tt>&rsquo; will look for files in the
directory <tt>/var/http/public/toast/stuff</tt>,  while completion after
&lsquo;<tt>http://toast/~yousir/</tt>&rsquo; will look for files in the directory
<tt>~yousir/public_html</tt>.
</p>
<a name="index-mail_002ddirectory_002c-completion-style"></a>
</dd>
<dt><tt>mail-directory</tt></dt>
<dd><p>If set, zsh will assume that mailbox files can be found in
the directory specified.  It defaults to &lsquo;<tt>~/Mail</tt>&rsquo;.
</p>
<a name="index-match_002doriginal_002c-completion-style"></a>
</dd>
<dt><tt>match-original</tt></dt>
<dd><p>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
&lsquo;<tt>*</tt>&rsquo; at the cursor position.  If set to any other non-empty value,
it will first try to generate matches without inserting the &lsquo;<tt>*</tt>&rsquo;
and if that yields no matches, it will try again with the &lsquo;<tt>*</tt>&rsquo;
inserted.  If it is unset or set to the empty string, matching will
only be performed with the &lsquo;<tt>*</tt>&rsquo; inserted.
</p>
<a name="index-matcher_002c-completion-style"></a>
</dd>
<dt><tt>matcher</tt></dt>
<dd><p>This style is tested separately for each tag valid in the current
context.  Its value is placed before any match specifications given by the
<tt>matcher-list</tt> style so can override them via the use of an <tt>x:</tt>
specification.  The value should be in the form described in
<a href="Completion-Widgets.html#Completion-Matching-Control">Completion Matching Control</a>.  For examples of this, see the description of the <tt>tag-order</tt> style.
</p>
<a name="index-matcher_002dlist_002c-completion-style"></a>
</dd>
<dt><tt>matcher-list</tt></dt>
<dd><p>This style can be set to a list of match specifications that are to
be applied everywhere. Match specifications are described in
<a href="Completion-Widgets.html#Completion-Matching-Control">Completion Matching Control</a>.
The completion system will try them one after another for each completer
selected.  For example, to try first simple completion and, if that
generates no matches, case-insensitive completion:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
</pre></div>

<p>By default each specification replaces the previous one; however, if a
specification is prefixed with <tt>+</tt>, it is added to the existing list.
Hence it is possible to create increasingly general specifications
without repetition:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' matcher-list \ 
       '' '+m:{a-z}={A-Z}' '+m:{A-Z}={a-z}'
</pre></div>

<p>It is possible to create match specifications valid for particular
completers by using the third field of the context.  This applies only
to completers that override the global matcher-list, which as of this
writing includes only <tt>_prefix</tt> and <tt>_ignored</tt>.  For example, to
use the completers <tt>_complete</tt> and <tt>_prefix</tt> but allow
case-insensitive completion only with <tt>_complete</tt>:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' completer _complete _prefix
zstyle ':completion:*:complete:*:*:*' matcher-list \ 
       '' 'm:{a-zA-Z}={A-Za-z}'
</pre></div>

<p>User-defined names, as explained for the <tt>completer</tt> style, are
available.  This makes it possible to try the same completer more than
once with different match specifications each time.  For example, to try
normal completion without a match specification, then normal completion
with case-insensitive matching, then correction, and finally
partial-word completion:
</p>
<div class="example">
<pre class="example">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></div>

<p>If the style is unset in any context no match specification is applied.
Note also that some completers such as <tt>_correct</tt> and <tt>_approximate</tt>
do not use the match specifications at all, though these completers will
only ever be called once even if the <tt>matcher-list</tt> contains more than
one element.
</p>
<p>Where multiple specifications are useful, note that the <em>entire</em>
completion is done for each element of <tt>matcher-list</tt>, which can
quickly reduce the shell&rsquo;s performance.  As a rough rule of thumb,
one to three strings will give acceptable performance.  On the other
hand, putting multiple space-separated values into the same string does
not have an appreciable impact on performance.
</p>
<p>If there is no current matcher or it is empty, and the option
<tt>NO_CASE_GLOB</tt> is in effect, the matching for files is performed
case-insensitively in any case.  However, any matcher must
explicitly specify case-insensitive matching if that is required.
</p>
<a name="index-max_002derrors_002c-completion-style"></a>
</dd>
<dt><tt>max-errors</tt></dt>
<dd><p>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.
</p>
<p>If the value for this style contains the string &lsquo;<tt>numeric</tt>&rsquo;, the 
completer function will take any numeric argument as the
maximum number of errors allowed. For example, with
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:approximate:::' max-errors 2 numeric
</pre></div>

<p>two errors are allowed if no numeric argument is given, but with
a numeric argument of six (as in &lsquo;<tt>ESC-6 TAB</tt>&rsquo;), up to six
errors are accepted.  Hence with a value of &lsquo;<tt>0 numeric</tt>&rsquo;, no correcting
completion will be attempted unless a numeric argument is given.
</p>
<p>If the value contains the string &lsquo;<tt>not-numeric</tt>&rsquo;, 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, &lsquo;<tt>2 not-numeric</tt>&rsquo; specifies that
correcting completion with two errors will usually be performed, but if a
numeric argument is given, correcting completion will not be
performed.
</p>
<p>The default value for this style is &lsquo;<tt>2 numeric</tt>&rsquo;.
</p>
<a name="index-max_002dmatches_002dwidth_002c-completion-style"></a>
</dd>
<dt><tt>max-matches-width</tt></dt>
<dd><p>This style is used to determine the trade off between the width of the
display used for matches and the width used for their descriptions when
the <tt>verbose</tt> style is in effect.  The value gives the number of
display columns to reserve for the matches.  The default is half the
width of the screen.
</p>
<p>This has the most impact when several matches have the
same description and so will be grouped together.  Increasing the style
will allow more matches to be grouped together; decreasing it will allow
more of the description to be visible.
</p>
<a name="index-menu_002c-completion-style"></a>
</dd>
<dt><tt>menu</tt></dt>
<dd><p>If this is &lsquo;true&rsquo; in the context of any of the tags defined
for the current completion menu completion will be used.  The value for
a specific tag will take precedence over that for the &lsquo;<tt>default</tt>&rsquo; tag.
</p>
<p>If none of the values found in this way is &lsquo;true&rsquo; but at least
one is set to &lsquo;<tt>auto</tt>&rsquo;, the shell behaves as if the <tt>AUTO_MENU</tt>
option is set.
</p>
<p>If one of the values is explicitly set to &lsquo;false&rsquo;, menu
completion will be explicitly turned off, overriding the
<tt>MENU_COMPLETE</tt> option and other settings.
</p>
<p>In the form &lsquo;<tt>yes=</tt><var>num</var>&rsquo;, where &lsquo;<tt>yes</tt>&rsquo; may be any of the
&lsquo;true&rsquo; values (&lsquo;<tt>yes</tt>&rsquo;, &lsquo;<tt>true</tt>&rsquo;, &lsquo;<tt>on</tt>&rsquo; and &lsquo;<tt>1</tt>&rsquo;),
menu completion will be turned on if there are at least <var>num</var> matches.
In the form &lsquo;<tt>yes=long</tt>&rsquo;, menu completion will be turned on
if the list does not fit on the screen.  This does not activate menu
completion if the widget normally only lists completions, but menu
completion can be activated in that case with the value &lsquo;<tt>yes=long-list</tt>&rsquo;
(Typically, the value &lsquo;<tt>select=long-list</tt>&rsquo; described later is more
useful as it provides control over scrolling.)
</p>
<p>Similarly, with any of the &lsquo;false&rsquo; values (as in &lsquo;<tt>no=10</tt>&rsquo;), menu
completion will <em>not</em> be used if there are <var>num</var> or more matches.  
</p>
<p>The value of this widget also controls menu selection, as implemented by
the <tt>zsh/complist</tt> module.  The following values may appear either
alongside or instead of the values above.
</p>
<p>If the value contains the string &lsquo;<tt>select</tt>&rsquo;, menu selection
will be started unconditionally.
</p>
<p>In the form &lsquo;<tt>select=</tt><var>num</var>&rsquo;, menu selection will only be started if
there are at least <var>num</var> matches.  If the values for more than one
tag provide a number, the smallest number is taken.
</p>
<p>Menu selection can be turned off explicitly by defining a value
containing the string&lsquo;<tt>no-select</tt>&rsquo;.
</p>
<p>It is also possible to start menu selection only if the list of
matches does not fit on the screen by using the value
&lsquo;<tt>select=long</tt>&rsquo;.  To start menu selection even if the current widget
only performs listing, use the value &lsquo;<tt>select=long-list</tt>&rsquo;.
</p>
<p>To turn on menu completion or menu selection when there are a certain
number of matches <em>or</em> the list of matches does not fit on the
screen, both of &lsquo;<tt>yes=</tt>&rsquo; and &lsquo;<tt>select=</tt>&rsquo; may be given twice, once
with a number and once with &lsquo;<tt>long</tt>&rsquo; or &lsquo;<tt>long-list</tt>&rsquo;.
</p>
<p>Finally, it is possible to activate two special modes of menu selection.
The word &lsquo;<tt>interactive</tt>&rsquo; in the value causes interactive mode
to be entered immediately when menu selection is started; see
<a href="Zsh-Modules.html#The-zsh_002fcomplist-Module">The zsh/complist Module</a>
for a description of interactive mode.  Including the string
&lsquo;<tt>search</tt>&rsquo; does the same for incremental search mode.  To select backward
incremental search, include the string &lsquo;<tt>search-backward</tt>&rsquo;.
</p>
<a name="index-muttrc_002c-completion-style"></a>
</dd>
<dt><tt>muttrc</tt></dt>
<dd><p>If set, gives the location of the mutt configuration file.  It defaults
to &lsquo;<tt>~/.muttrc</tt>&rsquo;.
</p>
<a name="index-numbers_002c-completion-style"></a>
</dd>
<dt><tt>numbers</tt></dt>
<dd><p>This is used with the <tt>jobs</tt> tag.  If it is &lsquo;true&rsquo;, the shell will
complete job numbers instead of the shortest unambiguous prefix
of the job command text.  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 &lsquo;<tt>1</tt>&rsquo;, strings will
only be used if all jobs differ in the first word on their command lines.
</p>
<a name="index-old_002dlist_002c-completion-style"></a>
</dd>
<dt><tt>old-list</tt></dt>
<dd><p>This is used by the <tt>_oldlist</tt> completer.  If it is set to &lsquo;<tt>always</tt>&rsquo;,
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 &lsquo;<tt>never</tt>&rsquo;, 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.
</p>
<p>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.
</p>
<p>As another example consider the <tt>_match</tt> completer: with the
<tt>insert-unambiguous</tt> style set to &lsquo;true&rsquo; 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.
</p>
<a name="index-old_002dmatches_002c-completion-style"></a>
</dd>
<dt><tt>old-matches</tt></dt>
<dd><p>This is used by the <tt>_all_matches</tt> completer to decide if an old
list of matches should be used if one exists.  This is selected by one of
the &lsquo;true&rsquo; values or by the string &lsquo;<tt>only</tt>&rsquo;.  If
the value is &lsquo;<tt>only</tt>&rsquo;, <tt>_all_matches</tt> will only use an old list
and won&rsquo;t have any effect on the list of matches currently being
generated.
</p>
<p>If this style is set it is generally unwise to call the <tt>_all_matches</tt>
completer unconditionally.  One possible use is for either this style or
the <tt>completer</tt> style to be defined with the <tt>-e</tt> option to
<tt>zstyle</tt> to make the style conditional.
</p>
<a name="index-old_002dmenu_002c-completion-style"></a>
</dd>
<dt><tt>old-menu</tt></dt>
<dd><p>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 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
&lsquo;false&rsquo;, 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.
</p>
<p>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 &lsquo;false&rsquo;, 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.
</p>
<a name="index-original_002c-completion-style"></a>
</dd>
<dt><tt>original</tt></dt>
<dd><p>This is used by the <tt>_approximate</tt> and <tt>_correct</tt>
completers to decide if the original string should be added as
a possible completion.  Normally, this is done only if there are
at least two possible corrections, but if this style is set to &lsquo;true&rsquo;, it
is always added.  Note that the style will be examined with the
completer field in the context name set 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.
</p>
<a name="index-packageset_002c-completion-style"></a>
</dd>
<dt><tt>packageset</tt></dt>
<dd><p>This style is used when completing arguments of the Debian &lsquo;<tt>dpkg</tt>&rsquo;
program.  It contains an override for the default package set
for a given context.  For example,
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:complete:dpkg:option--status-1:*' \ 
               packageset avail
</pre></div>

<p>causes available packages, rather than only installed packages,
to be completed for &lsquo;<tt>dpkg -</tt><tt>-status</tt>&rsquo;.
</p>
<a name="index-path_002c-completion-style"></a>
</dd>
<dt><tt>path</tt></dt>
<dd><p>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.
</p>
<a name="index-path_002dcompletion_002c-completion-style"></a>
</dd>
<dt><tt>path-completion</tt></dt>
<dd><p>This is used by filename completion.  By default, filename completion
examines all components of a path to see if there are completions of
that component.  For example, <tt>/u/b/z</tt> can be completed to
<tt>/usr/bin/zsh</tt>.  Explicitly setting this style to &lsquo;false&rsquo; inhibits this
behaviour for path components up to the <tt>/</tt> before the cursor; this
overrides the setting of <tt>accept-exact-dirs</tt>.
</p>
<p>Even with the style set to &lsquo;false&rsquo;, it is still possible to complete
multiple paths by setting the option <tt>COMPLETE_IN_WORD</tt> and moving the
cursor back to the first component in the path to be completed.  For
example, <tt>/u/b/z</tt> can be completed to <tt>/usr/bin/zsh</tt> if the cursor is
after the <tt>/u</tt>.
</p>
<a name="index-pine_002ddirectory_002c-completion-style"></a>
</dd>
<dt><tt>pine-directory</tt></dt>
<dd><p>If set, specifies the directory containing PINE mailbox files.  There
is no default, since recursively searching this directory is inconvenient
for anyone who doesn&rsquo;t use PINE.
</p>
<a name="index-ports_002c-completion-style"></a>
</dd>
<dt><tt>ports</tt></dt>
<dd><p>A list of Internet service names (network ports) to complete.  If this is
not set, service names are taken from the file &lsquo;<tt>/etc/services</tt>&rsquo;.
</p>
<a name="index-prefix_002dhidden_002c-completion-style"></a>
</dd>
<dt><tt>prefix-hidden</tt></dt>
<dd><p>This is used for certain completions which share a common prefix, for
example command options beginning with dashes.  If it is &lsquo;true&rsquo;, the
prefix will not be shown in the list of matches.
</p>
<p>The default value for this style is &lsquo;false&rsquo;.
</p>
<a name="index-prefix_002dneeded_002c-completion-style"></a>
</dd>
<dt><tt>prefix-needed</tt></dt>
<dd><p>This style is also relevant for matches with a common prefix.  If it is
set to &lsquo;true&rsquo; this common prefix must be typed by the user to generate
the matches.
</p>
<p>The style is applicable to the <tt>options</tt>, <tt>signals</tt>, <tt>jobs</tt>,
<tt>functions</tt>, and <tt>parameters</tt> completion tags.
</p>
<p>For command options, this means that the initial &lsquo;<tt>-</tt>&rsquo;, &lsquo;<tt>+</tt>&rsquo;, or
&lsquo;<tt>-</tt><tt>-</tt>&rsquo; must be typed explicitly before option names will be
completed.
</p>
<p>For signals, an initial &lsquo;<tt>-</tt>&rsquo; is required before signal names will
be completed.
</p>
<p>For jobs, an initial &lsquo;<tt>%</tt>&rsquo; is required before job names will be
completed.
</p>
<p>For function and parameter names, an initial &lsquo;<tt>_</tt>&rsquo; or &lsquo;<tt>.</tt>&rsquo; is
required before function or parameter names starting with those
characters will be completed.
</p>
<p>The default value for this style is &lsquo;false&rsquo; for <tt>function</tt> and
<tt>parameter</tt> completions, and  &lsquo;true&rsquo; otherwise.
</p>
<a name="index-preserve_002dprefix_002c-completion-style"></a>
</dd>
<dt><tt>preserve-prefix</tt></dt>
<dd><p>This style is used when completing path names.  Its value should be a
pattern matching an initial prefix of the word to complete that should
be left unchanged under all circumstances.  For example, on some Unices
an initial &lsquo;<tt>//</tt>&rsquo; (double slash) has a special meaning; setting
this style to the string &lsquo;<tt>//</tt>&rsquo; will preserve it.  As another example,
setting this style to &lsquo;<tt>?:/</tt>&rsquo; under Cygwin would allow completion
after &lsquo;<tt>a:/...</tt>&rsquo; and so on.
</p>
<a name="index-range_002c-completion-style"></a>
</dd>
<dt><tt>range</tt></dt>
<dd><p>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.  
</p>
<p>If it is a single number, only the last <var>N</var> words from the history
will be completed.
</p>
<p>If it is a range of the form &lsquo;<var>max</var><tt>:</tt><var>slice</var>&rsquo;,
the last <var>slice</var> words will be completed; then if that
yields no matches, the <var>slice</var> words before those will be tried and 
so on.  This process stops either when at least one match has been
found, or <var>max</var> words have been tried.
</p>
<p>The default is to complete all words from the history at once.
</p>
<a name="index-recursive_002dfiles_002c-completion-style"></a>
</dd>
<dt><tt>recursive-files</tt></dt>
<dd><p>If this style is set, its value is an array of patterns to be
tested against &lsquo;<tt>$PWD/</tt>&rsquo;: note the trailing slash, which allows
directories in the pattern to be delimited unambiguously by including
slashes on both sides.  If an ordinary file completion fails
and the word on the command line does not yet have a directory part to its
name, the style is retrieved using the same tag as for the completion
just attempted, then the elements tested against <tt>$PWD/</tt> in turn.
If one matches, then the shell reattempts completion by prepending the word
on the command line with each directory in the expansion of <tt>**/*(/)</tt>
in turn.  Typically the elements of the style will be set to restrict
the number of directories beneath the current one to a manageable
number, for example &lsquo;<tt>*/.git/*</tt>&rsquo;.
</p>
<p>For example,
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' recursive-files '*/zsh/*'
</pre></div>

<p>If the current directory is <tt>/home/pws/zsh/Src</tt>, then
<tt>zle_tr</tt><em>TAB</em> can be completed to <tt>Zle/zle_tricky.c</tt>.
</p>
<a name="index-regular_002c-completion-style"></a>
</dd>
<dt><tt>regular</tt></dt>
<dd><p>This style is used by the <tt>_expand_alias</tt> completer and bindable 
command.  If set to &lsquo;true&rsquo; (the default), regular aliases will be
expanded but only in command position.  If it is set to &lsquo;false&rsquo;,
regular aliases will never be expanded.   If it is set to &lsquo;<tt>always</tt>&rsquo;,
regular aliases will be expanded even if not in command position.
</p>
<a name="index-rehash_002c-completion-style"></a>
</dd>
<dt><tt>rehash</tt></dt>
<dd><p>If this is set when completing external commands, the internal
list (hash) of commands will be updated for each search by issuing
the <tt>rehash</tt> command.  There is a speed penalty for this which
is only likely to be noticeable when directories in the path have
slow file access.
</p>
<a name="index-remote_002daccess_002c-completion-style"></a>
</dd>
<dt><tt>remote-access</tt></dt>
<dd><p>If set to &lsquo;false&rsquo;, certain commands will be prevented from making
Internet connections to retrieve remote information.  This includes the
completion for the <tt>CVS</tt> command.
</p>
<p>It is not always possible to know if connections are in fact to a remote
site, so some may be prevented unnecessarily.
</p>
<a name="index-remove_002dall_002ddups_002c-completion-style"></a>
</dd>
<dt><tt>remove-all-dups</tt></dt>
<dd><p>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.
</p>
<a name="index-select_002dprompt_002c-completion-style"></a>
</dd>
<dt><tt>select-prompt</tt></dt>
<dd><p>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, except that the numbers refer to the match or line the mark is
on.  A default prompt is used when the value is the empty string.
</p>
<a name="index-select_002dscroll_002c-completion-style"></a>
</dd>
<dt><tt>select-scroll</tt></dt>
<dd><p>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.  If the value is &lsquo;<tt>0</tt>&rsquo; (zero), the list is scrolled by
half-screenfuls; if it is a positive integer, the list is scrolled by the
given number of lines; if it is a negative number, the list is scrolled by a
screenful minus the absolute value of the given number of lines.
The default is to scroll by single lines.
</p>
<a name="index-separate_002dsections_002c-completion-style"></a>
</dd>
<dt><tt>separate-sections</tt></dt>
<dd><p>This style is used with the <tt>manuals</tt> tag when completing names of
manual pages.  If it is &lsquo;true&rsquo;, entries for different sections are
added separately using tag names of the form &lsquo;<tt>manual.</tt><var>X</var>&rsquo;,
where <var>X</var> is the section number.  When the <tt>group-name</tt> style is
also in effect, pages from different sections will appear separately.
This style is also used similarly with the <tt>words</tt> style when
completing words for the dict command. It allows words from different
dictionary databases to be added separately.
The default for this style is &lsquo;false&rsquo;.
</p>
<a name="index-show_002dambiguity_002c-completion-style"></a>
</dd>
<dt><tt>show-ambiguity</tt></dt>
<dd><p>If the <tt>zsh/complist</tt> module is loaded, this style can be used to
highlight the first ambiguous character in completion lists. The
value is either a color indication such as those supported by the
<tt>list-colors</tt> style or, with a value of &lsquo;true&rsquo;, a default of
underlining is selected. The highlighting is only applied if the
completion display strings correspond to the actual matches.
</p>
<a name="index-show_002dcompleter_002c-completion-style"></a>
</dd>
<dt><tt>show-completer</tt></dt>
<dd><p>Tested whenever a new completer is tried.  If it is &lsquo;true&rsquo;, the completion
system outputs a progress message in the listing area showing what
completer is being tried.  The message will be overwritten by any output
when completions are found and is removed after completion is finished.
</p>
<a name="index-single_002dignored_002c-completion-style"></a>
</dd>
<dt><tt>single-ignored</tt></dt>
<dd><p>This is used by the <tt>_ignored</tt> completer when there is only one match.
If its value is &lsquo;<tt>show</tt>&rsquo;, the single match will be
displayed but not inserted.  If the value is &lsquo;<tt>menu</tt>&rsquo;, then the single
match and the original string are both added as matches and menu completion
is started, making it easy to select either of them.
</p>
<a name="index-sort_002c-completion-style"></a>
</dd>
<dt><tt>sort</tt></dt>
<dd><p>Many completion widgets call <tt>_description</tt> at some point which
decides whether the matches are added sorted or unsorted (often
indirectly via <tt>_wanted</tt> or <tt>_requested</tt>).  This style can be set
explicitly to one of the usual &lsquo;true&rsquo; or &lsquo;false&rsquo; values as an override.
If it is not set for the context, the standard behaviour of the
calling widget is used.
</p>
<p>The style is tested first against the full context including the tag, and
if that fails to produce a value against the context without the tag.
</p>
<p>If the calling widget explicitly requests unsorted matches, this is usually
honoured.  However, the default (unsorted) behaviour of completion
for the command history may be overridden by setting the style to
&lsquo;true&rsquo;.
</p>
<p>In the <tt>_expand</tt> completer, if it is set to
&lsquo;true&rsquo;, the expansions generated will always be sorted.  If it is set
to &lsquo;<tt>menu</tt>&rsquo;, then the expansions are only sorted when they are offered 
as single strings but not in the string containing all possible
expansions.
</p>
<a name="index-special_002ddirs_002c-completion-style"></a>
</dd>
<dt><tt>special-dirs</tt></dt>
<dd><p>Normally, the completion code will not produce the directory names
&lsquo;<tt>.</tt>&rsquo; and &lsquo;<tt>..</tt>&rsquo; as possible completions.  If this style is set to
&lsquo;true&rsquo;, it will add both &lsquo;<tt>.</tt>&rsquo; and &lsquo;<tt>..</tt>&rsquo; as possible completions;
if it is set to &lsquo;<tt>..</tt>&rsquo;, only &lsquo;<tt>..</tt>&rsquo; will be added.
</p>
<p>The following example sets <tt>special-dirs</tt> to &lsquo;<tt>..</tt>&rsquo; when the
current prefix is empty, is a single &lsquo;<tt>.</tt>&rsquo;, or consists only of a path
beginning with &lsquo;<tt>../</tt>&rsquo;.  Otherwise the value is &lsquo;false&rsquo;.
</p>
<div class="example">
<pre class="example">zstyle -e ':completion:*' special-dirs \ 
   '[[ $PREFIX = (../)#(|.|..) ]] &amp;&amp; reply=(..)'
</pre></div>

<a name="index-squeeze_002dslashes_002c-completion-style"></a>
</dd>
<dt><tt>squeeze-slashes</tt></dt>
<dd><p>If set to &lsquo;true&rsquo;, sequences of slashes in filename paths (for example in
&lsquo;<tt>foo//bar</tt>&rsquo;) will be treated as a single slash.  This is the usual
behaviour of UNIX paths.  However, by default the file completion
function behaves as if there were a &lsquo;<tt>*</tt>&rsquo; between the slashes.
</p>
<a name="index-stop_002c-completion-style"></a>
</dd>
<dt><tt>stop</tt></dt>
<dd><p>If set to &lsquo;true&rsquo;, 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 &lsquo;false&rsquo; (the 
default), <tt>_history_complete_word</tt> will loop immediately as in a
menu completion.
</p>
<a name="index-strip_002dcomments_002c-completion-style"></a>
</dd>
<dt><tt>strip-comments</tt></dt>
<dd><p>If set to &lsquo;true&rsquo;, this style causes non-essential comment text to be
removed from completion matches.  Currently it is only used when
completing e-mail addresses where it removes any display name from the
addresses, cutting them down to plain <var>user@host</var> form.
</p>
<a name="index-subst_002dglobs_002donly_002c-completion-style"></a>
</dd>
<dt><tt>subst-globs-only</tt></dt>
<dd><p>This is used by the <tt>_expand</tt> completer.  If it is set to &lsquo;true&rsquo;,
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.
</p>
<p>The default for this style is &lsquo;false&rsquo;.
</p>
<a name="index-substitute_002c-completion-style"></a>
</dd>
<dt><tt>substitute</tt></dt>
<dd><p>This boolean style controls whether the <tt>_expand</tt> completer will
first try to expand all substitutions in the string (such as
&lsquo;<tt>$(</tt><var>...</var><tt>)</tt>&rsquo; and &lsquo;<tt>${</tt><var>...</var><tt>}</tt>&rsquo;).
</p>
<p>The default is &lsquo;true&rsquo;.
</p>
<a name="index-suffix_002c-completion-style"></a>
</dd>
<dt><tt>suffix</tt></dt>
<dd><p>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 &lsquo;true&rsquo;, the
word will only be expanded if it doesn&rsquo;t have a suffix, i.e. if it is
something like &lsquo;<tt>~foo</tt>&rsquo; or &lsquo;<tt>$foo</tt>&rsquo; rather than &lsquo;<tt>~foo/</tt>&rsquo; or
&lsquo;<tt>$foo/bar</tt>&rsquo;, unless that suffix itself contains characters eligible
for expansion.  The default for this style is &lsquo;true&rsquo;.
</p>
<a name="index-tag_002dorder_002c-completion-style"></a>
</dd>
<dt><tt>tag-order</tt></dt>
<dd><p>This provides a mechanism for sorting how the tags available in a
particular context will be used.
</p>
<p>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.)
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:complete:-command-:*:*' tag-order \ 
    'commands functions'
</pre></div>

<p>specifies that completion in command position first offers
external commands and shell functions.  Remaining tags will be tried if
no completions are found.
</p>
<p>In addition to tag names, each string in the value may take one of the
following forms:
</p>
<dl compact="compact">
<dt><tt>-</tt></dt>
<dd><p>If any value consists of only a hyphen,
then <em>only</em> the tags specified in the other values are
generated.  Normally all tags not explicitly selected are tried last
if the specified tags fail to generate any matches.  This means 
that a single value consisting only of a single hyphen
turns off completion.
</p>
</dd>
<dt><tt>!</tt> <var>tags</var>...</dt>
<dd><p>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.
</p>
</dd>
<dt><var>tag</var><tt>:</tt><var>label</var> ...</dt>
<dd><p>Here, <var>tag</var> is one of the standard tags and <var>label</var> is an
arbitrary name.  Matches are generated as normal but the name <var>label</var>
is used in contexts instead of <var>tag</var>.  This is not useful in words
starting with <tt>!</tt>.
</p>
<p>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.
</p>
</dd>
<dt><var>tag</var><tt>:</tt><var>label</var><tt>:</tt><var>description</var></dt>
<dd><p>As before, but <tt>description</tt> will replace the &lsquo;<tt>%d</tt>&rsquo; in
the value of the <tt>format</tt> style instead of the default description
supplied by the completion function.  Spaces in the description must
be quoted with a backslash.  A &lsquo;<tt>%d</tt>&rsquo; appearing
in <var>description</var> is replaced with the description given by the
completion function.
</p>
</dd>
</dl>

<p>In any of the forms above the tag may be a pattern or several
patterns in the form &lsquo;<tt>{</tt><var>pat1</var><tt>,</tt><var>pat2...</var><tt>}</tt>&rsquo;.  In this
case all matching tags will be used except 
for any given explicitly in the same string.
</p>
<p>One use of these features is to try
one tag more than once, setting other styles differently on
each attempt, but still 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:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:*:-command-:*:*' tag-order \ 
    'functions:-non-comp *' functions
zstyle ':completion:*:functions-non-comp' \ 
    ignored-patterns '_*'
</pre></div>

<p>On the first attempt, all tags will be offered but the <tt>functions</tt> tag
will be replaced by <tt>functions-non-comp</tt>.  The <tt>ignored-patterns</tt> style 
is set for this tag to exclude functions starting with an underscore.
If there are no matches, the second value of the
<tt>tag-order</tt> style is used which completes functions using the default
tag, this time presumably including all function names.
</p>
<p>The matches for one tag can be split into different groups.  For example:
</p>
<div class="example">
<pre class="example">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></div>

<p>With the <tt>group-names</tt> style set, options beginning with
&lsquo;<tt>-</tt><tt>-</tt>&rsquo;, options beginning with a single &lsquo;<tt>-</tt>&rsquo; or &lsquo;<tt>+</tt>&rsquo; but
containing multiple characters, and single-letter options will be
displayed in separate groups with different descriptions.
</p>
<p>Another use of patterns is 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&rsquo;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>:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*:*:foo:*:*' tag-order '*' '*:-case'
zstyle ':completion:*-case' matcher 'm:{a-z}={A-Z}'
</pre></div>

<p>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.
</p>
<p>It is possible to use the <tt>-e</tt> option of the <tt>zstyle</tt> builtin
command to specify conditions for the use of particular tags.  For
example:
</p>
<div class="example">
<pre class="example">zstyle -e '*:-command-:*' tag-order '
    if [[ -n $PREFIX$SUFFIX ]]; then
      reply=( )
    else
      reply=( - )
    fi'
</pre></div>

<p>Completion in command position will be attempted only if the string
typed so far is not empty.  This is tested using the <tt>PREFIX</tt>
special parameter; see
<a href="Completion-Widgets.html#Completion-Widgets">Completion Widgets</a>
for a description of parameters which are special inside completion widgets.
Setting <tt>reply</tt> to an empty array provides the default
behaviour of trying all tags at once; setting it to an
array containing only a hyphen disables the use of all tags and hence of
all completions.
</p>
<p>If no <tt>tag-order</tt> style has been defined for a context, the strings
&lsquo;<tt>(|*-)argument-* (|*-)option-* values</tt>&rsquo; and &lsquo;<tt>options</tt>&rsquo; 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.
</p>
<a name="index-urls_002c-completion-style"></a>
</dd>
<dt><tt>urls</tt></dt>
<dd><p>This is used together with the <tt>urls</tt> tag by
functions completing URLs.
</p>
<p>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.
</p>
<p>If the value contains only one string which 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).
</p>
<p>Finally, if the only string in the value names a directory, the
directory hierarchy rooted at this directory gives the completions.  The
top level directory should be the file access method, such as
&lsquo;<tt>http</tt>&rsquo;, &lsquo;<tt>ftp</tt>&rsquo;, &lsquo;<tt>bookmark</tt>&rsquo; and so on.  In many cases the next
level of directories will be a filename.  The directory hierarchy can
descend as deep as necessary.
</p>
<p>For example, 
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' urls ~/.urls
mkdir -p ~/.urls/ftp/ftp.zsh.org/pub

</pre></div>

<p>allows completion of all the components of the URL
<tt>ftp://ftp.zsh.org/pub</tt> after suitable commands such as
&lsquo;<tt>netscape</tt>&rsquo; or &lsquo;<tt>lynx</tt>&rsquo;.  Note, however, that access methods and
files are completed separately, so if the <tt>hosts</tt> style is set hosts
can be completed without reference to the <tt>urls</tt> style.
</p>
<p>See the description in the function <tt>_urls</tt> itself
for more information (e.g. &lsquo;<tt>more $^fpath/_urls(N)</tt>&rsquo;).
</p>
<a name="index-use_002dcache_002c-completion-style"></a>
</dd>
<dt><tt>use-cache</tt></dt>
<dd><p>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.
</p>
<a name="index-use_002dcompctl_002c-completion-style"></a>
</dd>
<dt><tt>use-compctl</tt></dt>
<dd><p>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 &lsquo;<tt>first</tt>&rsquo; to
use completions defined with &lsquo;<tt>compctl -T</tt>&rsquo;, and the substring
&lsquo;<tt>default</tt>&rsquo; to use the completion defined with &lsquo;<tt>compctl -D</tt>&rsquo;.
</p>
<p>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.
</p>
<p>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, if there is a function <tt>_foo</tt> to complete arguments to the
command <tt>foo</tt>, <tt>compctl</tt> will never be invoked for <tt>foo</tt>.
However, the <tt>compctl</tt> version will be tried if <tt>foo</tt> only uses
default completion.
</p>
<a name="index-use_002dip_002c-completion-style"></a>
</dd>
<dt><tt>use-ip</tt></dt>
<dd><p>By default, the function <tt>_hosts</tt> that completes host names strips
IP addresses from entries read from host databases such as NIS and
ssh files.  If this style is &lsquo;true&rsquo;, the corresponding IP addresses
can be completed as well.  This style is not use in any context
where the <tt>hosts</tt> style is set; note also it must be set before
the cache of host names is generated (typically the first completion
attempt).
</p>
<a name="index-users_002c-completion-style"></a>
</dd>
<dt><tt>users</tt></dt>
<dd><p>This may be set to a list of usernames to be completed.
If it is not set all usernames will be completed.
Note that if it is set only that list of users will be completed;
this is because on some systems querying all users can take
a prohibitive amount of time.
</p>
<a name="index-users_002dhosts_002c-completion-style"></a>
</dd>
<dt><tt>users-hosts</tt></dt>
<dd><p>The values of this style should be of the form
&lsquo;<var>user</var><tt>@</tt><var>host</var>&rsquo; or &lsquo;<var>user</var><tt>:</tt><var>host</var>&rsquo;. It is used for
commands that need pairs of
user- and hostnames.  These commands will complete usernames from this
style (only), and will restrict subsequent hostname completion to hosts
paired with that user in one of the values of the style.
</p>
<p>It is possible to group values for sets of commands which allow a remote
login, such as <tt>rlogin</tt> and <tt>ssh</tt>, by using the <tt>my-accounts</tt> tag.
Similarly, values for sets of commands which usually refer to the
accounts of other people, such as <tt>talk</tt> and <tt>finger</tt>, can be
grouped by using the <tt>other-accounts</tt> tag.  More ambivalent commands
may use the <tt>accounts</tt> tag.
</p>
<a name="index-users_002dhosts_002dports_002c-completion-style"></a>
</dd>
<dt><tt>users-hosts-ports</tt></dt>
<dd><p>Like <tt>users-hosts</tt> but used for commands like <tt>telnet</tt> and
containing strings of the form &lsquo;<var>user</var><tt>@</tt><var>host</var><tt>:</tt><var>port</var>&rsquo;.
</p>
<a name="index-verbose_002c-completion-style"></a>
</dd>
<dt><tt>verbose</tt></dt>
<dd><p>If set, as it is by default, the completion listing is more verbose.
In particular many commands show descriptions for options if this
style is &lsquo;true&rsquo;.
</p>
<a name="index-word_002c-completion-style"></a>
</dd>
<dt><tt>word</tt></dt>
<dd><p>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
&lsquo;true&rsquo;, 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.
</p>
</dd>
</dl>

<hr>
<a name="Control-Functions"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Standard-Styles" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Bindable-Commands" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Control-Functions-1"></a>
<h2 class="section">20.4 Control Functions</h2>
<a name="index-completion-system_002c-choosing-completers"></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 &lsquo;completer&rsquo; 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&rsquo;t generate any matches:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' completer _complete _correct
</pre></div>

<p>after calling <tt>compinit</tt>. The default value for this style is
&lsquo;<tt>_complete _ignored</tt>&rsquo;, 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 status of the completer
functions to decide if other completers should be called.  If the return
status is zero, no other completers are tried and the <tt>_main_complete</tt>
function returns.
</p>
<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>
<p>The following completer functions are contained in the distribution,
although users may write their own.  Note that in contexts the leading
underscore is stripped, for example basic completion is performed in the
context &lsquo;<tt>:completion::complete:</tt><var>...</var>&rsquo;.
</p>
<a name="index-completion-system_002c-completers"></a>
<dl compact="compact">
<dd><a name="index-_005fall_005fmatches"></a>
</dd>
<dt><tt>_all_matches</tt></dt>
<dd><p>This completer can be used to add a string consisting of all other
matches.  As it influences later completers it must appear as the first
completer in the list.  The list of all matches is affected by the
<tt>avoid-completer</tt> and <tt>old-matches</tt> styles described above.
</p>
<p>It may be useful to use the <tt>_generic</tt> function described below
to bind <tt>_all_matches</tt> to its own keystroke, for example:
</p>
<div class="example">
<pre class="example">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></div>

<p>Note that this does not generate completions by itself:  first use
any of the standard ways of generating a list of completions,
then use <tt>^Xa</tt> to show all matches.  It is possible instead to
add a standard completer to the list and request that the
list of all matches should be directly inserted:
</p>
<div class="example">
<pre class="example">zstyle ':completion:all-matches::::' completer \ 
       _all_matches _complete
zstyle ':completion:all-matches:*' insert true
</pre></div>

<p>In this case the <tt>old-matches</tt> style should not be set.
</p>
<a name="index-_005fapproximate"></a>
</dd>
<dt><tt>_approximate</tt></dt>
<dd><p>This is similar to the basic <tt>_complete</tt> completer but allows the
completions to undergo corrections.  The maximum number of errors can be
specified by the <tt>max-errors</tt> style; see the description of
approximate matching in
<a href="Expansion.html#Filename-Generation">Filename Generation</a>
for how errors are counted.  Normally this completer will only be tried
after the normal <tt>_complete</tt> completer:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' completer _complete _approximate
</pre></div>

<p>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.
</p>
<p>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
&lsquo;<tt>%e</tt>&rsquo; and &lsquo;<tt>%o</tt>&rsquo; which will be replaced by the number of errors
accepted to generate the corrections and the original string,
respectively.
</p>
<p>The completer progressively increases the number of errors allowed up to
the limit by the <tt>max-errors</tt> style, hence if a completion is found
with one error, no completions with two errors will be shown, and so on.
It modifies the completer name in the context to indicate the number of
errors being tried: on the first try the completer field contains
&lsquo;<tt>approximate-1</tt>&rsquo;, on the second try &lsquo;<tt>approximate-2</tt>&rsquo;, and so on.
</p>
<p>When <tt>_approximate</tt> is called from another function, the number of
errors to accept may be passed with the <tt>-a</tt> option.  The argument
is in the same format as the <tt>max-errors</tt> style, all in one string.
</p>
<p>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.:
</p>
<div class="example">
<pre class="example">zstyle -e ':completion:*' completer '
  if [[ $_last_try != &quot;$HISTNO$BUFFER$CURSOR&quot; ]]; then
    _last_try=&quot;$HISTNO$BUFFER$CURSOR&quot;
    reply=(_complete _match _prefix)
  else
    reply=(_ignored _correct _approximate)
  fi'
</pre></div>

<p>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&rsquo;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.
</p>
<a name="index-_005fcanonical_005fpaths"></a>
</dd>
<dt><tt>_canonical_paths</tt> [ <tt>-A</tt> <var>var</var> ] [ <tt>-N</tt> ] [ <tt>-MJV12nfX</tt> ] <var>tag</var> <var>descr</var> [ <var>paths</var> ... ]</dt>
<dd><p>This completion function completes all paths given to it, and also tries to
offer completions which point to the same file as one of the paths given
(relative path when an absolute path is given, and vice versa; when <tt>..</tt>&rsquo;s
are present in the word to be completed; and some paths got from symlinks).
</p>
<p><tt>-A</tt>, if specified, takes the paths from the array variable specified. Paths can
also be specified on the command line as shown above.  <tt>-N</tt>, if specified,
prevents canonicalizing the paths given before using them for completion, in
case they are already so. The options <tt>-M</tt>, <tt>-J</tt>, <tt>-V</tt>, <tt>-1</tt>, <tt>-2</tt>,
<tt>-n</tt>, <tt>-F</tt>, <tt>-X</tt> are passed to <tt>compadd</tt>.
</p>
<p>See <tt>_description</tt> for a description of <var>tag</var> and <var>descr</var>.
</p>
<a name="index-_005fcmdambivalent"></a>
</dd>
<dt><tt>_cmdambivalent</tt></dt>
<dd><p>Completes the remaining positional arguments as an external command.
The external command and its arguments are completed as separate arguments
(in a manner appropriate for completing <tt>/usr/bin/env</tt>)
if there are two or more remaining positional arguments on the command line,
and as a quoted command string (in the manner of <tt>system(...)</tt>) otherwise.
See also <tt>_cmdstring</tt> and <tt>_precommand</tt>.
</p>
<p>This function takes no arguments.
</p>
<a name="index-_005fcmdstring"></a>
</dd>
<dt><tt>_cmdstring</tt></dt>
<dd><p>Completes an external command as a single argument, as for
<tt>system(...)</tt>.
</p>
<a name="index-_005fcomplete"></a>
</dd>
<dt><tt>_complete</tt></dt>
<dd><p>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.
</p>
<p>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> are handled specifically. These are all
mentioned above as possible arguments to the <tt>#compdef</tt> tag.
</p>
<p>Before trying to find a function for a specific context, <tt>_complete</tt> 
checks if the parameter &lsquo;<tt>compcontext</tt>&rsquo; is set. Setting
&lsquo;<tt>compcontext</tt>&rsquo; allows the usual completion dispatching to be
overridden which is useful in places such as a function that uses
<tt>vared</tt> for input. If it is set to an array, the elements are taken
to be the possible matches which will be completed using the tag
&lsquo;<tt>values</tt>&rsquo; and the description &lsquo;<tt>value</tt>&rsquo;. 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
&lsquo;<tt>compcontext</tt>&rsquo; is set to a string containing colons, it should be of
the form &lsquo;<var>tag</var><tt>:</tt><var>descr</var><tt>:</tt><var>action</var>&rsquo;.  In this case the
<var>tag</var> and <var>descr</var> give the tag and description to use and the
<var>action</var> indicates what should be completed in one of the forms
accepted by the <tt>_arguments</tt> utility function described below.
</p>
<p>Finally, if &lsquo;<tt>compcontext</tt>&rsquo; 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).  This is not used by the completion
system itself but is nonetheless handled when explicitly called.
</p>
<a name="index-_005fcorrect"></a>
</dd>
<dt><tt>_correct</tt></dt>
<dd><p>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.  The effect is
similar to spell-checking.  It is based on <tt>_approximate</tt>, but the
completer field in the context name is <tt>correct</tt>.
</p>
<p>For example, with:
</p>
<div class="example">
<pre class="example">zstyle ':completion:::::' completer \ 
       _complete _correct _approximate
zstyle ':completion:*:correct:::' max-errors 2 not-numeric
zstyle ':completion:*:approximate:::' max-errors 3 numeric
</pre></div>

<p>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.
</p>
<p>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 is in the same
form a values to the <tt>accept</tt> style, all in one string.
</p>
<p>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 &mdash; and probably more.
</p>
<a name="index-_005fexpand"></a>
</dd>
<dt><tt>_expand</tt></dt>
<dd><p>This completer function does not really perform 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.  For
this to happen, the completion system needs to be invoked with
<tt>complete-word</tt>, not <tt>expand-or-complete</tt> (the default binding for
<tt>TAB</tt>), as otherwise the string will be expanded by the shell&rsquo;s
internal mechanism before the completion system is started.
Note also this completer should be called before the <tt>_complete</tt> 
completer function.
</p>
<p>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.  The order in which these strings are
generated, if at all, can be controlled by the <tt>group-order</tt> and
<tt>tag-order</tt> styles, as usual.
</p>
<p>The format string for <tt>all-expansions</tt> and for <tt>expansions</tt> may
contain the sequence &lsquo;<tt>%o</tt>&rsquo; which will be replaced by the original
string from the line.
</p>
<p>The kind of expansion to be tried is controlled by the <tt>substitute</tt>,
<tt>glob</tt> and <tt>subst-globs-only</tt> styles.
</p>
<p>It is also possible to call <tt>_expand</tt> as a function, in which case the
different modes may be selected with options: <tt>-s</tt> for
<tt>substitute</tt>, <tt>-g</tt> for <tt>glob</tt> and <tt>-o</tt> for <tt>subst-globs-only</tt>.
</p>
<a name="index-_005fexpand_005falias"></a>
</dd>
<dt><tt>_expand_alias</tt></dt>
<dd><p>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 styles <tt>regular</tt>, <tt>global</tt> and <tt>disabled</tt>.
</p>
<p>This function is also a bindable command, see
<a href="#Bindable-Commands">Bindable Commands</a>.
</p>
<a name="index-_005fextensions"></a>
</dd>
<dt><tt>_extensions</tt></dt>
<dd><p>If the cursor follows the string &lsquo;<tt>*.</tt>&rsquo;, filename extensions are
completed. The extensions are taken from files in current directory or a
directory specified at the beginning of the current word. For exact matches,
completion continues to allow other completers such as <tt>_expand</tt> to
expand the pattern. The standard <tt>add-space</tt> and <tt>prefix-hidden</tt>
styles are observed.
</p>
<a name="index-_005fexternal_005fpwds"></a>
</dd>
<dt><tt>_external_pwds</tt></dt>
<dd><p>Completes current directories of other zsh processes belonging to the
current user.
</p>
<p>This is intended to be used via <tt>_generic</tt>, bound to a custom key
combination. Note that pattern matching is enabled so matching is
performed similar to how it works with the <tt>_match</tt> completer.
</p>
<a name="index-_005fhistory"></a>
</dd>
<dt><tt>_history</tt></dt>
<dd><p>Complete words from the shell&rsquo;s command  history.  This completer 
can be controlled by the <tt>remove-all-dups</tt>, and <tt>sort</tt> styles as for the
<tt>_history_complete_word</tt> bindable command, see
<a href="#Bindable-Commands">Bindable Commands</a>
and
<a href="#Completion-System-Configuration">Completion System Configuration</a>.
</p>
<a name="index-_005fignored"></a>
</dd>
<dt><tt>_ignored</tt></dt>
<dd><p>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 invoked
is determined in the same way as for the <tt>_prefix</tt> completer.
The <tt>single-ignored</tt> style is also available as described above.
</p>
<a name="index-_005flist"></a>
</dd>
<dt><tt>_list</tt></dt>
<dd><p>This completer allows the insertion of matches to be delayed 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
<a href="#Completion-System-Configuration">Completion System Configuration</a>.
</p>
<a name="index-_005fmatch"></a>
</dd>
<dt><tt>_match</tt></dt>
<dd><p>This completer is intended to be used after the <tt>_complete</tt>
completer.  It behaves similarly but the string on the command line may
be a pattern to match against trial completions.  This gives the effect
of the <tt>GLOB_COMPLETE</tt> option.
</p>
<p>Normally completion will be performed by taking the pattern from the line,
inserting a &lsquo;<tt>*</tt>&rsquo; at the cursor position and comparing the resulting
pattern with the possible completions generated.  This can be modified
with the <tt>match-original</tt> style described above.
</p>
<p>The generated matches will be offered in a menu completion unless the
<tt>insert-unambiguous</tt> style is set to &lsquo;true&rsquo;; see the description above
for other options for this style.
</p>
<p>Note that matcher specifications defined globally or used by the
completion functions (the styles <tt>matcher-list</tt> and <tt>matcher</tt>) will
not be used.
</p>
<a name="index-_005fmenu"></a>
</dd>
<dt><tt>_menu</tt></dt>
<dd><p>This completer was written as simple example function to show how menu
completion can be enabled in shell code. However, it has the notable
effect of disabling menu selection which can be useful with
<tt>_generic</tt> based widgets. It should be used as the first completer in
the list.  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>.
</p>
<a name="index-_005foldlist"></a>
</dd>
<dt><tt>_oldlist</tt></dt>
<dd><p>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
<a href="#Completion-System-Configuration">Completion System Configuration</a>.
</p>
<a name="index-_005fprecommand"></a>
</dd>
<dt><tt>_precommand</tt></dt>
<dd><p>Complete an external command in word-separated arguments, as for
<tt>exec</tt> and <tt>/usr/bin/env</tt>.
</p>
<a name="index-_005fprefix"></a>
</dd>
<dt><tt>_prefix</tt></dt>
<dd><p>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.  The effect is similar
to the <tt>expand-or-complete-prefix</tt> command.
</p>
<p>The <tt>completer</tt> style is used to decide which other completers are to
be called to generate matches.  If this style is unset, the list of
completers set for the current context is used &mdash; 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.
</p>
<p>For example, consider this global <tt>completer</tt> style:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' completer \ 
    _complete _prefix _correct _prefix:foo
</pre></div>

<p>Here, the <tt>_prefix</tt> completer tries normal completion but ignoring the
suffix.  If that doesn&rsquo;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.  On the second invocation the completer part of the
context appears as &lsquo;<tt>foo</tt>&rsquo;.
</p>
<p>To use <tt>_prefix</tt> as the last resort and try only normal completion
when it is invoked:
</p>
<div class="example">
<pre class="example">zstyle ':completion:*' completer _complete ... _prefix
zstyle ':completion::prefix:*' completer _complete
</pre></div>

<p>The <tt>add-space</tt> style is also respected.  If it is set to &lsquo;true&rsquo; then
<tt>_prefix</tt> will insert a space between the matches generated (if any) 
and the suffix.
</p>
<p>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.
</p>
<a name="index-_005fuser_005fexpand"></a>
</dd>
<dt><tt>_user_expand</tt></dt>
<dd><p>This completer behaves similarly to the <tt>_expand</tt> completer but
instead performs expansions defined by users.  The styles <tt>add-space</tt> and
<tt>sort</tt> styles specific to the <tt>_expand</tt> completer are usable with
<tt>_user_expand</tt> in addition to other styles handled more generally by
the completion system.  The tag <tt>all-expansions</tt> is also available.
</p>
<p>The expansion depends on the array style <tt>user-expand</tt> being defined
for the current context; remember that the context for completers is less
specific than that for contextual completion as the full context has not
yet been determined.  Elements of the array may have one of the following
forms:
</p>
<dl compact="compact">
<dt><tt>$</tt><var>hash</var></dt>
<dd>
<p><var>hash</var> is the name of an associative array.  Note this is not a full
parameter expression, merely a <tt>$</tt>, suitably quoted to prevent immediate
expansion, followed by the name of an associative array.  If the trial
expansion word matches a key in <var>hash</var>, the resulting expansion is the
corresponding value.
</p>
</dd>
<dt><var>_func</var></dt>
<dd>
<p><var>_func</var> is the name of a shell function whose name must begin with
<tt>_</tt> but is not otherwise special to the completion system.  The function
is called with the trial word as an argument.  If the word is to be
expanded, the function should set the array <tt>reply</tt> to a list of
expansions.  Optionally, it can set <tt>REPLY</tt> to a word that will
be used as a description for the set of expansions.
The return status of the function is irrelevant.
</p>
</dd>
</dl>

</dd>
</dl>

<hr>
<a name="Bindable-Commands"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Control-Functions" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Functions" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Bindable-Commands-1"></a>
<h2 class="section">20.5 Bindable Commands</h2>
<a name="index-completion-system_002c-bindable-commands"></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="compact">
<dd><a name="index-_005fbash_005fcompletions"></a>
</dd>
<dt><tt>_bash_completions</tt></dt>
<dd><p>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: &lsquo;<tt>!</tt>&rsquo;, command names; &lsquo;<tt>$</tt>&rsquo;, environment variables;
&lsquo;<tt>@</tt>&rsquo;, host names; &lsquo;<tt>/</tt>&rsquo;, file names; &lsquo;<tt>~</tt>&rsquo; user names.  In bash, the
binding preceded by &lsquo;<tt>\e</tt>&rsquo; gives completion, and preceded by &lsquo;<tt>^X</tt>&rsquo;
lists options.  As some of these bindings clash with standard zsh
bindings, only &lsquo;<tt>\e~</tt>&rsquo; and &lsquo;<tt>^X~</tt>&rsquo; are bound by default.  To add the
rest, the following should be added to <tt>.zshrc</tt> after <tt>compinit</tt> has
been run:
</p>
<div class="example">
<pre class="example">for key in '!' '$' '@' '/' '~'; do
  bindkey &quot;\e$key&quot; _bash_complete-word
  bindkey &quot;^X$key&quot; _bash_list-choices
done
</pre></div>

<p>This includes the bindings for &lsquo;<tt>~</tt>&rsquo; in case they were already bound to
something else; the completion code does not override user bindings.
</p>
<a name="index-_005fcorrect_005ffilename-_0028_005eXC_0029"></a>
</dd>
<dt><tt>_correct_filename</tt> (<tt>^XC</tt>)</dt>
<dd><p>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.
</p>
<a name="index-_005fcorrect_005fword-_0028_005eXc_0029"></a>
</dd>
<dt><tt>_correct_word</tt> (<tt>^Xc</tt>)</dt>
<dd><p>Performs correction of the current argument using the usual contextual
completions as possible choices. This stores the string
&lsquo;<tt>correct-word</tt>&rsquo; in the <var>function</var> field of the context name and
then calls the <tt>_correct</tt> completer.
</p>
<a name="index-_005fexpand_005falias-_0028_005eXa_0029"></a>
</dd>
<dt><tt>_expand_alias</tt> (<tt>^Xa</tt>)</dt>
<dd><p>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
alias expanded can be controlled with the styles <tt>regular</tt>, <tt>global</tt>
and <tt>disabled</tt>.
</p>
<p>When used as a bindable command there is one additional feature that
can be selected by setting the <tt>complete</tt> style to &lsquo;true&rsquo;.  In this
case, if the word is not the name of an alias, <tt>_expand_alias</tt> tries
to complete the word to a full alias name without expanding it.  It
leaves the cursor directly after the completed word so that invoking
<tt>_expand_alias</tt> once more will expand the now-complete alias name.
</p>
<a name="index-_005fexpand_005fword-_0028_005eXe_0029"></a>
</dd>
<dt><tt>_expand_word</tt> (<tt>^Xe</tt>)</dt>
<dd><p>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 of the context is set to
&lsquo;<tt>expand-word</tt>&rsquo;.
</p>
<a name="index-_005fgeneric"></a>
</dd>
<dt><tt>_generic</tt></dt>
<dd><p>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 defined easily.  For example, 
to define a widget that performs normal completion and starts
menu selection:
</p>
<div class="example">
<pre class="example">zle -C foo complete-word _generic
bindkey '...' foo
zstyle ':completion:foo:*' menu yes select=1
</pre></div>

<p>Note in particular that the <tt>completer</tt> style may be set for the context
in order to change the set of functions used to generate possible matches.
If <tt>_generic</tt> is called with arguments, those are passed through to
<tt>_main_complete</tt> as the list of completers in place of those defined by
the <tt>completer</tt> style.
</p>
<a name="index-_005fhistory_005fcomplete_005fword-_0028_005ce_002f_0029"></a>
</dd>
<dt><tt>_history_complete_word</tt> (<tt>\e/</tt>)</dt>
<dd><p>Complete words from the shell&rsquo;s command history. This uses the
<tt>list</tt>, <tt>remove-all-dups</tt>, <tt>sort</tt>, and <tt>stop</tt> styles.
</p>
<a name="index-_005fmost_005frecent_005ffile-_0028_005eXm_0029"></a>
</dd>
<dt><tt>_most_recent_file</tt> (<tt>^Xm</tt>)</dt>
<dd><p>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.
</p>
<a name="index-_005fnext_005ftags-_0028_005eXn_0029"></a>
</dd>
<dt><tt>_next_tags</tt> (<tt>^Xn</tt>)</dt>
<dd><p>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.
</p>
<a name="index-_005fread_005fcomp-_0028_005eX_005eR_0029"></a>
</dd>
<dt><tt>_read_comp</tt> (<tt>^X^R</tt>)</dt>
<dd><p>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 &lsquo;<tt>_</tt>&rsquo;, for example &lsquo;<tt>_files -/</tt>&rsquo;, 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.
</p>
<p>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.
</p>
<p>A very restricted set of editing commands is available when reading the
string:  &lsquo;<tt>DEL</tt>&rsquo; and &lsquo;<tt>^H</tt>&rsquo; delete the last character; &lsquo;<tt>^U</tt>&rsquo; deletes
the line, and &lsquo;<tt>^C</tt>&rsquo; and &lsquo;<tt>^G</tt>&rsquo; abort the function, while &lsquo;<tt>RET</tt>&rsquo;
accepts the completion.  Note the string is used verbatim as a command
line, so arguments must be quoted in accordance with standard shell rules.
</p>
<p>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.
</p>
<a name="index-_005fcomplete_005fdebug-_0028_005eX_003f_0029"></a>
</dd>
<dt><tt>_complete_debug</tt> (<tt>^X?</tt>)</dt>
<dd><p>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.
</p>
<a name="index-_005fcomplete_005fhelp-_0028_005eXh_0029"></a>
</dd>
<dt><tt>_complete_help</tt> (<tt>^Xh</tt>)</dt>
<dd><p>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 &lsquo;<tt>ESC-2 ^Xh</tt>&rsquo;), then the styles
used and the contexts for which they are used will be shown, too.
</p>
<p>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&rsquo;s own styles and other settings.
</p>
<a name="index-_005fcomplete_005fhelp_005fgeneric"></a>
</dd>
<dt><tt>_complete_help_generic</tt></dt>
<dd><p>Unlike other commands listed here, this must be created as a normal ZLE
widget rather than a completion widget (i.e. with <tt>zle -N</tt>).  It
is used for generating help with a widget bound to the <tt>_generic</tt>
widget that is described above.
</p>
<p>If this widget is created using the name of the function, as it is by
default, then when executed it will read a key sequence.  This is expected
to be bound to a call to a completion function that uses the <tt>_generic</tt>
widget.  That widget will be executed, and information provided in
the same format that the <tt>_complete_help</tt> widget displays for
contextual completion.
</p>
<p>If the widget&rsquo;s name contains <tt>debug</tt>, for example if it is created
as &lsquo;<tt>zle -N _complete_debug_generic _complete_help_generic</tt>&rsquo;, it
will read and execute the keystring for a generic widget as before,
but then generate debugging information as done by <tt>_complete_debug</tt>
for contextual completion.
</p>
<p>If the widget&rsquo;s name contains <tt>noread</tt>, it will not read a keystring
but instead arrange that the next use of a generic widget run in
the same shell will have the effect as described above.
</p>
<p>The widget works by setting the shell parameter
<tt>ZSH_TRACE_GENERIC_WIDGET</tt> which is read by <tt>_generic</tt>.  Unsetting
the parameter cancels any pending effect of the <tt>noread</tt> form.
</p>
<p>For example, after executing the following:
</p>
<div class="example">
<pre class="example">zle -N _complete_debug_generic _complete_help_generic
bindkey '^x:' _complete_debug_generic
</pre></div>

<p>typing &lsquo;<tt>C-x :</tt>&rsquo; followed by the key sequence for a generic widget
will cause trace output for that widget to be saved to a file.
</p>
<a name="index-_005fcomplete_005ftag-_0028_005eXt_0029"></a>
</dd>
<dt><tt>_complete_tag</tt> (<tt>^Xt</tt>)</dt>
<dd><p>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&rsquo;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.
</p>
</dd>
</dl>

<hr>
<a name="Completion-Functions"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Bindable-Commands" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System-Variables" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Utility-Functions"></a>
<h2 class="section">20.6 Utility Functions</h2>
<a name="index-completion-system_002c-utility-functions"></a>

<p>Descriptions follow for utility functions that may be
useful when writing completion functions.  If functions are installed in
subdirectories, 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 status zero if they
generated completions and non-zero if no matching completions could be 
added.
</p>
<dl compact="compact">
<dd><a name="index-_005fabsolute_005fcommand_005fpaths"></a>
</dd>
<dt><tt>_absolute_command_paths</tt></dt>
<dd><p>This function completes external commands as absolute paths (unlike
<tt>_command_names -e</tt> which completes their basenames).  It takes no
arguments.
</p>
<a name="index-_005fall_005flabels"></a>
</dd>
<dt><tt>_all_labels</tt> [ <tt>-x</tt> ] [ <tt>-12VJ</tt> ] <var>tag</var> <var>name</var> <var>descr</var> [ <var>command</var> <var>arg</var> ... ]</dt>
<dd><p>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> and its arguments are called to generate the matches.  The
options stored in the parameter <var>name</var> will automatically be inserted
into the <var>arg</var>s passed to the <var>command</var>.  Normally, they are put
directly after the <var>command</var>, but if one of the <var>arg</var>s is a single
hyphen, they are inserted directly before that.  If the hyphen is the last
argument, it 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.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">local expl
...
if _requested foo; then
  ...
  _all_labels foo expl '...' compadd ... - $matches
fi
</pre></div>

<p>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>.
</p>
<a name="index-_005falternative"></a>
</dd>
<dt><tt>_alternative</tt> [ <tt>-O</tt> <var>name</var> ] [ <tt>-C</tt> <var>name</var> ] <var>spec</var> ...</dt>
<dd><p>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 below.
</p>
<p>The tags to use and the action to perform if a tag is requested are
described using the <var>spec</var>s which are of the form:
&lsquo;<var>tag</var><tt>:</tt><var>descr</var><tt>:</tt><var>action</var>&rsquo;.  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 are those accepted
by the <tt>_arguments</tt> function (described below), excluding the
&lsquo;<tt>-&gt;</tt><var>state</var>&rsquo; and &lsquo;<tt>=</tt><var>...</var>&rsquo; forms.
</p>
<p>For example, the <var>action</var> may be a simple function call:
</p>
<div class="example">
<pre class="example">_alternative \ 
    'users:user:_users' \ 
    'hosts:host:_hosts'
</pre></div>

<p>offers usernames and hostnames as possible matches,
generated by the <tt>_users</tt> and <tt>_hosts</tt> functions respectively.
</p>
<p>Like <tt>_arguments</tt>, this function uses <tt>_all_labels</tt> to execute 
the actions, which will loop over all sets of tags.  Special handling is
only required if there is an additional valid tag, for example inside a
function called from <tt>_alternative</tt>.
</p>
<p>The option &lsquo;<tt>-O</tt> <var>name</var>&rsquo; is 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 passed to <tt>compadd</tt> when executing an action.
</p>
<p>Like <tt>_tags</tt> this function supports the <tt>-C</tt> option to give a
different name for the argument context field.
</p>
<a name="index-_005farguments"></a>

</dd>
<dt><tt>_arguments </tt>[ <tt>-nswWCRS</tt> ] [ <tt>-A</tt> <var>pat</var> ] [ <tt>-O</tt> <var>name</var> ] [ <tt>-M</tt> <var>matchspec</var> ]</dt>
<dt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt>[ <tt>:</tt> ] <var>spec</var> ...</dt>
<dt><tt>_arguments </tt>[ <var>opt</var> ... ] <tt>-</tt><tt>-</tt> [ <tt>-l</tt> ] [ <tt>-i</tt> <var>pats</var> ] [ <tt>-s</tt> <var>pair</var> ]</dt>
<dt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt>[ <var>helpspec</var> ...]</dt>
<dd><p>This function can be used to give a complete specification for completion
for a command whose arguments follow standard UNIX option and argument
conventions.
</p>
<p><em>Options Overview</em>
</p>
<p>Options to <tt>_arguments</tt> itself must be in separate words, i.e. <tt>-s -w</tt>,
not <tt>-sw</tt>.  The options are followed by <var>spec</var>s that describe options and
arguments of the analyzed command.  To avoid ambiguity, all
options to <tt>_arguments</tt> itself may be separated from the <var>spec</var> forms
by a single colon.
</p>
<p>The &lsquo;<tt>-</tt><tt>-</tt>&rsquo;
form is used to intuit <var>spec</var> forms from the help output of the command
being analyzed, and is described in detail below.  The <var>opts</var> for the
&lsquo;<tt>-</tt><tt>-</tt>&rsquo; form are otherwise the same options as the first form.  Note
that &lsquo;<tt>-s</tt>&rsquo; following &lsquo;<tt>-</tt><tt>-</tt>&rsquo; has a distinct meaning from &lsquo;<tt>-s</tt>&rsquo;
preceding &lsquo;<tt>-</tt><tt>-</tt>&rsquo;, and both may appear.
</p>
<p>The option switches <tt>-s</tt>, <tt>-S</tt>, <tt>-A</tt>, <tt>-w</tt>, and <tt>-W</tt> affect how
<tt>_arguments</tt> parses the analyzed command line&rsquo;s options.  These switches are
useful for commands with standard argument parsing.
</p>
<p>The options of <tt>_arguments</tt> have the following meanings:
</p>
<dl compact="compact">
<dt><tt>-n</tt></dt>
<dd><p>With this option, <tt>_arguments</tt> sets the parameter <tt>NORMARG</tt>
to the position of the first normal argument in the <tt>$words</tt> array,
i.e. the position after the end of the options.  If that argument
has not been reached, <tt>NORMARG</tt> is set to <tt>-1</tt>.  The caller
should declare &lsquo;<tt>integer NORMARG</tt>&rsquo; if the <tt>-n</tt> option is passed;
otherwise the parameter is not used.
</p>
</dd>
<dt><tt>-s</tt></dt>
<dd><p>Enable <em>option stacking</em> for single-letter options, whereby multiple
single-letter options may be combined into a single word.  For example,
the two options &lsquo;<tt>-x</tt>&rsquo; and &lsquo;<tt>-y</tt>&rsquo; may be combined into
a single word &lsquo;<tt>-xy</tt>&rsquo;.  By default, every word corresponds to a single
option name (&lsquo;<tt>-xy</tt>&rsquo; is a single option named &lsquo;<tt>xy</tt>&rsquo;).
</p>
<p>Options beginning with a single hyphen or plus sign are eligible for stacking;
words beginning with two hyphens are not.
</p>
<p>Note that <tt>-s</tt> after <tt>-</tt><tt>-</tt> has a different meaning, which is documented
in the segment entitled &lsquo;Deriving <var>spec</var> forms from the help output&rsquo;.
</p>
</dd>
<dt><tt>-w</tt></dt>
<dd><p>In combination with <tt>-s</tt>, allow option stacking
even if one or more of the options take
arguments.  For example, if <tt>-x</tt> takes an argument, with no
<tt>-s</tt>, &lsquo;<tt>-xy</tt>&rsquo; is considered as a single (unhandled) option; with
<tt>-s</tt>, <tt>-xy</tt> is an option with the argument &lsquo;<tt>y</tt>&rsquo;; with both <tt>-s</tt>
and <tt>-w</tt>, <tt>-xy</tt> is the option <tt>-x</tt> and the option <tt>-y</tt> with
arguments to <tt>-x</tt> (and to <tt>-y</tt>, if it takes arguments) still to come
in subsequent words.
</p>
</dd>
<dt><tt>-W</tt></dt>
<dd><p>This option takes <tt>-w</tt> a stage further:  it is possible to
complete single-letter options even after an argument that occurs in the
same word.  However, it depends on the action performed whether options
will really be completed at this point.  For more control, use a
utility function like <tt>_guard</tt> as part of the action.
</p>
</dd>
<dt><tt>-C</tt></dt>
<dd><p>Modify the <tt>curcontext</tt> parameter for an action of the form &lsquo;<tt>-&gt;</tt><var>state</var>&rsquo;.
This is discussed in detail below.
</p>
</dd>
<dt><tt>-R</tt></dt>
<dd><p>Return status 300 instead of zero when a <tt>$state</tt> is to
be handled, in the &lsquo;<tt>-&gt;</tt><var>string</var>&rsquo; syntax.
</p>
</dd>
<dt><tt>-S</tt></dt>
<dd><p>Do not complete options after a &lsquo;<tt>-</tt><tt>-</tt>&rsquo; appearing on the line,
and ignore the &lsquo;<tt>-</tt><tt>-</tt>&rsquo;.  For example, with <tt>-S</tt>, in the line
</p>
<div class="example">
<pre class="example">foobar -x -- -y
</pre></div>

<p>the &lsquo;<tt>-x</tt>&rsquo; is considered an option, the &lsquo;<tt>-y</tt>&rsquo; is considered an
argument, and the &lsquo;<tt>-</tt><tt>-</tt>&rsquo; is considered to be neither.
</p>
</dd>
<dt><tt>-A</tt> <var>pat</var></dt>
<dd><p>Do not complete options after the first non-option
argument on the line.  <var>pat</var> is 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, the form is &lsquo;<tt>-A &quot;-*&quot;</tt>&rsquo;.
</p>
</dd>
<dt><tt>-O</tt> <var>name</var></dt>
<dd><p>Pass the elements of the array <var>name</var> as arguments to functions called to
execute <var>action</var>s.
This is discussed in detail below.
</p>
</dd>
<dt><tt>-M</tt> <var>matchspec</var></dt>
<dd><p>Use the match specification <var>matchspec</var> for completing option names and values.
The default <var>matchspec</var> allows partial word completion after &lsquo;<tt>_</tt>&rsquo; and
&lsquo;<tt>-</tt>&rsquo;, such as completing &lsquo;<tt>-f-b</tt>&rsquo; to &lsquo;<tt>-foo-bar</tt>&rsquo;.  The default
<var>matchspec</var> is:
</p><div class="example">
<pre class="example"><tt>r:|[_-]=* r:|=*</tt>
</pre></div>

</dd>
</dl>

<p><em><var>spec</var>s: overview</em>
</p>
<p>Each of the following forms is a <var>spec</var> describing individual sets of
options or arguments on the command line being analyzed.
</p>
<dl compact="compact">
<dt><var>n</var><tt>:</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dt><var>n</var><tt>::</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dd><p>This describes the <var>n</var>&rsquo;th normal argument.  The <var>message</var> will be 
printed above the matches generated and the <var>action</var> indicates what can
be completed in this position (see below).  If there are two colons
before the <var>message</var> the argument is optional.  If the
<var>message</var> contains only white space, nothing will be printed above
the matches unless the action adds an explanation string itself.
</p>
</dd>
<dt><tt>:</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dt><tt>::</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dd><p>Similar, but describes the <em>next</em> argument, whatever number that
happens to be.  If all arguments are specified in this form in the
correct order the numbers are unnecessary.
</p>
</dd>
<dt><tt>*:</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dt><tt>*::</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dt><tt>*:::</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dd><p>This describes how arguments (usually non-option arguments, those not
beginning with <tt>-</tt> or <tt>+</tt>) are to be completed when neither
of the first two forms was provided.  Any number of arguments can
be completed in this fashion.
</p>
<p>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.
</p>
</dd>
<dt><var>optspec</var></dt>
<dt><var>optspec</var><tt>:</tt><var>...</var></dt>
<dd><p>This describes an option.  The colon indicates handling for one or more
arguments to the option; if it is not present, the option is assumed to
take no arguments.
</p>
<p>The following forms are available for the initial <var>optspec</var>, whether
or not the option has arguments.
</p>
<dl compact="compact">
<dt><tt>*</tt><var>optspec</var></dt>
<dd><p>Here <var>optspec</var> is one of the remaining forms below.  This indicates
the following <var>optspec</var> may be repeated.  Otherwise if the
corresponding option is already present on the command line to the left
of the cursor it will not be offered again.
</p>
</dd>
<dt><tt>-</tt><var>optname</var></dt>
<dt><tt>+</tt><var>optname</var></dt>
<dd><p>In the simplest form the <var>optspec</var> is just the option name beginning
with a minus or a plus sign, such as &lsquo;<tt>-foo</tt>&rsquo;.  The first argument for
the option (if any) must follow as a <em>separate</em> word directly after the
option.
</p>
<p>Either of &lsquo;<tt>-+</tt><var>optname</var>&rsquo; and &lsquo;<tt>+-</tt><var>optname</var>&rsquo; can be used to
specify that <tt>-</tt><var>optname</var> and <tt>+</tt><var>optname</var> are both valid.
</p>
<p>In all the remaining forms, the leading &lsquo;<tt>-</tt>&rsquo; may be replaced by or
paired with &lsquo;<tt>+</tt>&rsquo; in this way.
</p>
</dd>
<dt><tt>-</tt><var>optname</var><tt>-</tt></dt>
<dd><p>The first argument of the option must come directly after the option name
<em>in the same word</em>.  For example, &lsquo;<tt>-foo-:</tt><var>...</var>&rsquo; specifies that
the completed option and argument will look like &lsquo;<tt>-foo</tt><var>arg</var>&rsquo;.
</p>
</dd>
<dt><tt>-</tt><var>optname</var><tt>+</tt></dt>
<dd><p>The first argument may appear immediately after <var>optname</var> in the same
word, or may appear as a separate word after the option.  For example,
&lsquo;<tt>-foo+:</tt><var>...</var>&rsquo; specifies that the completed option and argument
will look like either &lsquo;<tt>-foo</tt><var>arg</var>&rsquo; or &lsquo;<tt>-foo</tt> <var>arg</var>&rsquo;.
</p>
</dd>
<dt><tt>-</tt><var>optname</var><tt>=</tt></dt>
<dd><p>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, for
example &lsquo;<tt>-foo=</tt><var>arg</var>&rsquo; or &lsquo;<tt>-foo</tt> <var>arg</var>&rsquo;.
</p>
</dd>
<dt><tt>-</tt><var>optname</var><tt>=-</tt></dt>
<dd><p>The argument to the option must appear after an equals sign in the same
word, and may not be given in the next argument.
</p>
</dd>
<dt><var>optspec</var><tt>[</tt><var>explanation</var><tt>]</tt></dt>
<dd><p>An explanation string may be appended to any of the preceding forms of
<var>optspec</var> by enclosing it in brackets, as in &lsquo;<tt>-q[query operation]</tt>&rsquo;.
</p>
<p>The <tt>verbose</tt> style is used to decide whether the explanation strings
are displayed with the option in a completion listing.
</p>
<p>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
&lsquo;<tt>%d</tt>&rsquo; in it replaced by the <var>message</var> of the first <var>optarg</var>
that follows the <var>optspec</var>; see below.
</p>
</dd>
</dl>

<p>It is possible for options with a literal &lsquo;<tt>+</tt>&rsquo; or &lsquo;<tt>=</tt>&rsquo; to
appear, but that character must be quoted, for example &lsquo;<tt>-\+</tt>&rsquo;.
</p>
<p>Each <var>optarg</var> following an <var>optspec</var> must take one of the
following forms:
</p>
<dl compact="compact">
<dt><tt>:</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dt><tt>::</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dd><p>An argument to the option; <var>message</var> and <var>action</var> are treated as
for ordinary arguments.  In the first form, the argument is mandatory,
and in the second form it is optional.
</p>
<p>This group may be repeated for options which take multiple arguments.
In other words,
<tt>:</tt><var>message1</var><tt>:</tt><var>action1</var><tt>:</tt><var>message2</var><tt>:</tt><var>action2</var>
specifies that the option takes two arguments.
</p>
</dd>
<dt><tt>:*</tt><var>pattern</var><tt>:</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dt><tt>:*</tt><var>pattern</var><tt>::</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dt><tt>:*</tt><var>pattern</var><tt>:::</tt><var>message</var><tt>:</tt><var>action</var></dt>
<dd><p>This describes multiple arguments.  Only the last <var>optarg</var> for
an option taking multiple arguments may be
given in this form.  If the <var>pattern</var> is empty (i.e. <tt>:*:</tt>), all
the remaining words on the line are to be completed as described by the
<var>action</var>; otherwise, all the words up to and including a word matching
the <var>pattern</var> are to be completed using the <var>action</var>.
</p>
<p>Multiple colons are treated as for the &lsquo;<tt>*:</tt><var>...</var>&rsquo; forms for
ordinary arguments:  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.
</p>
</dd>
</dl>

</dd>
</dl>

<p>Any literal colon in an <var>optname</var>, <var>message</var>, or <var>action</var>
must be preceded by a backslash, &lsquo;<tt>\:</tt>&rsquo;.
</p>
<p>Each of the forms above may be preceded by a list in parentheses
of option names and argument numbers.  If the given option is on
the command line, the options and arguments indicated in parentheses
will not be offered.  For example, 
&lsquo;<tt>(-two -three 1)-one:</tt><var>...</var>&rsquo; completes the option &lsquo;<tt>-one</tt>&rsquo;; if this
appears on the command line, the options <tt>-two</tt> and <tt>-three</tt> and the
first ordinary argument will not be completed after it.
&lsquo;<tt>(-foo):</tt><var>...</var>&rsquo; specifies an ordinary argument completion;
<tt>-foo</tt> will not be completed if that argument is already present.
</p>
<p>Other items may appear in the list of excluded options to indicate
various other items that should not be applied when the current
specification is matched: a single star (<tt>*</tt>) for the rest arguments
(i.e. a specification of the form &lsquo;<tt>*:</tt><var>...</var>&rsquo;); a colon (<tt>:</tt>)
for all normal (non-option-) arguments; and a hyphen (<tt>-</tt>) for all
options.  For example, if &lsquo;<tt>(*)</tt>&rsquo; appears before an option and the
option appears on the command line, the list of remaining arguments
(those shown in the above table beginning with &lsquo;<tt>*:</tt>&rsquo;) will not be
completed.
</p>
<p>To aid in reuse of specifications, it is possible to precede any of the
forms above with &lsquo;<tt>!</tt>&rsquo;; then the form will no longer be completed,
although if the option or argument appears on the command line they will
be skipped as normal.  The main use for this is when the arguments are
given by an array, and <tt>_arguments</tt> is called repeatedly for more
specific contexts: on the first call &lsquo;<tt>_arguments $global_options</tt>&rsquo; is
used, and on subsequent calls &lsquo;<tt>_arguments !$^global_options</tt>&rsquo;.
</p>
<p><em><var>spec</var>s: actions</em>
</p>
<p>In each of the forms above the <var>action</var> determines how
completions should be generated.  Except for the &lsquo;<tt>-&gt;</tt><var>string</var>&rsquo;
form below, the <var>action</var> will be executed by calling the
<tt>_all_labels</tt> function to process all tag labels.  No special handling
of tags is needed unless a function call introduces a new one.
</p>
<p>The functions called to execute <var>action</var>s will be called with the
elements of the array named by the &lsquo;<tt>-O</tt> <var>name</var>&rsquo; option as arguments.
This can be used, for example, to pass the same set of options for the
<tt>compadd</tt> builtin to all <var>action</var>s.
</p>
<p>The forms for <var>action</var> are as follows.
</p>
<dl compact="compact">
<dt><tt>&nbsp;</tt>(single unquoted space)</dt>
<dd><p>This is useful where an argument is required but it is not possible or
desirable to generate matches for it.  The
<var>message</var> will be displayed but no completions listed.  Note
that even in this case the colon at the end of the <var>message</var> is
needed; it may only be omitted when neither a <var>message</var>
nor an <var>action</var> is given.
</p>
</dd>
<dt><tt>(</tt><var>item1</var> <var>item2</var> <var>...</var><tt>)</tt></dt>
<dd><p>One of a list of possible matches, for example:
</p>
<div class="example">
<pre class="example"><tt>:foo:(foo bar baz</tt><tt>)</tt>
</pre></div>

</dd>
<dt><tt>((<var>item1</var>\:<var>desc1</var> <var>...</var>))</tt></dt>
<dd><p>Similar to the above, but with descriptions for each possible match.
Note the backslash before the colon.  For example,
</p>
<div class="example">
<pre class="example"><tt>:foo:((a\:bar b\:baz</tt><tt>))</tt>
</pre></div>

<p>The matches will be listed together with their descriptions if the
<tt>description</tt> style is set with the <tt>values</tt> tag in the context.
</p>
</dd>
<dt><tt>-&gt;</tt><var>string</var></dt>
<dd><a name="index-context_002c-use-of"></a>
<a name="index-line_002c-use-of"></a>
<a name="index-opt_005fargs_002c-use-of"></a>
<p>In this form, <tt>_arguments</tt> processes the arguments and options and then
returns control to the calling function with parameters set to indicate the
state of processing; the calling function then makes its own arrangements
for generating completions.  For example, functions that implement a state
machine can use this type of action.
</p>
<p>Where <tt>_arguments</tt> encounters <var>action</var> in the &lsquo;<tt>-&gt;</tt><var>string</var>&rsquo;
format, it will strip all leading and trailing whitespace from <var>string</var>
and set the array <tt>state</tt> to the set of all <var>string</var>s for which an
action is to be performed.  The elements of the array <tt>state_descr</tt> are
assigned the corresponding <var>message</var> field from each <var>optarg</var>
containing such an <var>action</var>.
</p>
<p>By default and in common with all other well behaved completion
functions, _arguments returns status zero if it was able to add matches and
non-zero otherwise. However, if the <tt>-R</tt> option is given,
<tt>_arguments</tt> will instead return a status of 300 to indicate that
<tt>$state</tt> is to be handled.
</p>
<p>In addition to <tt>$state</tt> and <tt>$state_descr</tt>, <tt>_arguments</tt> also
sets the global
parameters &lsquo;<tt>context</tt>&rsquo;, &lsquo;<tt>line</tt>&rsquo; and &lsquo;<tt>opt_args</tt>&rsquo; as described
below, and does not reset any changes made to the special parameters
such as <tt>PREFIX</tt> and <tt>words</tt>.  This gives the calling function the
choice of resetting these parameters or propagating changes in them.
</p>
<p>A function calling <tt>_arguments</tt> with at least
one action containing a &lsquo;<tt>-&gt;</tt><var>string</var>&rsquo; must therefore declare
appropriate local parameters:
</p>
<div class="example">
<pre class="example">local context state state_descr line
typeset -A opt_args
</pre></div>

<p>to prevent <tt>_arguments</tt> from altering the global environment.
</p>
</dd>
<dt><tt>{</tt><var>eval-string</var><tt>}</tt></dt>
<dd><a name="index-expl_002c-use-of"></a>
<p>A string in braces is evaluated as shell code to generate matches.  If the
<var>eval-string</var> itself does not begin with an opening parenthesis or
brace it is split into separate words before execution.
</p>
</dd>
<dt><tt>= </tt><var>action</var></dt>
<dd><p>If the <var>action</var> starts with &lsquo;<tt>= </tt>&rsquo; (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 increment the value of the <tt>CURRENT</tt> special
parameter.  This has the effect of inserting a dummy word onto the
completion command line while not changing the point at which completion is
taking place.
</p>
<p>This is most useful with one of the specifiers that restrict the words on
the command line on which the <var>action</var> is to operate (the two- and
three-colon forms above).  One particular use is when an <var>action</var> itself
causes <tt>_arguments</tt> on a restricted range; it is necessary to use this
trick to insert an appropriate command name into the range for the second
call to <tt>_arguments</tt> to be able to parse the line.
</p>
</dd>
<dt><var><tt>&nbsp;</tt>word...</var></dt>
<dt><var>word...</var></dt>
<dd><p>This covers all forms other than those above.  If the <var>action</var>
starts with a space, the remaining list of words will be invoked unchanged.
</p>
<p>Otherwise it will be invoked with some extra strings placed after the
first word; these are to be passed down as options to the <tt>compadd</tt>
builtin.  They ensure that the state specified by <tt>_arguments</tt>, in
particular the descriptions of options and arguments, is correctly passed
to the completion command.  These additional arguments
are taken from the array parameter &lsquo;<tt>expl</tt>&rsquo;; this will be set up
before executing the <var>action</var> and hence may be referred to inside it,
typically in an expansion of the form &lsquo;<tt>$expl[@]</tt>&rsquo; which preserves empty
elements of the array.
</p>
</dd>
</dl>

<p>During the performance of the action the array &lsquo;<tt>line</tt>&rsquo; will be set to
the normal arguments from the command line, i.e. the words from the
command line after the command name excluding all options and their
arguments.  Options are stored in the associative array
&lsquo;<tt>opt_args</tt>&rsquo; with 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 and backslashes
in the original arguments are preceded with backslashes.
</p>
<p>The parameter &lsquo;<tt>context</tt>&rsquo; is set when returning to the calling function
to perform an action of the form &lsquo;<tt>-&gt;</tt><var>string</var>&rsquo;.  It is set to an
array of elements corresponding to the elements of <tt>$state</tt>.  Each
element is a suitable name for the argument field of the context: either a
string of the form &lsquo;<tt>option</tt><var>-opt</var><tt>-</tt><var>n</var>&rsquo; for the <var>n</var>&rsquo;th
argument of the option <var>-opt</var>, or a string of the form
&lsquo;<tt>argument-</tt><var>n</var>&rsquo; for the <var>n</var>&rsquo;th argument.  For &lsquo;rest&rsquo; arguments,
that is those in the list at the end not handled by position, <var>n</var> is the
string &lsquo;<tt>rest</tt>&rsquo;.  For example, when completing the argument of the <tt>-o</tt>
option, the name is &lsquo;<tt>option-o-1</tt>&rsquo;, while for the second normal
(non-option-) argument it is &lsquo;<tt>argument-2</tt>&rsquo;.
</p>
<p>Furthermore, during the evaluation of the <var>action</var> the context name in
the <tt>curcontext</tt> parameter is altered to append the same string that is
stored in the <tt>context</tt> parameter.
</p>
<p>The option <tt>-C</tt> tells <tt>_arguments</tt> to modify the <tt>curcontext</tt>
parameter for an action of the form &lsquo;<tt>-&gt;</tt><var>state</var>&rsquo;.  This is the
standard parameter used to keep track of the current context.  Here it
(and not the <tt>context</tt> array) should be made local to the calling
function to avoid passing back the modified value and should be
initialised to the current value at the start of the function:
</p>
<div class="example">
<pre class="example">local curcontext=&quot;$curcontext&quot;
</pre></div>

<p>This is useful where it is not possible for multiple states to be valid
together.
</p>
<p><em>Grouping Options</em>
</p>
<p>Options can be grouped to simplify exclusion lists. A group is
introduced with &lsquo;<tt>+</tt>&rsquo; followed by a name for the group in the
subsequent word. Whole groups can then be referenced in an exclusion
list or a group name can be used to disambiguate between two forms of
the same option. For example:
</p>
<div class="example">
<pre class="example">_arguments \ 
    '(group2--x)-a' \ 
  + group1 \ 
    -m \ 
    '(group2)-n' \ 
  + group2 \ 
    -x -y
</pre></div>

<p>If the name of a group is specified in the form
&lsquo;<tt>(</tt><var>name</var><tt>)</tt>&rsquo; then only one value from that group
will ever be completed; more formally, all specifications are mutually
exclusive to all other specifications in that group. This is useful for
defining options that are aliases for each other. For example:
</p>
<div class="example">
<pre class="example">_arguments \ 
    -a -b \ 
  + '(operation)' \ 
    {-c,--compress}'[compress]' \ 
    {-d,--decompress}'[decompress]' \ 
    {-l,--list}'[list]'
</pre></div>

<p>If an option in a group appears on the command line, it is stored in the
associative array &lsquo;<tt>opt_args</tt>&rsquo; with &rsquo;<var>group</var><tt>-</tt><var>option</var>&rsquo;
as a key.  In the example above, a key &lsquo;<tt>operation--c</tt>&rsquo; is used if the option
&lsquo;<tt>-c</tt>&rsquo; is present on the command line.
</p>
<p><em>Specifying Multiple Sets of Arguments</em>
</p>
<p>It is possible to specify multiple sets of options and arguments with
the sets separated by single hyphens. This differs from groups in that
sets are considered to be mutually exclusive of each other.
</p>
<p>Specifications before the first set and from any group are common to
all sets. For example:
</p>
<div class="example">
<pre class="example">_arguments \ 
    -a \ 
  - set1 \ 
    -c \ 
  - set2 \ 
    -d \ 
    ':arg:(x2 y2)'
</pre></div>

<p>This defines two sets.  When the command line contains the option
&lsquo;<tt>-c</tt>&rsquo;, the &lsquo;<tt>-d</tt>&rsquo; option and the argument will not be considered
possible completions.  When it contains &lsquo;<tt>-d</tt>&rsquo; or an argument, the
option &lsquo;<tt>-c</tt>&rsquo; will not be considered.  However, after &lsquo;<tt>-a</tt>&rsquo;
both sets will still be considered valid.
</p>
<p>As for groups, the name of a set may appear in exclusion lists, either
alone or preceding a normal option or argument specification.
</p>
<p>The completion code has to parse the command line separately for each
set. This can be slow so sets should only be used when necessary.
A useful alternative is often an option specification with rest-arguments
(as in &lsquo;<tt>-foo:*:...</tt>&rsquo;); here the option <tt>-foo</tt> swallows up all
remaining arguments as described by the <var>optarg</var> definitions.
</p>
<p><em>Deriving <var>spec</var> forms from the help output</em>
</p>
<p>The option &lsquo;<tt>-</tt><tt>-</tt>&rsquo; allows <tt>_arguments</tt> to work out the names of long
options that support the &lsquo;<tt>-</tt><tt>-help</tt>&rsquo; option which is standard in many
GNU commands.  The command word is called with the argument
&lsquo;<tt>-</tt><tt>-help</tt>&rsquo; and the output examined for option names.  Clearly, it can
be dangerous to pass this to commands which may not support this option as
the behaviour of the command is unspecified.
</p>
<p>In addition to options, &lsquo;<tt>_arguments -</tt><tt>-</tt>&rsquo; will try to deduce the
types of arguments available for options when the form
&lsquo;<tt>-</tt><tt>-</tt><var>opt</var><tt>=</tt><var>val</var>&rsquo; is valid.  It is also possible to provide
hints by examining the help text of the command and adding <var>helpspec</var> of
the form &lsquo;<var>pattern</var><tt>:</tt><var>message</var><tt>:</tt><var>action</var>&rsquo;; note that other
<tt>_arguments</tt> <var>spec</var> forms are not used.  The <var>pattern</var> is matched
against the help text for an option, and if it matches the <var>message</var> and
<var>action</var> are used as for other argument specifiers.  The special case
of &lsquo;<tt>*:</tt>&rsquo; means both <var>message</var> and <var>action</var> are empty, which has
the effect of causing options having no description in the help output to
be ordered in listings ahead of options that have a description.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">_arguments -- '*\*:toggle:(yes no)' \ 
              '*=FILE*:file:_files' \ 
              '*=DIR*:directory:_files -/' \ 
              '*=PATH*:directory:_files -/'
</pre></div>

<p>Here, &lsquo;<tt>yes</tt>&rsquo; and &lsquo;<tt>no</tt>&rsquo; will be completed as the argument of
options whose description ends in a star; file names will be completed for
options that contain the substring &lsquo;<tt>=FILE</tt>&rsquo; in the description; and
directories will be completed for options whose description contains
&lsquo;<tt>=DIR</tt>&rsquo; or &lsquo;<tt>=PATH</tt>&rsquo;.  The last three are in fact the default and so
need not be given explicitly, although it is possible to override the use
of these patterns.  A typical help text which uses this feature is:
</p>
<div class="example">
<pre class="example">  -C, --directory=DIR          change to directory DIR
</pre></div>

<p>so that the above specifications will cause directories to be completed
after &lsquo;<tt>-</tt><tt>-directory</tt>&rsquo;, though not after &lsquo;<tt>-C</tt>&rsquo;.
</p>
<p>Note also that <tt>_arguments</tt> tries to find out automatically if the
argument for an option is optional.  This can be specified explicitly by
doubling the colon before the <var>message</var>.
</p>
<p>If the <var>pattern</var> ends in &lsquo;<tt>(-)</tt>&rsquo;, this will be removed from the
pattern and the <var>action</var> will be used only directly after the
&lsquo;<tt>=</tt>&rsquo;, not in the next word.  This is the behaviour of a normal
specification defined with the form &lsquo;<tt>=-</tt>&rsquo;.
</p>
<p>By default, the command (with the option &lsquo;<tt>--help</tt>&rsquo;) is run after
resetting all the locale categories (except for <tt>LC_CTYPE</tt>) to &lsquo;<tt>C</tt>&rsquo;.
If the localized help output is known to work, the option &lsquo;<tt>-l</tt>&rsquo; can
be specified after the &lsquo;<tt>_arguments -</tt><tt>-</tt>&rsquo; so that the command is
run in the current locale.
</p>
<p>The &lsquo;<tt>_arguments -</tt><tt>-</tt>&rsquo; can be followed by the option &lsquo;<tt>-i</tt>
<var>patterns</var>&rsquo; to give patterns for options which are not to be
completed.  The patterns can be given as the name of an array parameter
or as a literal list in parentheses.  For example,
</p>
<div class="example">
<pre class="example">_arguments -- -i \ 
    &quot;(--(en|dis)able-FEATURE*)&quot;
</pre></div>

<p>will cause completion to ignore the options
&lsquo;<tt>-</tt><tt>-enable-FEATURE</tt>&rsquo; and &lsquo;<tt>-</tt><tt>-disable-FEATURE</tt>&rsquo; (this example is
useful with GNU <tt>configure</tt>).
</p>
<p>The &lsquo;<tt>_arguments -</tt><tt>-</tt>&rsquo; form can also be followed by the option &lsquo;<tt>-s</tt>
<var>pair</var>&rsquo; to describe option aliases.  The <var>pair</var> consists of a list
of alternating patterns and corresponding replacements, enclosed in parens
and quoted so that it forms a single argument word in the <tt>_arguments</tt>
call.
</p>
<p>For example, some <tt>configure</tt>-script help output describes options only
as &lsquo;<tt>-</tt><tt>-enable-foo</tt>&rsquo;, but the script also accepts the negated form
&lsquo;<tt>-</tt><tt>-disable-foo</tt>&rsquo;.  To allow completion of the second form:
</p>
<div class="example">
<pre class="example">_arguments -- -s &quot;((#s)--enable- --disable-)&quot;
</pre></div>

<p><em>Miscellaneous notes</em>
</p>
<p>Finally, note that <tt>_arguments</tt> generally expects to be the primary
function handling any completion for which it is used.  It may have side
effects which change the treatment of any matches added by other functions
called after it.  To combine <tt>_arguments</tt> with other functions, those
functions should be called either before <tt>_arguments</tt>, as an <var>action</var>
within a <var>spec</var>, or in handlers for &lsquo;<tt>-&gt;</tt><var>state</var>&rsquo; actions.
</p>
<p>Here is a more general example of the use of <tt>_arguments</tt>:
</p>
<div class="example">
<pre class="example">_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></div>

<p>This describes three options: &lsquo;<tt>-l</tt>&rsquo;, &lsquo;<tt>-format</tt>&rsquo;, and
&lsquo;<tt>-copy</tt>&rsquo;.  The first takes one argument described as &lsquo;<var>left
border</var>&rsquo; for which no completion will be offered because of the empty
action.  Its argument may come directly after the &lsquo;<tt>-l</tt>&rsquo; or it may be 
given as the next word on the line.
</p>
<p>The &lsquo;<tt>-format</tt>&rsquo; option takes one
argument in the next word, described as &lsquo;<var>paper size</var>&rsquo; for which
only the strings &lsquo;<tt>letter</tt>&rsquo; and &lsquo;<tt>A4</tt>&rsquo; will be completed.
</p>
<p>The &lsquo;<tt>-copy</tt>&rsquo; option may appear more than once on the command line and
takes two arguments.  The first is mandatory and will be completed as a
filename.  The second is optional (because of the second colon before
the description &lsquo;<var>resolution</var>&rsquo;) and will be completed from the strings
&lsquo;<tt>300</tt>&rsquo; and &lsquo;<tt>600</tt>&rsquo;.
</p>
<p>The last two descriptions say what should be completed as
arguments.  The first describes the first argument as a
&lsquo;<var>postscript file</var>&rsquo; and makes files ending in &lsquo;<tt>ps</tt>&rsquo; or &lsquo;<tt>eps</tt>&rsquo; 
be completed.  The last description gives all other arguments the
description &lsquo;<var>page numbers</var>&rsquo; but does not offer completions.
</p>
<a name="index-_005fcache_005finvalid"></a>
</dd>
<dt><tt>_cache_invalid</tt> <var>cache_identifier</var></dt>
<dd><p>This function returns status zero 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.
This should provide a function name which is run with the full path to the
relevant cache file as the only argument.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">_example_caching_policy () {
    # rebuild if cache is more than a week old
    local -a oldp
    oldp=( &quot;$1&quot;(Nm+7) )
    (( $#oldp ))
}
</pre></div>

<a name="index-_005fcall_005ffunction"></a>
</dd>
<dt><tt>_call_function</tt> <var>return</var> <var>name</var> [ <var>arg</var> ... ]</dt>
<dd><p>If a function <var>name</var> exists, it is called with the arguments
<var>arg</var>s.  The <var>return</var> argument gives the name of a parameter in which
the return status from the function <var>name</var> should be stored; if <var>return</var>
is empty or a single hyphen it is ignored.
</p>
<p>The return status of <tt>_call_function</tt> itself is zero if the function
<var>name</var> exists and was called and non-zero otherwise.
</p>
<a name="index-_005fcall_005fprogram"></a>
</dd>
<dt><tt>_call_program</tt> [ <tt>-l</tt> ] [ <tt>-p</tt> ] <var>tag</var> <var>string</var> ...</dt>
<dd><p>This function provides a mechanism for the user to override the use of an
external command.  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.  The <var>string</var>s from the call to <tt>_call_program</tt>, or from the
style if set, are concatenated with spaces between them and the resulting
string is evaluated.  The return status is the return status of the command
called.
</p>
<p>By default, the command is run in an environment where all the locale
categories (except for <tt>LC_CTYPE</tt>) are reset to &lsquo;<tt>C</tt>&rsquo; by calling the
utility function <tt>_comp_locale</tt> (see below). If the option &lsquo;<tt>-l</tt>&rsquo; is
given, the command is run with the current locale.
</p>
<p>If the option &lsquo;<tt>-p</tt>&rsquo; is supplied it indicates that the command
output is influenced by the permissions it is run with. If the
<tt>gain-privileges</tt> style is set to true, <tt>_call_program</tt> will make
use of commands such as <tt>sudo</tt>, if present on the command-line, to
match the permissions to whatever the final command is likely to run
under. When looking up the <tt>gain-privileges</tt> and <tt>command</tt> styles,
the command component of the zstyle context will end with a slash
(&lsquo;<tt>/</tt>&rsquo;) followed by the command that would be used to gain privileges.
</p>
<a name="index-_005fcombination"></a>
</dd>
<dt><tt>_combination</tt> [ <tt>-s</tt> <var>pattern</var> ] <var>tag</var> <var>style</var> <var>spec</var> ... <var>field</var> <var>opts</var> ...</dt>
<dd><p>This function is used to complete combinations of values,  for example
pairs of hostnames and usernames.  The <var>style</var> argument gives the style
which defines the pairs; it is looked up in a context with the <var>tag</var>
specified.
</p>
<p>The style name consists of field names separated by hyphens, for example
&lsquo;<tt>users-hosts-ports</tt>&rsquo;.  For each field for a value is already known, a
<var>spec</var> of the form &lsquo;<var>field</var><tt>=</tt><var>pattern</var>&rsquo; is given.  For example,
if the command line so far specifies a user &lsquo;<tt>pws</tt>&rsquo;, the argument
&lsquo;<tt>users=pws</tt>&rsquo; should appear.
</p>
<p>The next argument with no equals sign is taken as the name of the field
for which completions should be generated (presumably not one of the
<var>field</var>s for which the value is known).
</p>
<p>The matches generated will be taken from the value of the style.  These
should contain the possible values for the combinations in the appropriate
order (users, hosts, ports in the example above).  The different fields
the values for the different fields are separated by colons.  This
can be altered with the option <tt>-s</tt> to <tt>_combination</tt> which specifies a
pattern.  Typically this is a character class, as for example
&lsquo;<tt>-s &quot;[:@]&quot;</tt>&rsquo; in the case of the <tt>users-hosts</tt> style.    Each
&lsquo;<var>field</var><tt>=</tt><var>pattern</var>&rsquo; specification restricts the
completions which apply to elements of the style with appropriately
matching fields.
</p>
<p>If no style with the given name is defined for the given tag,
or if none of the strings in style&rsquo;s value match, but a
function name of the required field preceded by an
underscore is defined, that function will be called to generate the
matches.  For example, if there is no &lsquo;<tt>users-hosts-ports</tt>&rsquo; or no
matching hostname when a host is required, the function &lsquo;<tt>_hosts</tt>&rsquo; will
automatically be called.
</p>
<p>If the same name is used for more than one field, in both the
&lsquo;<var>field</var><tt>=</tt><var>pattern</var>&rsquo; and the argument that gives the name of the
field to be completed, the number of the field (starting with one) may
be given after the fieldname, separated from it by a colon.
</p>
<p>All arguments after the required 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.
</p>
<a name="index-_005fcommand_005fnames"></a>
</dd>
<dt><tt>_command_names</tt> [ <tt>-e</tt> | <tt>-</tt> ]</dt>
<dd><p>This function completes words that are valid at command position: names of
aliases, builtins, hashed commands, functions, and so on.  With the <tt>-e</tt>
flag, only hashed commands are completed.  The <tt>-</tt> flag is ignored.
</p>
<a name="index-_005fcomp_005flocale"></a>
</dd>
<dt><tt>_comp_locale</tt></dt>
<dd><p>This function resets all the locale categories other than <tt>LC_CTYPE</tt> to
&lsquo;<tt>C</tt>&rsquo; so that the output from external commands can be easily analyzed by
the completion system. <tt>LC_CTYPE</tt> retains the current value (taking
<tt>LC_ALL</tt> and <tt>LANG</tt> into account), ensuring that non-ASCII characters
in file names are still handled properly.
</p>
<p>This function should normally be run only in a subshell, because the new
locale is exported to the environment. Typical usage would be
&lsquo;<tt>$(_comp_locale; </tt><var>command</var> ...<tt>)</tt>&rsquo;.
</p>
<a name="index-_005fcompleters"></a>
</dd>
<dt><tt>_completers</tt> [ <tt>-p</tt> ]</dt>
<dd><p>This function completes names of completers.
</p>
<dl compact="compact">
<dt><tt>-p</tt></dt>
<dd><p>Include the leading underscore (&lsquo;<tt>_</tt>&rsquo;) in the matches.
</p>
</dd>
</dl>

<a name="index-_005fdescribe"></a>

</dd>
<dt><tt>_describe </tt>[<tt>-12JVx</tt>] [ <tt>-oO</tt> | <tt>-t</tt> <var>tag</var> ] <var>descr</var> <var>name1</var> [ <var>name2</var> ] [ <var>opt</var> ... ]</dt>
<dt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt>[ <tt>-</tt><tt>-</tt> <var>name1</var> [ <var>name2</var> ] [ <var>opt</var> ... ] ... ]</dt>
<dd><p>This function associates completions with descriptions.
Multiple groups separated by <tt>-</tt><tt>-</tt> can be supplied, potentially with
different completion options <var>opt</var>s.
</p>
<p>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.  This is followed by
one or two names of arrays followed by options to pass to <tt>compadd</tt>.  The
array <var>name1</var> contains the possible completions with their descriptions in
the form &lsquo;<var>completion</var><tt>:</tt><var>description</var>&rsquo;.  Any literal colons in
<var>completion</var> must be quoted with a backslash.  If a <var>name2</var> is
given, it should have the same number of elements as <var>name1</var>; in this
case the corresponding elements are added as possible completions instead
of the <var>completion</var> strings from <var>name1</var>.  The completion list
will retain the descriptions from <var>name1</var>.  Finally, a set of
completion options can appear.
</p>
<p>If the option &lsquo;<tt>-o</tt>&rsquo; appears before the first argument, the matches added
will be treated as names of command options (N.B. not shell options),
typically following a &lsquo;<tt>-</tt>&rsquo;, &lsquo;<tt>-</tt><tt>-</tt>&rsquo; or &lsquo;<tt>+</tt>&rsquo; on the command
line.  In this case <tt>_describe</tt> uses the <tt>prefix-hidden</tt>,
<tt>prefix-needed</tt> and <tt>verbose</tt> styles to find out if the strings should
be added as completions and if the descriptions should be shown.  Without
the &lsquo;<tt>-o</tt>&rsquo; option, only the <tt>verbose</tt> style is used to decide how
descriptions are shown.  If &lsquo;<tt>-O</tt>&rsquo; is used instead of &lsquo;<tt>-o</tt>&rsquo;, command
options are completed as above but <tt>_describe</tt> will not handle the
<tt>prefix-needed</tt> style.
</p>
<p>With the <tt>-t</tt> option a <var>tag</var> can be specified.  The default is
&lsquo;<tt>values</tt>&rsquo; or, if the <tt>-o</tt> option is given, &lsquo;<tt>options</tt>&rsquo;.
</p>
<p>The options <tt>-1</tt>, <tt>-2</tt>, <tt>-J</tt>, <tt>-V</tt>, <tt>-x</tt> are passed to
<tt>_next_label</tt>.
</p>
<p>If selected by the <tt>list-grouped</tt> style, strings with the same
description will appear together in the list.
</p>
<p><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.
</p>
<a name="index-_005fdescription"></a>
</dd>
<dt><tt>_description</tt> [ <tt>-x</tt> ] [ <tt>-12VJ</tt> ] <var>tag</var> <var>name</var> <var>descr</var> [ <var>spec</var> ... ]</dt>
<dd><p>This function is not to be confused with the previous one; it is used as
a helper function for creating options to <tt>compadd</tt>.  It is buried
inside many of the higher level completion functions and so often does
not need to be called directly.
</p>
<p>The styles listed below are tested in the current context using the
given <var>tag</var>.  The resulting options for <tt>compadd</tt> are put into the
array named <var>name</var> (this is traditionally &lsquo;<tt>expl</tt>&rsquo;, but this
convention is not enforced).  The description for the corresponding set
of matches is passed to the function in <var>descr</var>.
</p>
<p>The styles tested are: <tt>format</tt>, <tt>hidden</tt>, <tt>matcher</tt>,
<tt>ignored-patterns</tt> and <tt>group-name</tt>.  The <tt>format</tt> style is first
tested for the given <var>tag</var> and then for the <tt>descriptions</tt> tag if
no value was found, while the remainder are only tested for the tag
given as the first argument.  The function also calls <tt>_setup</tt>
which tests some more styles.
</p>
<p>The string returned by the <tt>format</tt> style (if any) will be modified so
that the sequence &lsquo;<tt>%d</tt>&rsquo; 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.
</p>
<p>If <tt>_description</tt> is called with more than three arguments,
the additional <var>spec</var>s should be of the form &lsquo;<var>char</var><tt>:</tt><var>str</var>&rsquo;.
These supply escape sequence replacements for the <tt>format</tt> style:
every appearance of &lsquo;<tt>%</tt><var>char</var>&rsquo; will be
replaced by <var>string</var>.
</p>
<p>If the <tt>-x</tt> option is given, the description will be passed to
<tt>compadd</tt> using the <tt>-x</tt> option instead of the default <tt>-X</tt>.  This
means that the description will be displayed even if there are no
corresponding matches.
</p>
<p>The options placed in the array <var>name</var> take account of the
<tt>group-name</tt> style, so matches are placed in a separate group where
necessary.  The group normally has its elements sorted (by passing the
option <tt>-J</tt> to <tt>compadd</tt>), but if an option starting with &lsquo;<tt>-V</tt>&rsquo;,
&lsquo;<tt>-J</tt>&rsquo;, &lsquo;<tt>-1</tt>&rsquo;, or &lsquo;<tt>-2</tt>&rsquo; is passed to <tt>_description</tt>, that
option will be included in the array.  Hence it is possible for the
completion group to be unsorted by giving the option &lsquo;<tt>-V</tt>&rsquo;,
&lsquo;<tt>-1V</tt>&rsquo;, or &lsquo;<tt>-2V</tt>&rsquo;.
</p>
<p>In most cases, the function will be used like this:
</p>
<div class="example">
<pre class="example">local expl
_description files expl file
compadd &quot;$expl[@]&quot; - &quot;$files[@]&quot;
</pre></div>

<p>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.
</p>
<a name="index-_005fdir_005flist"></a>
</dd>
<dt><tt>_dir_list</tt> [ <tt>-s</tt> <var>sep</var> ] [ <tt>-S</tt> ]</dt>
<dd><p>Complete a list of directory names separated by colons
(the same format as <tt>$PATH</tt>).
</p>
<dl compact="compact">
<dt><tt>-s</tt> <var>sep</var></dt>
<dd><p>Use <var>sep</var> as separator between items.
<var>sep</var> defaults to a colon (&lsquo;<tt>:</tt>&rsquo;).
</p>
</dd>
<dt><tt>-S</tt></dt>
<dd><p>Add <var>sep</var> instead of slash (&lsquo;<tt>/</tt>&rsquo;) as an autoremoveable suffix.
</p>
</dd>
</dl>

<a name="index-_005fdispatch"></a>
</dd>
<dt><tt>_dispatch</tt> <var>context string</var> ...</dt>
<dd><p>This sets the current context to <var>context</var> and looks for completion
functions to handle this context by hunting through the list of command
names or special contexts (as described above for <tt>compdef</tt>)
given as <var>string</var>s.  The first completion function to be defined
for one of the contexts in the list is used to generate matches.
Typically, the last <var>string</var> is <tt>-default-</tt> to cause the function
for default completion to be used as a fallback.
</p>
<p>The function sets the parameter
<tt>$service</tt> to the <var>string</var> being tried, and sets
the <var>context/command</var> field (the fourth) of the <tt>$curcontext</tt>
parameter to the <var>context</var> given as the first argument.
</p>
<a name="index-_005femail_005faddresses"></a>
</dd>
<dt><tt>_email_addresses</tt> [ <tt>-c</tt> ] [ <tt>-n</tt> <var>plugin</var> ]</dt>
<dd><p>Complete email addresses.  Addresses are provided by plugins.
</p>
<dl compact="compact">
<dt><tt>-c</tt></dt>
<dd><p>Complete bare <tt>localhost@domain.tld</tt> addresses, without a name part or
a comment.
Without this option, RFC822 &lsquo;<var>Firstname Lastname</var> <tt>&lt;</tt><var>address</var><tt>&gt;</tt>&rsquo;
strings are completed.
</p>
</dd>
<dt><tt>-n</tt> <var>plugin</var></dt>
<dd><p>Complete aliases from <var>plugin</var>.  
</p>
</dd>
</dl>

<p>The following plugins are available by default:
<tt>_email-ldap</tt> (see the <tt>filter</tt> style),
<tt>_email-local</tt> (completes <var>user</var><tt>@</tt><var>hostname</var> Unix addresses),
<tt>_email-mail</tt> (completes aliases from <tt>~/.mailrc</tt>),
<tt>_email-mush</tt>,
<tt>_email-mutt</tt>,
and
<tt>_email-pine</tt>.
</p>
<p>Addresses from the <tt>_email-</tt><var>foo</var> plugin are added under the
tag &lsquo;<tt>email-</tt><var>foo</var>&rsquo;.
</p>
<p><em>Writing plugins</em>
</p>
<p>Plugins are written as separate functions with names starting with &lsquo;<tt>_email-</tt>&rsquo;.
They are invoked with the <tt>-c</tt> option and <tt>compadd</tt> options.
They should either do their own completion or
set the <tt>$reply</tt> array to a list of &lsquo;<var>alias</var><tt>:</tt><var>address</var>&rsquo; elements and return <tt>300</tt>.
New plugins will be picked up and run automatically.
</p>
<a name="index-_005ffiles"></a>
</dd>
<dt><tt>_files</tt></dt>
<dd><p>The function <tt>_files</tt> calls <tt>_path_files</tt> with all the arguments it
was passed except for <tt>-g</tt> and <tt>-/</tt>.  The use of these two options
depends on the setting of the  <tt>file-patterns</tt> style.
</p>
<p>This function accepts the full set of options allowed by
<tt>_path_files</tt>, described below.
</p>
<a name="index-_005fgnu_005fgeneric"></a>
</dd>
<dt><tt>_gnu_generic</tt></dt>
<dd><p>This function is a simple wrapper around the <tt>_arguments</tt> function
described above.  It can be used to determine automatically the long
options understood by commands that produce a list when passed the
option &lsquo;<tt>-</tt><tt>-help</tt>&rsquo;.  It is intended to be used 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>, use
</p>
<div class="example">
<pre class="example">compdef _gnu_generic foo bar
</pre></div>

<p>after the call to <tt>compinit</tt>.
</p>
<p>The completion system as supplied is conservative in its use of this
function, since it is important to be sure the command understands the
option &lsquo;<tt>-</tt><tt>-help</tt>&rsquo;.
</p>
<a name="index-_005fguard"></a>
</dd>
<dt><tt>_guard</tt> [ <var>options</var> ] <var>pattern descr</var></dt>
<dd><p>This function displays <var>descr</var> if <var>pattern</var> matches the string to
be completed.  It is intended to be used in the <var>action</var> for the
specifications passed to <tt>_arguments</tt> and similar functions.
</p>
<p>The return status is zero if the message was displayed and the word to
complete is not empty, and non-zero otherwise.
</p>
<p>The <var>pattern</var> may be preceded by any of the 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 will be ignored.  This fits in conveniently with the
argument-passing conventions of actions for <tt>_arguments</tt>.
</p>
<p>As an example, consider a command taking the options <tt>-n</tt> and
<tt>-none</tt>, where <tt>-n</tt> must be followed by a numeric value in the
same word.  By using:
</p>
<div class="example">
<pre class="example">_arguments '-n-: :_guard &quot;[0-9]#&quot; &quot;numeric value&quot;' '-none'
</pre></div>

<p><tt>_arguments</tt> can be made to both display the message &lsquo;<tt>numeric
value</tt>&rsquo; and complete options after &lsquo;<tt>-n&lt;TAB&gt;</tt>&rsquo;.  If the &lsquo;<tt>-n</tt>&rsquo; is
already followed by one or more digits (the pattern passed to
<tt>_guard</tt>) only the message will be displayed; if the &lsquo;<tt>-n</tt>&rsquo; is
followed by another character, only options are completed.
</p>
<a name="index-_005fmessage"></a>
</dd>
<dt><tt>_message</tt> [ <tt>-r12</tt> ] [ <tt>-VJ</tt> <var>group</var> ] <var>descr</var></dt>
<dt><tt>_message -e</tt> [ <var>tag</var> ] <var>descr</var></dt>
<dd><p>The <var>descr</var> is used in the same way as the third
argument to the <tt>_description</tt> function, except that the resulting
string will always be shown whether or not matches were
generated.  This is useful for displaying a help message in places where
no completions can be generated.
</p>
<p>The <tt>format</tt> style is examined with the <tt>messages</tt> tag to find a
message; the usual tag, <tt>descriptions</tt>, is used only if the style is
not set with the former.
</p>
<p>If the <tt>-r</tt> option is given, no style is used; the <var>descr</var> is
taken literally as the string to display.  This is most useful
when the <var>descr</var> comes from a pre-processed argument list
which already contains an expanded description.
</p>
<p>The <tt>-12VJ</tt> options and the <var>group</var> are passed to <tt>compadd</tt> and
hence determine the group the message string is added to.
</p>
<p>The second <tt>-e</tt> form gives a description for completions with the tag
<var>tag</var> to be shown even if there are no matches for that tag.  This form
is called by <tt>_arguments</tt> in the event that there is no action for an
option specification.  The tag can be omitted and if so the tag is taken
from the parameter <tt>$curtag</tt>; this is maintained by the completion
system and so is usually correct.  Note that if there are no matches at
the time this function is called, <tt>compstate[insert]</tt> is cleared, so
additional matches generated later are not inserted on the command line.
</p>
<a name="index-_005fmulti_005fparts"></a>
</dd>
<dt><tt>_multi_parts</tt> [ <tt>-i</tt> ] <var>sep</var> <var>array</var></dt>
<dd><p>The argument <var>sep</var> is a separator character.
The <var>array</var> may be either the
name of an array parameter or a literal array in the form
&lsquo;<tt>(foo bar</tt><tt>)</tt>&rsquo;, a parenthesised list of words separated
by whitespace.  The possible completions are the
strings from the array.  However, each chunk delimited by <var>sep</var> will be
completed separately.  For example, the <tt>_tar</tt> function uses
&lsquo;<tt>_multi_parts</tt> <tt>/</tt> <var>patharray</var>&rsquo; to complete partial file paths
from the given array of complete file paths.
</p>
<p>The <tt>-i</tt> option causes <tt>_multi_parts</tt> to insert a unique match even
if that requires multiple separators to be inserted.  This is not usually
the expected behaviour with filenames, but certain other types of
completion, for example those with a fixed set of possibilities, may be
more suited to this form.
</p>
<p>Like other utility functions, this function accepts the &lsquo;<tt>-V</tt>&rsquo;,
&lsquo;<tt>-J</tt>&rsquo;, &lsquo;<tt>-1</tt>&rsquo;, &lsquo;<tt>-2</tt>&rsquo;, &lsquo;<tt>-n</tt>&rsquo;, &lsquo;<tt>-f</tt>&rsquo;, &lsquo;<tt>-X</tt>&rsquo;, &lsquo;<tt>-M</tt>&rsquo;,
&lsquo;<tt>-P</tt>&rsquo;, &lsquo;<tt>-S</tt>&rsquo;, &lsquo;<tt>-r</tt>&rsquo;, &lsquo;<tt>-R</tt>&rsquo;, and &lsquo;<tt>-q</tt>&rsquo; options and passes
them to the <tt>compadd</tt> builtin.
</p>
<a name="index-_005fnext_005flabel"></a>
</dd>
<dt><tt>_next_label</tt> [ <tt>-x</tt> ] [ <tt>-12VJ</tt> ] <var>tag</var> <var>name</var> <var>descr</var> [ <var>option</var> ... ]</dt>
<dd><p>This function is used to implement the loop over different tag
labels for a particular tag as described above for the <tt>tag-order</tt>
style.  On each call it checks to see if there are any more tag labels; if
there is it returns status zero, otherwise non-zero.
As this function requires a current tag to be set, it must always follow
a call to <tt>_tags</tt> or <tt>_requested</tt>.
</p>
<p>The <tt>-x12VJ</tt> options and the first three arguments are passed to the
<tt>_description</tt> function.  Where appropriate the <var>tag</var> will be
replaced by a tag label in this call.  Any description given in
the <tt>tag-order</tt> style is preferred to the <var>descr</var> passed to
<tt>_next_label</tt>.
</p>
<p>The <var>option</var>s given after the <var>descr</var>
are set in the parameter given by <var>name</var>, and hence are to be passed
to <tt>compadd</tt> or whatever function is called to add the matches.
</p>
<p>Here is a typical use of this function for the tag <tt>foo</tt>.  The call to
<tt>_requested</tt> determines if tag <tt>foo</tt> is required at all; the loop
over <tt>_next_label</tt> handles any labels defined for the tag in the
<tt>tag-order</tt> style.
</p>
<div class="example">
<pre class="example">local expl ret=1
...
if _requested foo; then
  ...
  while _next_label foo expl '...'; do
    compadd &quot;$expl[@]&quot; ... &amp;&amp; ret=0
  done
  ...
fi
return ret
</pre></div>

<a name="index-_005fnormal"></a>
</dd>
<dt><tt>_normal</tt></dt>
<dd><p>This is the standard function called to handle completion outside
any special <tt>-</tt><var>context</var><tt>-</tt>.  It is called both to complete the command
word and also the arguments for a command.  In the second case,
<tt>_normal</tt> looks for a special completion for that command, and if
there is none it uses the completion for the <tt>-default-</tt> context.
</p>
<p>A second use is to reexamine the command line specified by the <tt>$words</tt>
array and the <tt>$CURRENT</tt> parameter after those have been modified.
For example, the function <tt>_precommand</tt>, which
completes after 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.  The effect is that &lsquo;<tt>nohup</tt> <var>cmd ...</var>&rsquo;
is treated in the same way as &lsquo;<var>cmd ...</var>&rsquo;.
</p>
<p>If the command name matches one of the patterns given by one of the
options <tt>-p</tt> or <tt>-P</tt> to <tt>compdef</tt>, the corresponding completion
function is called and then the parameter <tt>_compskip</tt> is
checked.  If it is set completion is terminated at that point even if
no matches have been found.  This is the same effect as in the
<tt>-first-</tt> context.
</p>
<a name="index-_005foptions"></a>
</dd>
<dt><tt>_options</tt></dt>
<dd><p>This can be used to complete the names of shell options.  It provides a
matcher specification that ignores a leading &lsquo;<tt>no</tt>&rsquo;, ignores
underscores and allows upper-case letters to
match their lower-case counterparts (for example, &lsquo;<tt>glob</tt>&rsquo;,
&lsquo;<tt>noglob</tt>&rsquo;, &lsquo;<tt>NO_GLOB</tt>&rsquo; are all completed).  Any arguments
are propagated to the <tt>compadd</tt> builtin.
</p>
<a name="index-_005foptions_005fset"></a>
<a name="index-_005foptions_005funset"></a>
</dd>
<dt><tt>_options_set</tt> and <tt>_options_unset</tt></dt>
<dd><p>These functions complete only set or unset options, with the same
matching specification used in the <tt>_options</tt> function.
</p>
<p>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 functions are not
generally used by the completion system.
</p>
<a name="index-_005fparameters"></a>
</dd>
<dt><tt>_parameters</tt></dt>
<dd><p>This is used to complete the names of shell parameters.
</p>
<p>The option &lsquo;<tt>-g</tt> <var>pattern</var>&rsquo; limits the completion to parameters
whose type matches the <var>pattern</var>.  The type of a parameter is that
shown by &lsquo;<tt>print ${(t)</tt><var>param</var><tt>}</tt>&rsquo;, hence judicious use of
&lsquo;<tt>*</tt>&rsquo; in <var>pattern</var> is probably necessary.
</p>
<p>All other arguments are passed to the <tt>compadd</tt> builtin.
</p>
<a name="index-_005fpath_005ffiles"></a>
</dd>
<dt><tt>_path_files</tt></dt>
<dd><p>This function is used throughout the completion system
to complete filenames.  It allows completion of partial paths.  For
example, the string &lsquo;<tt>/u/i/s/sig</tt>&rsquo; may be completed to
&lsquo;<tt>/usr/include/sys/signal.h</tt>&rsquo;.
</p>
<p>The options accepted by both <tt>_path_files</tt> and <tt>_files</tt> are:
</p>
<dl compact="compact">
<dt><tt>-f</tt></dt>
<dd><p>Complete all filenames.  This is the default.
</p>
</dd>
<dt><tt>-/</tt></dt>
<dd><p>Specifies that only directories should be completed.
</p>
</dd>
<dt><tt>-g</tt> <var>pattern</var></dt>
<dd><p>Specifies that only files matching the <var>pattern</var> should be completed.
</p>
</dd>
<dt><tt>-W</tt> <var>paths</var></dt>
<dd><p>Specifies path prefixes that are to be prepended to the string from the
command line to generate the filenames but that should not be inserted
as completions nor shown in completion listings.  Here, <var>paths</var> may be
the name of an array parameter, a literal list of paths enclosed in
parentheses or an absolute pathname.
</p>
</dd>
<dt><tt>-F</tt> <var>ignored-files</var></dt>
<dd><p>This behaves as for the corresponding option to the <tt>compadd</tt> builtin.
It gives direct control over which
filenames should be ignored.  If the option is not present, the
<tt>ignored-patterns</tt> style is used.
</p>
</dd>
</dl>

<p>Both <tt>_path_files</tt> and <tt>_files</tt> also accept the following options
which are passed to <tt>compadd</tt>: &lsquo;<tt>-J</tt>&rsquo;, &lsquo;<tt>-V</tt>&rsquo;,
&lsquo;<tt>-1</tt>&rsquo;, &lsquo;<tt>-2</tt>&rsquo;, &lsquo;<tt>-n</tt>&rsquo;, &lsquo;<tt>-X</tt>&rsquo;, &lsquo;<tt>-M</tt>&rsquo;, &lsquo;<tt>-P</tt>&rsquo;, &lsquo;<tt>-S</tt>&rsquo;,
&lsquo;<tt>-q</tt>&rsquo;, &lsquo;<tt>-r</tt>&rsquo;, and &lsquo;<tt>-R</tt>&rsquo;.
</p>
<p>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>
described above.
</p>
<a name="index-_005fpick_005fvariant"></a>

</dd>
<dt><tt>_pick_variant </tt>[ <tt>-b</tt> <var>builtin-label</var> ] [ <tt>-c</tt> <var>command</var> ] [ <tt>-r</tt> <var>name</var> ]</dt>
<dt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt><var>label</var><tt>=</tt><var>pattern</var> ... <var>label</var> [ <var>arg</var> ... ]</dt>
<dd><p>This function is used to resolve situations where a single command name
requires more than one type of handling, either because it
has more than one variant or because there is a name clash between two
different commands.
</p>
<p>The command to run is taken from the first element of the array
<tt>words</tt> unless this is overridden by the option <tt>-c</tt>.  This command
is run and its output is compared with a series of patterns.  Arguments
to be passed to the command can be specified at the end after all the
other arguments.  The patterns to try in order are given by the arguments
<var>label</var><tt>=</tt><var>pattern</var>; if the output of &lsquo;<var>command</var> <var>arg</var>
...&rsquo; contains <var>pattern</var>, then <var>label</var> is selected as the label
for the command variant.  If none of the patterns match, the final
command label is selected and status 1 is returned.
</p>
<p>If the &lsquo;<tt>-b</tt> <var>builtin-label</var>&rsquo; is given, the command is tested to
see if it is provided as a shell builtin, possibly autoloaded; if so,
the label <var>builtin-label</var> is selected as the label for the variant.
</p>
<p>If the &lsquo;<tt>-r</tt> <var>name</var>&rsquo; is given, the <var>label</var> picked is stored in
the parameter named <var>name</var>.
</p>
<p>The results are also cached in the <tt>_cmd_variant</tt> associative array
indexed by the name of the command run.
</p>
<a name="index-_005fregex_005farguments"></a>
</dd>
<dt><tt>_regex_arguments</tt> <var>name</var> <var>spec</var> ...</dt>
<dd><p>This function generates a completion function <var>name</var> which matches
the specifications <var>spec</var>s, a set of regular expressions as
described below.  After running <tt>_regex_arguments</tt>, the function
<var>name</var> should be called as a normal completion function.
The pattern to be matched is given by the contents of
the <tt>words</tt> array up to the current cursor position joined together
with null characters; no quotation is applied.
</p>
<p>The arguments are grouped as sets of alternatives separated by &lsquo;<tt>|</tt>&rsquo;,
which are tried one after the other until one matches.  Each alternative
consists of a one or more specifications which are tried left to right,
with each pattern matched being stripped in turn from the command line
being tested, until all of the group succeeds or until one fails; in the
latter case, the next alternative is tried.  This structure can be
repeated to arbitrary depth by using parentheses; matching proceeds from
inside to outside.
</p>
<p>A special procedure is applied if no test succeeds but the remaining
command line string contains no null character (implying the remaining
word is the one for which completions are to be generated).  The
completion target is restricted to the remaining word and any
<var>action</var>s for the corresponding patterns are executed.  In this case,
nothing is stripped from the command line string.  The order of
evaluation of the <var>action</var>s can be determined by the <tt>tag-order</tt>
style; the various formats supported by <tt>_alternative</tt> can be used
in <var>action</var>.  The <var>descr</var> is used for setting up the array
parameter <tt>expl</tt>.
</p>
<p>Specification arguments take one of following forms, in which
metacharacters such as &lsquo;<tt>(</tt>&rsquo;, &lsquo;<tt>)</tt>&rsquo;, &lsquo;<tt>#</tt>&rsquo; and &lsquo;<tt>|</tt>&rsquo;
should be quoted.
</p>
<dl compact="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>]</dt>
<dd><p>This is a single primitive component.
The function tests whether the combined pattern
&lsquo;<tt>(#b)((#B)</tt><var>pattern</var><tt>)</tt><var>lookahead</var><tt>*</tt>&rsquo; matches
the command line string.  If so, &lsquo;<var>guard</var>&rsquo; is evaluated and
its return status is examined to determine if the test has succeeded.
The <var>pattern</var> string &lsquo;<tt>[]</tt>&rsquo; is guaranteed never to match.
The <var>lookahead</var> is not stripped from the command line before the next
pattern is examined.
</p>
<p>The argument starting with <tt>:</tt> is used in the same manner as an argument to
<tt>_alternative</tt>.
</p>
<p>A component is used as follows: <var>pattern</var> is tested to
see if the component already exists on the command line.  If
it does, any following specifications are examined to find something to
complete.  If a component is reached but no such pattern exists yet on the
command line, the string containing the <var>action</var> is used to generate
matches to insert at that point.
</p>
</dd>
<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>]</dt>
<dd><p>This is similar to &lsquo;<tt>/</tt><var>pattern</var><tt>/</tt> ...&rsquo; but the left part of the
command line string (i.e. the part already matched by previous patterns)
is also considered part of the completion target.
</p>
</dd>
<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>]</dt>
<dd><p>This is similar to &lsquo;<tt>/</tt><var>pattern</var><tt>/</tt> ...&rsquo; but the <var>action</var>s of the
current and previously matched patterns are ignored even if the
following &lsquo;<var>pattern</var>&rsquo; matches the empty string.
</p>
</dd>
<dt><tt>(</tt> <var>spec</var> <tt>)</tt></dt>
<dd><p>Parentheses may be used to groups <var>spec</var>s; note each parenthesis
is a single argument to <tt>_regex_arguments</tt>.
</p>
</dd>
<dt><var>spec</var> <tt>#</tt></dt>
<dd><p>This allows any number of repetitions of <var>spec</var>.
</p>
</dd>
<dt><var>spec</var> <var>spec</var></dt>
<dd><p>The two <var>spec</var>s are to be matched one after the other as described
above.
</p>
</dd>
<dt><var>spec</var> <tt>|</tt> <var>spec</var></dt>
<dd><p>Either of the two <var>spec</var>s can be matched.
</p>
</dd>
</dl>

<p>The function <tt>_regex_words</tt> can be used as a helper function to
generate matches for a set of alternative words possibly with
their own arguments as a command line argument.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">_regex_arguments _tst /$'[^\0]#\0'/ \ 
    /$'[^\0]#\0'/ :'compadd aaa'
</pre></div>

<p>This generates a function <tt>_tst</tt> that completes <tt>aaa</tt> as its only
argument.  The <var>tag</var> and <var>description</var> for the action have been
omitted for brevity (this works but is not recommended in normal use).
The first component matches the command word, which is arbitrary; the
second matches  any argument.  As the argument is also arbitrary, any
following component would not depend on <tt>aaa</tt> being present.
</p>
<div class="example">
<pre class="example">_regex_arguments _tst /$'[^\0]#\0'/ \ 
    /$'aaa\0'/ :'compadd aaa'
</pre></div>

<p>This is a more typical use; it is similar, but any following patterns
would only match if <tt>aaa</tt> was present as the first argument.
</p>
<div class="example">
<pre class="example">_regex_arguments _tst /$'[^\0]#\0'/ \( \ 
    /$'aaa\0'/ :'compadd aaa' \ 
    /$'bbb\0'/ :'compadd bbb' \) \#
</pre></div>

<p>In this example, an indefinite number of command arguments may be
completed.  Odd arguments are completed as <tt>aaa</tt> and even arguments
as <tt>bbb</tt>.  Completion fails unless the set of <tt>aaa</tt> and <tt>bbb</tt>
arguments before the current one is matched correctly.
</p>
<div class="example">
<pre class="example">_regex_arguments _tst /$'[^\0]#\0'/ \ 
    \( /$'aaa\0'/ :'compadd aaa' \| \ 
    /$'bbb\0'/ :'compadd bbb' \) \#
</pre></div>

<p>This is similar, but either <tt>aaa</tt> or <tt>bbb</tt> may be completed for
any argument.  In this case <tt>_regex_words</tt> could be used to generate
a suitable expression for the arguments.
</p>

<a name="index-_005fregex_005fwords-_005b-_002dt-term-_005d"></a>
</dd>
<dt><tt>_regex_words</tt> <var>tag</var> <var>description</var> <var>spec</var> ...</dt>
<dd><p>This function can be used to generate arguments for the
<tt>_regex_arguments</tt> command which may be inserted at any point where
a set of rules is expected.  The <var>tag</var> and <var>description</var> give a
standard tag and description pertaining to the current context.  Each
<var>spec</var> contains two or three arguments separated by a colon: note
that there is no leading colon in this case.
</p>
<p>Each <var>spec</var> gives one of a set of words that may be completed at
this point, together with arguments.  It is thus roughly equivalent to
the <tt>_arguments</tt> function when used in normal (non-regex) completion.
</p>
<p>The part of the <var>spec</var> before the first colon is the word to be
completed.  This may contain a <tt>*</tt>; the entire word, before and after
the <tt>*</tt> is completed, but only the text before the <tt>*</tt> is required
for the context to be matched, so that further arguments may be
completed after the abbreviated form.
</p>
<p>The second part of <var>spec</var> is a description for the word being
completed.
</p>
<p>The optional third part of the <var>spec</var> describes how words following
the one being completed are themselves to be completed.  It will be
evaluated in order to avoid problems with quoting.  This means that
typically it contains a reference to an array containing previously
generated regex arguments.
</p>
<p>The option <tt>-t</tt> <var>term</var> specifies a terminator for the word
instead of the usual space.  This is handled as an auto-removable suffix
in the manner of the option <tt>-s</tt> <var>sep</var> to <tt>_values</tt>.
</p>
<p>The result of the processing by <tt>_regex_words</tt> is placed in the array
<tt>reply</tt>, which should be made local to the calling function.
If the set of words and arguments may be matched repeatedly, a <tt>#</tt>
should be appended to the generated array at that point.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">local -a reply
_regex_words mydb-commands 'mydb commands' \ 
  'add:add an entry to mydb:$mydb_add_cmds' \ 
  'show:show entries in mydb'
_regex_arguments _mydb &quot;$reply[@]&quot;
_mydb &quot;$@&quot;
</pre></div>

<p>This shows a completion function for a command <tt>mydb</tt> which takes
two command arguments, <tt>add</tt> and <tt>show</tt>.  <tt>show</tt> takes no arguments,
while the arguments for <tt>add</tt> have already been prepared in an
array <tt>mydb_add_cmds</tt>, quite possibly by a previous call to
<tt>_regex_words</tt>.
</p>
<a name="index-_005frequested"></a>
</dd>
<dt><tt>_requested</tt> [ <tt>-x</tt> ] [ <tt>-12VJ</tt> ] <var>tag</var> [ <var>name</var> <var>descr</var> [ <var>command</var> [ <var>arg</var> ... ] ]</dt>
<dd><p>This function is called to decide whether a tag already registered by a
call to <tt>_tags</tt> (see below) has been requested by the user and hence
completion should be performed for it.  It returns status zero if the
tag is requested and non-zero otherwise.  The function is typically used
as part of a loop over different tags as follows:
</p>
<div class="example">
<pre class="example">_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></div>

<p>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 set
the <tt>tag-order</tt> style to specify a set of tags to be completed at the
same time.
</p>
<p>If <var>name</var> and <var>descr</var> are given, <tt>_requested</tt> calls the
<tt>_description</tt> function with these arguments together with the options
passed to <tt>_requested</tt>.
</p>
<p>If <var>command</var> is given, the <tt>_all_labels</tt> function will be called
immediately with the same arguments.  In simple cases this makes it
possible to perform the test for the tag and the matching in one go.
For example:
</p>
<div class="example">
<pre class="example">local expl ret=1
_tags foo bar baz
while _tags; do
  _requested foo expl 'description' \ 
      compadd foobar foobaz &amp;&amp; ret=0
  ...
  (( ret )) || break
done
</pre></div>

<p>If the <var>command</var> is not <tt>compadd</tt>, it must nevertheless be prepared
to handle the same options.
</p>
<a name="index-_005fretrieve_005fcache"></a>
</dd>
<dt><tt>_retrieve_cache</tt> <var>cache_identifier</var></dt>
<dd><p>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 which defaults to <tt>~/.zcompcache</tt>.  The return status
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.
</p>
<p>See <tt>_store_cache</tt> below for more details.
</p>
<a name="index-_005fsep_005fparts"></a>
</dd>
<dt><tt>_sep_parts</tt></dt>
<dd><p>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
&lsquo;<tt>hosts=(ftp news)</tt>&rsquo; the call &lsquo;<tt>_sep_parts '(foo bar)' @ hosts</tt>&rsquo; will
complete the string  &lsquo;<tt>f</tt>&rsquo; to &lsquo;<tt>foo</tt>&rsquo; and the string &lsquo;<tt>b@n</tt>&rsquo; to
&lsquo;<tt>bar@news</tt>&rsquo;.
</p>
<p>This function accepts the <tt>compadd</tt> options &lsquo;<tt>-V</tt>&rsquo;, &lsquo;<tt>-J</tt>&rsquo;,
&lsquo;<tt>-1</tt>&rsquo;, &lsquo;<tt>-2</tt>&rsquo;, &lsquo;<tt>-n</tt>&rsquo;, &lsquo;<tt>-X</tt>&rsquo;, &lsquo;<tt>-M</tt>&rsquo;, &lsquo;<tt>-P</tt>&rsquo;, &lsquo;<tt>-S</tt>&rsquo;,
&lsquo;<tt>-r</tt>&rsquo;, &lsquo;<tt>-R</tt>&rsquo;, and &lsquo;<tt>-q</tt>&rsquo; and passes them on to the <tt>compadd</tt>
builtin used to add the matches.
</p>
<a name="index-_005fsequence"></a>
</dd>
<dt><tt>_sequence</tt> [ <tt>-s</tt> <var>sep</var> ] [ <tt>-n</tt> <var>max</var> ] [ <tt>-d</tt> ] <var>function</var> [ <tt>-</tt> ] ...</dt>
<dd><p>This function is a wrapper to other functions for completing items in a
separated list. The same function is used to complete each item in the
list. The separator is specified with the <tt>-s</tt> option. If <tt>-s</tt> is
omitted it will use &lsquo;<tt>,</tt>&rsquo;. Duplicate values are not matched unless
<tt>-d</tt> is specified. If there is a fixed or maximum number of items in
the list, this can be specified with the <tt>-n</tt> option.
</p>
<p>Common <tt>compadd</tt> options are passed on to the function. It is possible
to use <tt>compadd</tt> directly with <tt>_sequence</tt>, though <tt>_values</tt> may
be more appropriate in this situation.
</p>
<a name="index-_005fsetup"></a>
</dd>
<dt><tt>_setup</tt> <var>tag</var> [ <var>group</var> ]</dt>
<dd><p>This function sets up the special
parameters used by the completion system appropriately for the <var>tag</var>
given as the first argument.  It uses the styles <tt>list-colors</tt>,
<tt>list-packed</tt>, <tt>list-rows-first</tt>, <tt>last-prompt</tt>, <tt>accept-exact</tt>,
<tt>menu</tt> and <tt>force-list</tt>.
</p>
<p>The optional <var>group</var> supplies 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.
</p>
<p>This function is called automatically from <tt>_description</tt>
and hence is not normally called explicitly.
</p>
<a name="index-_005fstore_005fcache"></a>
</dd>
<dt><tt>_store_cache</tt> <var>cache_identifier</var> <var>param</var> ...</dt>
<dd><p>This function, together with <tt>_retrieve_cache</tt> and
<tt>_cache_invalid</tt>, implements a caching layer which can be used
in any completion function.  Data obtained by
costly operations are stored in parameters;
this function then dumps the values of those parameters to a file.  The
data can then be retrieved quickly from that file via <tt>_retrieve_cache</tt>,
even in different instances of the shell.
</p>
<p>The <var>cache_identifier</var> specifies the file which the data should be
dumped to.  The file is stored in a directory specified by the
<tt>cache-path</tt> style which defaults to <tt>~/.zcompcache</tt>.  The remaining
<var>param</var>s arguments are the parameters to dump to the file.
</p>
<p>The return status 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.
</p>
<p>The completion function may avoid calling <tt>_retrieve_cache</tt> when it
already has the completion data available as parameters. 
However, in that case it should
call <tt>_cache_invalid</tt> to check whether the data in the parameters and
in the cache are still valid.
</p>
<p>See the _perl_modules completion function for a simple example of
the usage of the caching layer.
</p>
<a name="index-_005ftags"></a>
</dd>
<dt><tt>_tags</tt> [ [ <tt>-C</tt> <var>name</var> ] <var>tag</var> ... ]</dt>
<dd><p>If called with arguments, these are taken to be the names of tags
valid for completions in the current context.  These tags are stored
internally and sorted by using the <tt>tag-order</tt> style.
</p>
<p>Next, <tt>_tags</tt> is called repeatedly without arguments from the same
completion function.  This successively selects the first, second,
etc. set of tags requested by the user.  The return status is zero if at
least one of the tags is requested and non-zero otherwise.  To test if a
particular tag is to be tried, the <tt>_requested</tt> function should be
called (see above).
</p>
<p>If &lsquo;<tt>-C</tt> <var>name</var>&rsquo; is given, <var>name</var> is temporarily stored in the
<var>argument</var> field (the fifth) of the context in the <tt>curcontext</tt> parameter
during the call to <tt>_tags</tt>; the field is restored on exit.  This
allows <tt>_tags</tt> to use a more 
specific context without having to change and reset the
<tt>curcontext</tt> parameter (which has the same effect).
</p>
<a name="index-_005ftilde_005ffiles"></a>
</dd>
<dt><tt>_tilde_files</tt></dt>
<dd><p>Like <tt>_files</tt>, but resolve leading tildes according to the rules of
filename expansion, so the suggested completions don&rsquo;t start with
a &lsquo;<tt>~</tt>&rsquo; even if the filename on the command-line does.
</p>
<a name="index-_005fvalues"></a>
</dd>
<dt><tt>_values</tt> [ <tt>-O</tt> <var>name</var> ] [ <tt>-s</tt> <var>sep</var> ] [ <tt>-S</tt> <var>sep</var> ] [ <tt>-wC</tt> ] <var>desc</var> <var>spec</var> ...</dt>
<dd><p>This is used to complete arbitrary keywords (values) and their arguments,
or lists of such combinations.
</p>
<p>If the first argument is the option &lsquo;<tt>-O</tt> <var>name</var>&rsquo;, it 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 passed to <tt>compadd</tt>
when executing an action.
</p>
<p>If the first argument (or the first argument after &lsquo;<tt>-O</tt> <var>name</var>&rsquo;)
is &lsquo;<tt>-s</tt>&rsquo;, the next argument is used as the character that separates
multiple values.  This character is automatically added after each value
in an auto-removable fashion (see below); all values completed by
&lsquo;<tt>_values -s</tt>&rsquo; appear in the same word on the command line, unlike
completion using <tt>_arguments</tt>.  If this option is not present, only a
single value will be completed per word.
</p>
<p>Normally, <tt>_values</tt> will only use the current word to determine
which values are already present on the command line and hence are not
to be completed again.  If the <tt>-w</tt> option is given, other arguments
are examined as well.
</p>
<p>The first non-option argument is used as a string to print as a
description before listing the values.
</p>
<p>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,
values can have only one argument, and the forms of action
beginning with an equal sign are not supported.
</p>
<p>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).  By default the equals
sign will be used as the separator between values and arguments.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">_values -s , 'description' \ 
        '*foo[bar]' \ 
        '(two)*one[number]:first count:' \ 
        'two[another number]::second count:(1 2 3)'
</pre></div>

<p>This describes three possible values: &lsquo;<tt>foo</tt>&rsquo;, &lsquo;<tt>one</tt>&rsquo;, and
&lsquo;<tt>two</tt>&rsquo;.  The first is described as &lsquo;<tt>bar</tt>&rsquo;, takes no argument 
and may appear more than once.  The second is described as
&lsquo;<tt>number</tt>&rsquo;, may appear more than once, and takes one mandatory
argument described as &lsquo;<tt>first count</tt>&rsquo;; no action is
specified, so it will not be completed.  The
&lsquo;<tt>(two)</tt>&rsquo; at the beginning says that if the value &lsquo;<tt>one</tt>&rsquo; is on
the line, the value &lsquo;<tt>two</tt>&rsquo; will no longer be considered a possible
completion.  Finally, the last value (&lsquo;<tt>two</tt>&rsquo;) is described
as &lsquo;<tt>another number</tt>&rsquo; and takes an optional argument described as
&lsquo;<tt>second count</tt>&rsquo; for which the completions (to appear after an
&lsquo;<tt>=</tt>&rsquo;) are &lsquo;<tt>1</tt>&rsquo;, &lsquo;<tt>2</tt>&rsquo;, and &lsquo;<tt>3</tt>&rsquo;.  The <tt>_values</tt> function
will complete lists of these values separated by commas.
</p>
<p>Like <tt>_arguments</tt>, this function temporarily adds another context name
component to the arguments element (the fifth) of the current context
while executing the <var>action</var>.  Here this name is just the name of the
value for which the argument is completed.
</p>
<p>The style <tt>verbose</tt> is used to decide if the descriptions for the
values (but not those for the arguments) should be printed.
</p>
<p>The associative array <tt>val_args</tt> is used to report values and their
arguments; this works similarly to the <tt>opt_args</tt> associative array
used by <tt>_arguments</tt>.  Hence the function calling <tt>_values</tt> should
declare the local parameters <tt>state</tt>, <tt>state_descr</tt>, <tt>line</tt>,
<tt>context</tt> and <tt>val_args</tt>:
</p>
<div class="example">
<pre class="example">local context state state_descr line
typeset -A val_args
</pre></div>

<p>when using an action of the form &lsquo;<tt>-&gt;</tt><var>string</var>&rsquo;.  With this
function the <tt>context</tt> parameter will be set to the name of the
value whose argument is to be completed.  Note that for <tt>_values</tt>,
the <tt>state</tt> and <tt>state_descr</tt> are scalars rather than arrays.
Only a single matching state is returned.
</p>
<p>Note also that <tt>_values</tt> normally adds the character used as the
separator between values as an auto-removable suffix (similar to a
&lsquo;<tt>/</tt>&rsquo; after a directory).  However, this is not possible for a
&lsquo;<tt>-&gt;</tt><var>string</var>&rsquo; action as the matches for the argument are
generated by the calling function.  To get the usual behaviour,
the calling function can add the separator <var>x</var> as a suffix by
passing the options &lsquo;<tt>-qS</tt> <var>x</var>&rsquo; either directly or indirectly to
<tt>compadd</tt>.
</p>
<p>The option <tt>-C</tt> is treated in the same way as it is by <tt>_arguments</tt>.
In that case the parameter <tt>curcontext</tt> should be made local instead 
of <tt>context</tt> (as described above).
</p>
<a name="index-_005fwanted"></a>
</dd>
<dt><tt>_wanted</tt> [ <tt>-x</tt> ] [ <tt>-C</tt> <var>name</var> ]  [ <tt>-12VJ</tt> ] <var>tag</var> <var>name</var> <var>descr</var> <var>command</var> [ <var>arg</var> ...]</dt>
<dd><p>In many contexts, completion can only 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.
</p>
<p>The arguments to <tt>_wanted</tt> are the same as those to <tt>_requested</tt>,
i.e. arguments to be passed to <tt>_description</tt>.  However, in this case
the <var>command</var> is not optional;  all the processing of tags, including
the loop over both tags and tag labels and the generation of matches,
is carried out automatically by <tt>_wanted</tt>.
</p>
<p>Hence to offer only one tag and immediately add the corresponding
matches with the given description:
</p>
<div class="example">
<pre class="example">local expl
_wanted tag expl 'description' \ 
    compadd matches...
</pre></div>

<p>Note that, as for <tt>_requested</tt>, the <var>command</var> must be able to
accept options to be passed down to <tt>compadd</tt>.
</p>
<p>Like <tt>_tags</tt> this function supports the <tt>-C</tt> option to give a
different name for the argument context field.  The <tt>-x</tt> option has
the same meaning as for <tt>_description</tt>.
</p>
<a name="index-_005fwidgets"></a>
</dd>
<dt><tt>_widgets</tt> [ <tt>-g</tt> <var>pattern</var> ]</dt>
<dd><p>This function completes names of zle widgets (see
<a href="Zsh-Line-Editor.html#Zle-Widgets">Widgets</a>).  The <var>pattern</var>, if present, is matched against values of the <tt>$widgets</tt>
special parameter, documented in 
<a href="Zsh-Modules.html#The-zsh_002fzleparameter-Module">The zsh/zleparameter Module</a>.
</p>
</dd>
</dl>

<hr>
<a name="Completion-System-Variables"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Functions" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Directories" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Completion-System-Variables-1"></a>
<h2 class="section">20.7 Completion System Variables</h2>
<a name="index-completion-system_002c-variables"></a>

<p>There are some standard variables, initialised by the <tt>_main_complete</tt>
function and then used from other functions.
</p>
<p>The standard variables are:
</p>
<dl compact="compact">
<dt><tt>_comp_caller_options</tt></dt>
<dd><p>The completion system uses <tt>setopt</tt> to set a number of options. This
allows functions to be written without concern for compatibility with
every possible combination of user options. However, sometimes completion
needs to know what the user&rsquo;s option preferences are. These are saved
in the <tt>_comp_caller_options</tt> associative array. Option names, spelled
in lowercase without underscores, are mapped to one or other of the
strings &lsquo;<tt>on</tt>&rsquo; and &lsquo;<tt>off</tt>&rsquo;.
</p>

</dd>
<dt><tt>_comp_priv_prefix</tt></dt>
<dd><p>Completion functions such as <tt>_sudo</tt> can set the <tt>_comp_priv_prefix</tt>
array to a command prefix that may then be used by <tt>_call_program</tt> to
match the privileges when calling programs to generate matches.
</p>
</dd>
</dl>

<p>Two more features are offered by the <tt>_main_complete</tt> function.  The
arrays <tt>compprefuncs</tt> and <tt>comppostfuncs</tt> may contain
names of functions that are to be called immediately before or after
completion has been tried.  A function will only be called once unless
it explicitly reinserts itself into the array.
</p>
<hr>
<a name="Completion-Directories"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System-Variables" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-System" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Completion-Directories-1"></a>
<h2 class="section">20.8 Completion Directories</h2>
<a name="index-completion-system_002c-directory-structure"></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="compact">
<dt><tt>Base</tt></dt>
<dd><p>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.
</p>
</dd>
<dt><tt>Zsh</tt></dt>
<dd><p>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.
</p>
</dd>
<dt><tt>Unix</tt></dt>
<dd><p>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>-</tt><tt>-help</tt> option is supported.
</p>
</dd>
<dt><tt>X</tt>, <tt>AIX</tt>, <tt>BSD</tt>, ...</dt>
<dd><p>Completion and utility function for commands available only on some systems.
These are not arranged hierarchically, so, for example, both the
<tt>Linux</tt> and <tt>Debian</tt> directories, as well as the <tt>X</tt> directory,
may be useful on your system.
</p>
</dd>
</dl>
<hr>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-System" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p><font size="-1">
  This document was generated on <em>April 8, 2018</em> using <a href="http://www.gnu.org/software/texinfo/"><em>texi2any</em></a>.
</font></p>

<font size="-1">Zsh version 5.5, released on April 8, 2018.</font>
</body>
</html>