Sophie

Sophie

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

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

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

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


<H1><A NAME="SEC98" HREF="zsh_toc.html#TOC98">Completion Widgets</A></H1>
<P>
<A NAME="IDX1030"></A>
<A NAME="IDX1031"></A>
<A NAME="IDX1032"></A>




<H2><A NAME="SEC99" HREF="zsh_toc.html#TOC99">Description</A></H2>
<P>
The shell's programmable completion mechanism can be manipulated in two
ways; here the low-level features supporting the newer, function-based
mechanism are defined.  A complete set of shell functions based on these
features is described in
the next chapter, section <A HREF="zsh_19.html#SEC105">Completion System</A>,
and users with no interest in adding to that system (or, potentially,
writing their own -- see dictionary entry for `hubris') should skip this
section.  The older system based on the <TT>compctl</TT> builtin command is
described in
the chapter section <A HREF="zsh_20.html#SEC119">Completion Using compctl</A>.


<P>
Completion widgets are defined by the <TT>-C</TT> option to the <TT>zle</TT>
builtin command provided by the <TT>zsh/zle</TT> module (see
section <A HREF="zsh_21.html#SEC157">The zsh/zle Module</A>). For example,


<P>

<PRE>
zle -C complete expand-or-complete completer
</PRE>

<P>
defines a widget named `<TT>complete</TT>'.  The second argument is the name
of any of the builtin widgets that handle completions:
<TT>complete-word</TT>, <TT>expand-or-complete</TT>,
<TT>expand-or-complete-prefix</TT>, <TT>menu-complete</TT>,
<TT>menu-expand-or-complete</TT>, <TT>reverse-menu-complete</TT>,
<TT>list-choices</TT>, or <TT>delete-char-or-list</TT>.  Note that this will still
work even if the widget in question has been re-bound.


<P>
When this newly defined widget is bound to a key
using the <TT>bindkey</TT> builtin command defined in the <TT>zsh/zle</TT> module
(section <A HREF="zsh_17.html#SEC84">Zsh Line Editor</A>), typing that key will call the shell function `<TT>completer</TT>'. This
function is responsible for generating the possible matches using the
builtins described below.  As with other ZLE widgets, the function is
called with its standard input closed.


<P>
Once the function returns, the completion code takes over control again
and treats the matches in the same manner as the specified builtin
widget, in this case <TT>expand-or-complete</TT>.


<P>


<P>




<H2><A NAME="SEC100" HREF="zsh_toc.html#TOC100">Special Parameters</A></H2>
<P>


<P>
Inside completion widgets, and any functions called from them, some
parameters have special meaning; outside these functions they are not
special to the shell in any way.  These parameters are used to pass
information between the completion code and the completion widget. Some of
the builtin commands and the condition codes use or change the current
values of these parameters.  Any existing values will be hidden during
execution of completion widgets; except for <TT>compstate</TT>, the parameters
are reset on each function exit (including nested function calls from
within the completion widget) to the values they had when the function was
entered.


<P>
<DL COMPACT>

<DT><TT>CURRENT</TT>
<DD>
<A NAME="IDX1033"></A>
 
This is the number of the current word, i.e. the word the cursor is
currently on in the <TT>words</TT> array.  Note that this value is only
correct if the <TT>ksharrays</TT> option is not set.

<A NAME="IDX1034"></A>
<DT><TT>IPREFIX</TT>
<DD>
Initially this will be set to the empty string.  This parameter functions
like <TT>PREFIX</TT>; it contains a string which precedes the one in <TT>PREFIX</TT>
and is not considered part of the list of matches.  Typically, a string is
transferred from the beginning of <TT>PREFIX</TT> to the end of <TT>IPREFIX</TT>, for
example:


<PRE>
IPREFIX=${PREFIX%%\=*}=
PREFIX=${PREFIX#*=}
</PRE>

causes the part of the prefix up to and including the first equal sign not
to be treated as part of a matched string.  This can be done automatically
by the <TT>compset</TT> builtin, see below.

<A NAME="IDX1035"></A>
<DT><TT>ISUFFIX</TT>
<DD>
As <TT>IPREFIX</TT>, but for a suffix that should not be considered part
of the matches; note that the <TT>ISUFFIX</TT> string follows the <TT>SUFFIX</TT>
string.

<A NAME="IDX1036"></A>
<DT><TT>PREFIX</TT>
<DD>
Initially this will be set to the part of the current word from the
beginning of the word up to the position of the cursor; it may be altered
to give a common prefix for all matches.

<A NAME="IDX1037"></A>
<DT><TT>QIPREFIX</TT>
<DD>
This parameter is read-only and contains the quoted string up to the
word being completed. E.g. when completing `<TT>"foo</TT>', this parameter
contains the double quote. If the <TT>-q</TT> option of <TT>compset</TT> is used 
(see below), and the original string was `<TT>"foo bar</TT>' with the
cursor on the `<TT>bar</TT>', this parameter contains `<TT>"foo </TT>'.

<A NAME="IDX1038"></A>
<DT><TT>QISUFFIX</TT>
<DD>
Like <TT>QIPREFIX</TT>, but containing the suffix.

<A NAME="IDX1039"></A>
<DT><TT>SUFFIX</TT>
<DD>
Initially this will be set to the part of the current word from the
cursor position to the end; it may be altered to give a common suffix for
all matches.  It is most useful when the option <TT>COMPLETE_IN_WORD</TT> is
set, as otherwise the whole word on the command line is treated as a
prefix.

<A NAME="IDX1040"></A>
<A NAME="IDX1041"></A>
<DT><TT>compstate</TT>
<DD>
This is an associative array with various keys and values that the
completion code uses to exchange information with the completion widget.
The keys are:

<DL COMPACT>

<DT><TT>all_quotes</TT>
<DD>
<A NAME="IDX1042"></A>
 
The <TT>-q</TT> option of the <TT>compset</TT> builtin command (see below)
allows a quoted string to be broken into separate words; if the cursor is
on one of those words, that word will be completed, possibly invoking
`<TT>compset -q</TT>' recursively.  With this key it is possible to test the
types of quoted strings which are currently broken into parts in this
fashion.  Its value contains one character for each quoting level.  The
characters are a single quote or a double quote for strings quoted with
these characters and a backslash for strings not starting with a quote
character.  The first character in the value always corresponds to the
innermost quoting level.

<A NAME="IDX1043"></A>
<DT><TT>context</TT>
<DD>
This will be set by the completion code to the overall context
in which completion is attempted. Possible values are:

<DL COMPACT>

<DT><TT>array_value</TT>
<DD>
when completing inside the value of an array parameter assignment; in
this case the <TT>words</TT> array contains the words inside the parentheses.

<DT><TT>brace_parameter</TT>
<DD>
when completing the name of a parameter in a parameter expansion beginning
with <TT>${</TT>.

<DT><TT>command</TT>
<DD>
when completing for a normal command (either in command position or for
an argument of the command).

<DT><TT>condition</TT>
<DD>
when completing inside a `<TT>[[</TT>...<TT>]]</TT>' conditional expression; in
this case the <TT>words</TT> array contains only the words inside the
conditional expression.

<DT><TT>math</TT>
<DD>
when completing in a mathematical environment such as a
`<TT>((</TT>...<TT>))</TT>' construct.

<DT><TT>parameter</TT>
<DD>
when completing the name of a parameter in a parameter expansion beginning
with <TT>$</TT> but not <TT>${</TT>.

<DT><TT>redirect</TT>
<DD>
when completing after a redirection operator.

<DT><TT>subscript</TT>
<DD>
when completing inside a parameter subscript.

<DT><TT>value</TT>
<DD>
when completing the value of a parameter assignment.

</DL>

<A NAME="IDX1044"></A>
<DT><TT>exact</TT>
<DD>
Controls the behaviour when the <TT>REC_EXACT</TT> option is set.  It will be
set to <TT>accept</TT> if an exact match would be accepted, and will be unset
otherwise.

If it was set when at least one match equal to the string on the line
was generated, the match is accepted.

<A NAME="IDX1045"></A>
<DT><TT>exact_string</TT>
<DD>
The string of an exact match if one was found, otherwise unset.

<A NAME="IDX1046"></A>
<DT><TT>ignored</TT>
<DD>
The number of words that were ignored because they matched one of the
patterns given with the <TT>-F</TT> option to the <TT>compadd</TT> builtin
command.

<A NAME="IDX1047"></A>
<DT><TT>insert</TT>
<DD>
This controls the manner in which a match is inserted into the command
line.  On entry to the widget function, if it is unset the command line is
not to be changed; if set to <TT>unambiguous</TT>, any prefix common to all
matches is to be inserted; if set to <TT>automenu-unambiguous</TT>, the
common prefix is to be inserted and the next invocation of the
completion code may start menu completion (due to the <TT>AUTO_MENU</TT>
option being set); if set to <TT>menu</TT> or <TT>automenu</TT> menu completion
will be started for the matches currently generated (in the
latter case this will happen because the <TT>AUTO_MENU</TT> is set). The
value may also contain the string `<TT>tab</TT>' when the completion code
would normally not really do completion, but only insert the TAB
character.

On exit it may be set to any of the values above (where setting it to
the empty string is the same as unsetting it), or to a number, in which
case the match whose number is given will be inserted into the command line.
Negative numbers count backward from the last match (with `<TT>-1</TT>'
selecting the last match) and out-of-range values are wrapped
around, so that a value of zero selects the last match and a value
one more than the maximum selects the first. Unless the value of this
key ends in a space, the match is inserted as in a menu completion,
i.e. without automatically appending a space.

Both <TT>menu</TT> and <TT>automenu</TT> may also specify the the number of the
match to insert, given after a colon.  For example, `<TT>menu:2</TT>' says
to start menu completion, beginning with the second match.

Note that a value containing the substring `<TT>tab</TT>' makes the
matches generated be ignored and only the TAB be inserted.

Finally, it may also be set to <TT>all</TT>, which makes all matches
generated be inserted into the line.

<A NAME="IDX1048"></A>
<DT><TT>insert_positions</TT>
<DD>
When the completion system inserts an unambiguous string into the
line, there may be multiple places where characters are missing or
where the character inserted differs from at least one match.  The
value of this key contains a colon separated list of all these
positions, as indexes into the command line.

<A NAME="IDX1049"></A>
<DT><TT>last_prompt</TT>
<DD>
If this is set to a non-empty string for every match added, the
completion code will move the cursor back to the previous prompt after
the list of completions has been displayed.  Initially this is set or
unset according to the <TT>ALWAYS_LAST_PROMPT</TT> option.

<A NAME="IDX1050"></A>
<DT><TT>list</TT>
<DD>
This controls whether or how the list of matches will be displayed.  If it
is unset or empty they will never be listed; if its value begins with
<TT>list</TT>, they will always be listed; if it begins with <TT>autolist</TT>
or <TT>ambiguous</TT>, they will be listed when the <TT>AUTO_LIST</TT> or
<TT>LIST_AMBIGUOUS</TT> options respectively would normally cause them to
be.

If the substring <TT>force</TT> appears in the value, this makes the
list be shown even if there is only one match. Normally, the list
would be shown only if there are at least two matches.

The value contains the substring <TT>packed</TT> if the <TT>LIST_PACKED</TT>
option is set. If this substring is given for all matches added to a
group, this group will show the <TT>LIST_PACKED</TT> behavior. The same is
done for the <TT>LIST_ROWS_FIRST</TT> option with the substring <TT>rows</TT>.

Finally, if the value contains the string <TT>explanations</TT>, only the
explanation strings, if any, will be listed and if it contains
<TT>messages</TT>, only the messages (added with the <TT>-x</TT> option of
<TT>compadd</TT>) will be listed.  If it contains both <TT>explanations</TT> and 
<TT>messages</TT> both kinds of explanation strings will be listed.  It
will be set appropriately on entry to a completion widget and may be
changed there.

<A NAME="IDX1051"></A>
<DT><TT>list_lines</TT>
<DD>
This gives the number of lines that are needed to display the full
list of completions.  Note that to calculate the total number of lines
to display you need to add the number of lines needed for the command
line to this value, this is available as the value of the <TT>BUFFERLINES</TT>
special parameter.

<A NAME="IDX1052"></A>
<DT><TT>list_max</TT>
<DD>
Initially this is set to the value of the <TT>LISTMAX</TT> parameter.
It may be set to any other value; when the widget exits this value
will be used in the same way as the value of <TT>LISTMAX</TT>.

<A NAME="IDX1053"></A>
<DT><TT>nmatches</TT>
<DD>
The number of matches generated and accepted by the completion code so
far.

<A NAME="IDX1054"></A>
<DT><TT>old_insert</TT>
<DD>
On entry to the widget this will be set to the number of the match of
an old list of completions that is currently inserted into the command
line. If no match has been inserted, this is unset.

As with <TT>old_list</TT>, the value of this key will only be used if it is the
string <TT>keep</TT>. If it was set to this value by the widget and there was an
old match inserted into the command line, this match will be kept and if
the value of the <TT>insert</TT> key specifies that another match should be
inserted, this will be inserted after the old one.

<A NAME="IDX1055"></A>
<DT><TT>old_list</TT>
<DD>
This is set to <TT>yes</TT> if there is still a valid list of completions
from a previous completion at the time the widget is invoked.  This will
usually be the case if and only if the previous editing operation was a
completion widget or one of the builtin completion functions.  If there is a
valid list and it is also currently shown on the screen, the value of this
key is <TT>shown</TT>.

After the widget has exited the value of this key is only used if it
was set to <TT>keep</TT>.  In this case the completion code will continue
to use this old list.  If the widget generated new matches, they will
not be used.

<A NAME="IDX1056"></A>
<DT><TT>parameter</TT>
<DD>
The name of the parameter when completing in a subscript or in the
value of a parameter assignment.

<A NAME="IDX1057"></A>
<DT><TT>pattern_insert</TT>
<DD>
Normally this is set to <TT>menu</TT>, which specifies that menu completion will
be used whenever a set of matches was generated using pattern matching.  If
it is set to any other non-empty string by the user and menu completion is
not selected by other option settings, the code will instead insert any
common prefix for the generated matches as with normal completion.

<A NAME="IDX1058"></A>
<DT><TT>pattern_match</TT>
<DD>
Locally controls the behaviour given by the <TT>GLOB_COMPLETE</TT> option.
Initially it is set to `<TT>*</TT>' if and only if the option is set.
The completion widget may set it to this value, to an empty string
(which has the same effect as unsetting it), or to any
other non-empty string.  If it is non-empty, unquoted metacharacters on the
command line will be treated as patterns; if it is `<TT>*</TT>', then
additionally a wildcard `<TT>*</TT>' is assumed at the cursor position; if
it is empty or unset, metacharacters will be treated literally.

Note that the matcher specifications given to the <TT>compadd</TT> builtin
command are not used if this is set to a non-empty string.

<A NAME="IDX1059"></A>
<DT><TT>quote</TT>
<DD>
When completing inside quotes, this contains the quotation character
(i.e. either a single quote, a double quote, or a backtick).  Otherwise it
is unset.

<A NAME="IDX1060"></A>
<DT><TT>quoting</TT>
<DD>
When completing inside single quotes, this is set to the string
<TT>single</TT>; inside double quotes, the string
<TT>double</TT>; inside backticks, the string <TT>backtick</TT>.
Otherwise it is unset.

<A NAME="IDX1061"></A>
<DT><TT>redirect</TT>
<DD>
The redirection operator when completing in a redirection position,
i.e. one of <TT>&#60;</TT>, <TT>&#62;</TT>, etc.

<A NAME="IDX1062"></A>
<DT><TT>restore</TT>
<DD>
This is set to <TT>auto</TT> before a function is entered, which forces the
special parameters mentioned above (<TT>words</TT>, <TT>CURRENT</TT>, <TT>PREFIX</TT>,
<TT>IPREFIX</TT>, <TT>SUFFIX</TT>, and <TT>ISUFFIX</TT>) to be restored to their
previous values when the function exits.   If a function unsets it or
sets it to any other string, they will not be restored.

<A NAME="IDX1063"></A>
<DT><TT>to_end</TT>
<DD>
Specifies the occasions on which the cursor is moved to the end of a string
when a match is inserted.  On entry to a widget function, it may be
<TT>single</TT> if this will happen when a single unambiguous match was inserted
or <TT>match</TT> if it will happen any time a match is inserted (for example,
by menu completion; this is likely to be the effect of the <TT>ALWAYS_TO_END</TT>
option).

On exit, it may be set to <TT>single</TT> as above.  It may also be set to
<TT>always</TT>, or to the empty string or unset; in those cases the cursor will
be moved to the end of the string always or never respectively.  Any
other string is treated as <TT>match</TT>.

<A NAME="IDX1064"></A>
<DT><TT>unambiguous</TT>
<DD>
This key is read-only and will always be set to the common (unambiguous)
prefix the completion code has generated for all matches added so far.

<A NAME="IDX1065"></A>
<DT><TT>unambiguous_cursor</TT>
<DD>
This gives the position the cursor would be placed at if the
common prefix in the <TT>unambiguous</TT> key were inserted, relative to
the value of that key. The cursor would be placed before the character
whose index is given by this key.

<A NAME="IDX1066"></A>
<DT><TT>unambiguous_positions</TT>
<DD>
This contains all positions where characters in the unambiguous string
are missing or where the character inserted differs from at least one
of the matches.  The positions are given as indexes into the string
given by the value of the <TT>unambiguous</TT> key.

<A NAME="IDX1067"></A>
<DT><TT>vared</TT>
<DD>
If completion is called while editing a line using the <TT>vared</TT>
builtin, the value of this key is set to the name of the parameter
given as an argument to <TT>vared</TT>.  This key is only set while a <TT>vared</TT>
command is active.

</DL>

<A NAME="IDX1068"></A>
<DT><TT>words</TT>
<DD>
This array contains the words present on the command line currently being
edited.

</DL>

<P>




<H2><A NAME="SEC101" HREF="zsh_toc.html#TOC101">Builtin Commands</A></H2>
<P>
<DL COMPACT>

<DT><TT>compadd</TT> [ <TT>-akqQfenUl12C</TT> ] [ <TT>-F</TT> <VAR>array</VAR> ]
<DD>
<A NAME="IDX1069"></A>
 <A NAME="IDX1070"></A>
 
<DT>[ <TT>-P</TT> <VAR>prefix</VAR> ] [ <TT>-S</TT> <VAR>suffix</VAR> ]
<DD>
<DT>[ <TT>-p</TT> <VAR>hidden-prefix</VAR> ] [ <TT>-s</TT> <VAR>hidden-suffix</VAR> ]
<DD>
<DT>[ <TT>-i</TT> <VAR>ignored-prefix</VAR> ] [ <TT>-I</TT> <VAR>ignored-suffix</VAR> ]
<DD>
<DT>[ <TT>-W</TT> <VAR>file-prefix</VAR> ] [ <TT>-d</TT> <VAR>array</VAR> ]
<DD>
<DT>[ <TT>-J</TT> <VAR>name</VAR> ] [ <TT>-V</TT> <VAR>name</VAR> ] [ <TT>-X</TT> <VAR>explanation</VAR> ] [ <TT>-x</TT> <VAR>message</VAR> ]
<DD>
<DT>[ <TT>-r</TT> <VAR>remove-chars</VAR> ] [ <TT>-R</TT> <VAR>remove-func</VAR> ]
<DD>
<DT>[ <TT>-D</TT> <VAR>array</VAR> ] [ <TT>-O</TT> <VAR>array</VAR> ] [ <TT>-A</TT> <VAR>array</VAR> ]
<DD>
<DT>[ <TT>-M</TT> <VAR>match-spec</VAR> ] [ <TT>--</TT> ] [ <VAR>words</VAR> ... ]
<DD>
This builtin command can be used to add matches directly and control
all the information the completion code stores with each possible
match. The return value is zero if at least one match was added and
non-zero if no matches were added.

The completion code breaks the string to complete into seven fields in
the order: 


<BLOCKQUOTE>
<P>
<VAR>&#60;ipre&#62;&#60;apre&#62;&#60;hpre&#62;&#60;word&#62;&#60;hsuf&#62;&#60;asuf&#62;&#60;isuf&#62;</VAR>
</BLOCKQUOTE>

The first field
is an ignored prefix taken from the command line, the contents of the
<TT>IPREFIX</TT> parameter plus the string given with the <TT>-i</TT>
option. With the <TT>-U</TT> option, only the string from the <TT>-i</TT>
option is used. The field <VAR>&#60;apre&#62;</VAR> is an optional prefix string
given with the <TT>-P</TT> option.  The <VAR>&#60;hpre&#62;</VAR> field is a string
that is considered part of the match but that should not be shown when 
listing completions, given with the <TT>-p</TT> option; for example,
functions that do filename generation might specify
a common path prefix this way.  <VAR>&#60;word&#62;</VAR> is the part of the match that
should appear in the list of completions, i.e. one of the <VAR>words</VAR> given
at the end of the <TT>compadd</TT> command line. The suffixes <VAR>&#60;hsuf&#62;</VAR>,
<VAR>&#60;asuf&#62;</VAR> and <VAR>&#60;isuf&#62;</VAR> correspond to the prefixes <VAR>&#60;hpre&#62;</VAR>,
<VAR>&#60;apre&#62;</VAR> and <VAR>&#60;ipre&#62;</VAR> and are given by the options <TT>-s</TT>, <TT>-S</TT> and
<TT>-I</TT>, respectively.

The supported flags are:

<DL COMPACT>

<DT><TT>-P</TT> <VAR>prefix</VAR>
<DD>
This gives a string to be inserted before the given <VAR>words</VAR>.  The
string given is not considered as part of the match and any shell
metacharacters in it will not be quoted when the string is inserted.

<DT><TT>-S</TT> <VAR>suffix</VAR>
<DD>
Like <TT>-P</TT>, but gives a string to be inserted after the match.

<DT><TT>-p</TT> <VAR>hidden-prefix</VAR>
<DD>
This gives a string that should be inserted into the command line before the
match but that should not appear in the list of matches. Unless the
<TT>-U</TT> option is given, this string must be matched as part of the string
on the command line.

<DT><TT>-s</TT> <VAR>hidden-suffix</VAR>
<DD>
Like `<TT>-p</TT>', but gives a string to insert after the match.

<DT><TT>-i</TT> <VAR>ignored-prefix</VAR>
<DD>
This gives a string to insert into the command line just before any
string given with the `<TT>-P</TT>' option.  Without `<TT>-P</TT>' the string is
inserted before the string given with `<TT>-p</TT>' or directly before the
match.

<DT><TT>-I</TT> <VAR>ignored-suffix</VAR>
<DD>
Like <TT>-i</TT>, but gives an ignored suffix.

<DT><TT>-a</TT>
<DD>
With this flag the <VAR>words</VAR> are taken as names of arrays and the
possible matches are their values.  If only some elements of the
arrays are needed, the <VAR>words</VAR> may also contain subscripts, as in
`<TT>foo[2,-1]</TT>'.

<DT><TT>-k</TT>
<DD>
With this flag the <VAR>words</VAR> are taken as names of associative arrays
and the possible matches are their keys.  As for <TT>-a</TT>, the
<VAR>words</VAR> may also contain subscripts, as in `<TT>foo[(R)*bar*]</TT>'.

<DT><TT>-d</TT> <VAR>array</VAR>
<DD>
This adds per-match display strings. The <VAR>array</VAR> should contain one 
element per <VAR>word</VAR> given. The completion code will then display the 
first element instead of the first <VAR>word</VAR>, and so on. The
<VAR>array</VAR> may be given as the name of an array parameter or directly
as a space-separated list of words in parentheses.

If there are fewer display strings than <VAR>words</VAR>, the leftover
<VAR>words</VAR> will be displayed unchanged and if there are more display
strings than <VAR>words</VAR>, the leftover display strings will be silently
ignored.

<DT><TT>-l</TT>
<DD>
This option only has an effect if used together with the <TT>-d</TT>
option. If it is given, the display strings are listed one per line,
not arrayed in columns.

<DT><TT>-J</TT> <VAR>name</VAR>
<DD>
Gives the name of the group of matches the words should be stored in.

<DT><TT>-V</TT> <VAR>name</VAR>
<DD>
Like <TT>-J</TT> but naming a unsorted group. These are in a different name 
space than groups created with the <TT>-J</TT> flag.

<DT><TT>-1</TT>
<DD>
If given together with the <TT>-V</TT> option, makes
only consecutive duplicates in the group be removed. If combined with
the <TT>-J</TT> option, this has no visible effect. Note that groups
with and without this flag are in different name spaces.

<DT><TT>-2</TT>
<DD>
If given together with the <TT>-J</TT> or <TT>-V</TT> option, makes all
duplicates be kept. Again, groups with and without this flag are in
different name spaces.

<DT><TT>-X</TT> <VAR>explanation</VAR>
<DD>
The <VAR>explanation</VAR> string will be printed with the list of matches,
above the group currently selected.

<DT><TT>-x</TT> <VAR>message</VAR>
<DD>
Like <TT>-X</TT>, but the <VAR>message</VAR> will be printed even if there are no 
matches in the group.

<DT><TT>-q</TT>
<DD>
The suffix given with <TT>-S</TT> will be automatically removed if 
the next character typed is a blank or does not insert anything, or if
the suffix consists of only one character and the next character typed 
is the same character.

<DT><TT>-r</TT> <VAR>remove-chars</VAR>
<DD>
This is a more versatile form of the <TT>-q</TT> option.
The suffix given with <TT>-S</TT> or the slash automatically added after
completing directories will be automatically removed if
the next character typed inserts one of the characters given in the
<VAR>remove-chars</VAR>.  This string is parsed as a characters class and
understands the backslash sequences used by the <TT>print</TT> command.  For
example, `<TT>-r "a-z\t"</TT>' removes the suffix if the next character typed
inserts a lowercase character or a TAB, and `<TT>-r "^0-9"</TT>' removes the
suffix if the next character typed inserts anything but a digit. One extra
backslash sequence is understood in this string: `<TT>\-</TT>' stands for
all characters that insert nothing. Thus `<TT>-S "=" -q</TT>' is the same
as `<TT>-S "=" -r "= \t\n\-"</TT>'.

<DT><TT>-R</TT> <VAR>remove-func</VAR>
<DD>
This is another form of the <TT>-r</TT> option. When a suffix 
has been inserted and the completion accepted, the function
<VAR>remove-func</VAR> will be called after the next character typed.  It is
passed the length of the suffix as an argument and can use the special
parameters available in ordinary (non-completion) zle widgets (see
section <A HREF="zsh_17.html#SEC84">Zsh Line Editor</A>) to analyse and modify the command line.

<DT><TT>-f</TT>
<DD>
If this flag is given, all of the matches built from <VAR>words</VAR> are
marked as being the names of files.  They are not required to be actual
filenames, but if they are, and the option <TT>LIST_TYPES</TT> is set, the
characters describing the types of the files in the completion lists will
be shown. This also forces a slash to be added when the name of a
directory is completed.

<DT><TT>-e</TT>
<DD>
This flag can be used to tell the completion code that the matches
added are parameter names for a parameter expansion. This will make
the <TT>AUTO_PARAM_SLASH</TT> and <TT>AUTO_PARAM_KEYS</TT> options be used for
the matches.

<DT><TT>-W</TT> <VAR>file-prefix</VAR>
<DD>
This string is a pathname that will be
prepended to each of the matches formed by the given <VAR>words</VAR> together 
with any prefix specified by the <TT>-p</TT> option to form a complete filename
for testing.  Hence it is only useful if combined with the <TT>-f</TT> flag, as
the tests will not otherwise be performed.

<DT><TT>-F</TT> <VAR>array</VAR>
<DD>
Specifies an array containing patterns. Words matching one of these
patterns are ignored, i.e. not considered to be possible matches.

The <VAR>array</VAR> may be the name of an array parameter or a list of
literal patterns enclosed in parentheses and quoted, as in `<TT>-F "(*?.o
*?.h)"</TT>'. If the name of an array is given, the elements of the array are
taken as the patterns.

<DT><TT>-Q</TT>
<DD>
This flag instructs the completion 
code not to quote any metacharacters in the words when inserting them
into the command line.

<DT><TT>-M</TT> <VAR>match-spec</VAR>
<DD>
This gives local match specifications as described below in
section <A HREF="zsh_18.html#SEC103">Matching Control</A>. This option may be given more than once. In 
this case all <VAR>match-spec</VAR>s given are concatenated with spaces
between them to form the specification string to use.
Note that they will only be used if the <TT>-U</TT> option is not given.

<DT><TT>-n</TT>
<DD>
Specifies that the words added are to be used as possible
matches, but are not to appear in the completion listing.

<DT><TT>-U</TT>
<DD>
If this flag is given, all words given will be accepted and no matching
will be done by the completion code. Normally this is used in
functions that do the matching themselves.

<DT><TT>-O</TT> <VAR>array</VAR>
<DD>
If this option is given, the <VAR>words</VAR> are <EM>not</EM> added to the set of
possible completions.  Instead, matching is done as usual and all of the
<VAR>words</VAR> given as arguments that match the string on the command line
will be stored in the array parameter whose name is given as <VAR>array</VAR>.

<DT><TT>-A</TT> <VAR>array</VAR>
<DD>
As the <TT>-O</TT> option, except that instead of those of the <VAR>words</VAR> which
match being stored in <VAR>array</VAR>, the strings generated internally by the
completion code are stored. For example,
with a matching specification of `<TT>-M "L:|no="</TT>', the string `<TT>nof</TT>'
on the command line and the string `<TT>foo</TT>' as one of the <VAR>words</VAR>, this
option stores the string `<TT>nofoo</TT>' in the array, whereas the <TT>-O</TT>
option stores the `<TT>foo</TT>' originally given.

<DT><TT>-D</TT> <VAR>array</VAR>
<DD>
As with <TT>-O</TT>, the <VAR>words</VAR> are not added to the set of possible
completions.  Instead, the completion code tests whether each <VAR>word</VAR> 
in turn matches what is on the line.  If the <VAR>n</VAR>'th <VAR>word</VAR> does not
match, the <VAR>n</VAR>'th element of the <VAR>array</VAR> is removed.  Elements
for which the corresponding <VAR>word</VAR> is matched are retained.

<DT><TT>-C</TT>
<DD>
This option adds a special match which expands to all other matches
when inserted into the line, even those that are added after this
option is used.  Together with the <TT>-d</TT> option it is possible to
specify a string that should be displayed in the list for this special 
match.  If no string is given, it will be shown as a string containing 
the strings that would be inserted for the other matches, truncated to 
the width of the screen.

<DT><TT>-</TT>
<DD>
<DT><TT>-</TT><TT>-</TT>
<DD>
This flag ends the list of flags and options. All arguments after it
will be taken as the words to use as matches even if they begin with
hyphens.

</DL>

Except for the <TT>-M</TT> flag, if any of these flags is given more than
once, the first one (and its argument) will be used.

<A NAME="IDX1071"></A>
<A NAME="IDX1072"></A>
<DT><TT>compset -p</TT> <VAR>number</VAR>
<DD>
<DT><TT>compset -P</TT> [ <VAR>number</VAR> ] <VAR>pattern</VAR>
<DD>
<DT><TT>compset -s</TT> <VAR>number</VAR>
<DD>
<DT><TT>compset -S</TT> [ <VAR>number</VAR> ] <VAR>pattern</VAR>
<DD>
<DT><TT>compset -n</TT> <VAR>begin</VAR> [ <VAR>end</VAR> ]
<DD>
<DT><TT>compset -N</TT> <VAR>beg-pat</VAR> [ <VAR>end-pat</VAR> ]
<DD>
<DT><TT>compset -q</TT>
<DD>
This command simplifies modification of the special parameters,
while its return value allows tests on them to be carried out.

The options are:

<DL COMPACT>

<DT><TT>-p</TT> <VAR>number</VAR>
<DD>
If the contents of the <TT>PREFIX</TT> parameter is longer than <VAR>number</VAR>
characters, the first <VAR>number</VAR> characters are removed from it and
appended to the contents of the <TT>IPREFIX</TT> parameter.

<DT><TT>-P</TT> [ <VAR>number</VAR> ] <VAR>pattern</VAR>
<DD>
If the value of the <TT>PREFIX</TT> parameter begins with anything that
matches the <VAR>pattern</VAR>, the matched portion is removed from
<TT>PREFIX</TT> and appended to <TT>IPREFIX</TT>.

Without the optional <VAR>number</VAR>, the longest match is taken, but
if <VAR>number</VAR> is given, anything up to the <VAR>number</VAR>'th match is
moved.  If the <VAR>number</VAR> is negative, the <VAR>number</VAR>'th longest
match is moved. For example, if <TT>PREFIX</TT> contains the string
`<TT>a=b=c</TT>', then <TT>compset -P '*\='</TT> will move the string `<TT>a=b=</TT>' 
into the <TT>IPREFIX</TT> parameter, but <TT>compset -P 1 '*\='</TT> will move only
the string `<TT>a=</TT>'.

<DT><TT>-s</TT> <VAR>number</VAR>
<DD>
As <TT>-p</TT>, but transfer the last <VAR>number</VAR> characters from the
value of <TT>SUFFIX</TT> to the front of the value of <TT>ISUFFIX</TT>.

<DT><TT>-S</TT> [ <VAR>number</VAR> ] <VAR>pattern</VAR>
<DD>
As <TT>-P</TT>, but match the last portion of <TT>SUFFIX</TT> and transfer the
matched portion to the front of the value of <TT>ISUFFIX</TT>.

<DT><TT>-n</TT> <VAR>begin</VAR> [ <VAR>end</VAR> ]
<DD>
If the current word position as specified by the parameter <TT>CURRENT</TT> 
is greater than or equal to <VAR>begin</VAR>, anything up to the
<VAR>begin</VAR>'th word is removed from the <TT>words</TT> array and the value
of the parameter <TT>CURRENT</TT> is decremented by <VAR>begin</VAR>.

If the optional <VAR>end</VAR> is given, the modification is done only if
the current word position is also less than or equal to <VAR>end</VAR>. In
this case, the words from position <VAR>end</VAR> onwards are also removed from
the <TT>words</TT> array.

Both <VAR>begin</VAR> and <VAR>end</VAR> may be negative to count backwards
from the last element of the <TT>words</TT> array.

<DT><TT>-N</TT> <VAR>beg-pat</VAR> [ <VAR>end-pat</VAR> ]
<DD>
If one of the elements of the <TT>words</TT> array before the one at the
index given by the value of the parameter <TT>CURRENT</TT> matches the
pattern <VAR>beg-pat</VAR>, all elements up to and including the matching one are
removed from the <TT>words</TT> array and the value of <TT>CURRENT</TT> is changed to
point to the same word in the changed array.

If the optional pattern <VAR>end-pat</VAR> is also given, and there is an
element in the <TT>words</TT> array matching this pattern, the parameters
are modified only if the index of this word is higher than the one
given by the <TT>CURRENT</TT> parameter (so that the matching word has 
to be after the cursor). In this case, the words starting with the one
matching <TT>end-pat</TT> are also removed from the <TT>words</TT>
array. If <TT>words</TT> contains no word matching <VAR>end-pat</VAR>, the
testing and modification is performed as if it were not given.

<DT><TT>-q</TT>
<DD>
The word
currently being completed is split on spaces into separate words,
respecting the usual shell quoting conventions.  The 
resulting words are stored in the <TT>words</TT> array, and <TT>CURRENT</TT>,
<TT>PREFIX</TT>, <TT>SUFFIX</TT>, <TT>QIPREFIX</TT>, and <TT>QISUFFIX</TT> are modified to
reflect the word part that is completed.

</DL>

In all the above cases the return value is zero if the test succeeded
and the parameters were modified and non-zero otherwise. This allows
one to use this builtin in tests such as:


<PRE>
if compset -P '*\='; then ...
</PRE>

This forces anything up to and including the last equal sign to be
ignored by the completion code.

<DT><TT>compcall</TT> [ <TT>-TD</TT> ]
<DD>
This allows the use of completions defined with the <TT>compctl</TT> builtin
from within completion widgets.  The list of matches will be generated as
if one of the non-widget completion function (<TT>complete-word</TT>, etc.)
had been called, except that only <TT>compctl</TT>s given for specific commands
are used. To force the code to try completions defined with the <TT>-T</TT>
option of <TT>compctl</TT> and/or the default completion (whether defined by
<TT>compctl -D</TT> or the builtin default) in the appropriate places, the
<TT>-T</TT> and/or <TT>-D</TT> flags can be passed to <TT>compcall</TT>.

The return value can be used to test if a matching <TT>compctl</TT>
definition was found. It is non-zero if a <TT>compctl</TT> was found and
zero otherwise.

Note that this builtin is defined by the <TT>zsh/compctl</TT> module.

</DL>

<P>




<H2><A NAME="SEC102" HREF="zsh_toc.html#TOC102">Condition Codes</A></H2>
<P>
<A NAME="IDX1073"></A>


<P>
The following additional condition codes for use within the <TT>[[ ... ]]</TT>
construct are available in completion widgets.  These work on the special
parameters.  All of these tests can also be performed by the <TT>compset</TT>
builtin, but in the case of the condition codes the contents of the special
parameters are not modified.


<P>
<DL COMPACT>

<DT><TT>-prefix</TT> [ <VAR>number</VAR> ] <VAR>pattern</VAR>
<DD>
true if the test for the <TT>-P</TT> option of <TT>compset</TT> would succeed.

<DT><TT>-suffix</TT> [ <VAR>number</VAR> ] <VAR>pattern</VAR>
<DD>
true if the test for the <TT>-S</TT> option of <TT>compset</TT> would succeed.

<DT><TT>-after</TT> <VAR>beg-pat</VAR>
<DD>
true if the test of the <TT>-N</TT> option with only the <VAR>beg-pat</VAR> given 
would succeed.

<DT><TT>-between</TT> <VAR>beg-pat end-pat</VAR>
<DD>
true if the test for the <TT>-N</TT> option with both patterns would succeed.

</DL>

<P>




<H2><A NAME="SEC103" HREF="zsh_toc.html#TOC103">Matching Control</A></H2>
<P>


<P>
It is possible by use of the
<TT>-M</TT> option of the <TT>compadd</TT> builtin command to specify how the
characters in the string to be completed (referred to here as the
command line) map onto the characters in the list of matches produced by
the completion code (referred to here as the trial completions). Note
that this is not used if the command line contains a glob pattern and
the <TT>GLOB_COMPLETE</TT> option is set or the <TT>pattern_match</TT> of the
<TT>compstate</TT> special association is set to a non-empty string.


<P>
The <VAR>match-spec</VAR> given as the argument to the <TT>-M</TT> option (see
section <A HREF="zsh_18.html#SEC101">Builtin Commands</A>) consists of one or more matching descriptions separated by
whitespace.  Each description consists of a letter followed by a colon
and then the patterns describing which character sequences on the line match
which character sequences in the trial completion.  Any sequence of
characters not handled in this fashion must match exactly, as usual.


<P>
The forms of <VAR>match-spec</VAR> understood are as follows. In each case, the
form with an uppercase initial character retains the string already
typed on the command line as the final result of completion, while with
a lowercase initial character the string on the command line is changed
into the corresponding part of the trial completion.


<P>
<DL COMPACT>

<DT><TT>m:</TT><VAR>lpat</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>M:</TT><VAR>lpat</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
Here, <VAR>lpat</VAR> is a pattern that matches on the command line,
corresponding to <VAR>tpat</VAR> which matches in the trial completion.

<DT><TT>l:</TT><VAR>lanchor</VAR><TT>|</TT><VAR>lpat</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>L:</TT><VAR>lanchor</VAR><TT>|</TT><VAR>lpat</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>l:</TT><VAR>lanchor</VAR><TT>||</TT><VAR>ranchor</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>L:</TT><VAR>lanchor</VAR><TT>||</TT><VAR>ranchor</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>b:</TT><VAR>lpat</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>B:</TT><VAR>lpat</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
These letters are for patterns that are anchored by another pattern on
the left side. Matching for <VAR>lpat</VAR> and <VAR>tpat</VAR> is as for <TT>m</TT> and
<TT>M</TT>, but the pattern <VAR>lpat</VAR> matched on the command line must be
preceded by the pattern <VAR>lanchor</VAR>.  The <VAR>lanchor</VAR> can be blank to
anchor the match to the start of the command line string; otherwise the
anchor can occur anywhere, but must match in both the command line and
trial completion strings.

If no <VAR>lpat</VAR> is given but a <VAR>ranchor</VAR> is, this matches the gap
between substrings matched by <VAR>lanchor</VAR> and <VAR>ranchor</VAR>. Unlike
<VAR>lanchor</VAR>, the <VAR>ranchor</VAR> only needs to match the trial
completion string.

The <TT>b</TT> and <TT>B</TT> forms are similar to <TT>l</TT> and <TT>L</TT> with an empty 
anchor, but need to match only the beginning of the trial completion
or the word on the command line, respectively.

<DT><TT>r:</TT><VAR>lpat</VAR><TT>|</TT><VAR>ranchor</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>R:</TT><VAR>lpat</VAR><TT>|</TT><VAR>ranchor</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>r:</TT><VAR>lanchor</VAR><TT>||</TT><VAR>ranchor</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>R:</TT><VAR>lanchor</VAR><TT>||</TT><VAR>ranchor</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>e:</TT><VAR>lpat</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
<DT><TT>E:</TT><VAR>lpat</VAR><TT>=</TT><VAR>tpat</VAR>
<DD>
As <TT>l</TT>, <TT>L</TT>, <TT>b</TT> and <TT>B</TT>, with the difference that the command
line and trial completion patterns are anchored on the right side.
Here an empty <VAR>ranchor</VAR> and the <TT>e</TT> and <TT>E</TT> forms force the
match to the end of the trial completion or command line string.

</DL>

<P>
Each <VAR>lpat</VAR>, <VAR>tpat</VAR> or <VAR>anchor</VAR> is either an empty string or
consists of a sequence of literal characters (which may be quoted with a
backslash), question marks, character classes, and correspondence
classes; ordinary shell patterns are not used.  Literal characters match
only themselves, question marks match any character, and character
classes are formed as for globbing and match any character in the given
set.


<P>
Correspondence classes are defined like character classes, but with two
differences: they are delimited by a pair of braces, and negated classes
are not allowed, so the characters <TT>!</TT> and <TT>^</TT> have no special
meaning directly after the opening brace.  They indicate that a range of
characters on the line match a range of characters in the trial
completion, but (unlike ordinary character classes) paired according to
the corresponding position in the sequence. For example, to make any
lowercase letter on the line match the corresponding uppercase letter in
the trial completion, you can use `<TT>m:{a-z}={A-Z}</TT>'.  More than one
pair of classes can occur, in which case the first class before the
<TT>=</TT> corresponds to the first after it, and so on.  If one side has
more such classes than the other side, the superfluous classes behave
like normal character classes.  In anchor patterns correspondence classes
also behave like normal character classes.


<P>
The pattern <VAR>tpat</VAR> may also be one or two stars, `<TT>*</TT>' or
`<TT>**</TT>'. This means that the pattern on the command line can match
any number of characters in the trial completion. In this case the
pattern must be anchored (on either side); in the case of a single
star, the <VAR>anchor</VAR> then determines how much of the trial completion
is to be included -- only the characters up to the next appearance of
the anchor will be matched. With two stars, substrings matched by the
anchor can be matched, too.


<P>
Examples:


<P>
The keys of the <TT>options</TT> association defined by the <TT>parameter</TT>
module are the option names in all-lowercase form, without
underscores, and without the optional <TT>no</TT> at the beginning even
though the builtins <TT>setopt</TT> and <TT>unsetopt</TT> understand option names
with uppercase letters, underscores, and the optional <TT>no</TT>.  The
following alters the matching rules so that the prefix <TT>no</TT> and any
underscore are ignored when trying to match the trial completions
generated and uppercase letters on the line match the corresponding
lowercase letters in the words:


<P>

<PRE>
compadd -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \ 
  ${(k)options} 
</PRE>

<P>
The first part says that the pattern `<TT>[nN][oO]</TT>' at the beginning
(the empty anchor before the pipe symbol) of the string on the
line matches the empty string in the list of words generated by
completion, so it will be ignored if present. The second part does the
same for an underscore anywhere in the command line string, and the
third part uses correspondence classes so that any
uppercase letter on the line matches the corresponding lowercase
letter in the word. The use of the uppercase forms of the
specification characters (<TT>L</TT> and <TT>M</TT>) guarantees that what has
already been typed on the command line (in particular the prefix
<TT>no</TT>) will not be deleted.


<P>
Note that the use of <TT>L</TT> in the first part means that it matches
only when at the beginning of both the command line string and the
trial completion. I.e., the string `<TT>_NO_f</TT>' would not be
completed to `<TT>_NO_foo</TT>', nor would `<TT>NONO_f</TT>' be completed to
`<TT>NONO_foo</TT>' because of the leading underscore or the second
`<TT>NO</TT>' on the line which makes the pattern fail even though they are 
otherwise ignored. To fix this, one would use `<TT>B:[nN][oO]=</TT>'
instead of the first part. As described above, this matches at the
beginning of the trial completion, independent of other characters or
substrings at the beginning of the command line word which are ignored
by the same or other <VAR>match-spec</VAR>s.


<P>
The second example makes completion case insensitive.  This is just
the same as in the option example, except here we wish to retain the
characters in the list of completions:


<P>

<PRE>
compadd -M 'm:{a-z}={A-Z}' ... 
</PRE>

<P>
This makes lowercase letters match their uppercase counterparts.
To make uppercase letters match the lowercase forms as well:


<P>

<PRE>
compadd -M 'm:{a-zA-Z}={A-Za-z}' ... 
</PRE>

<P>
A nice example for the use of <TT>*</TT> patterns is partial word
completion. Sometimes you would like to make strings like `<TT>c.s.u</TT>'
complete to strings like `<TT>comp.source.unix</TT>', i.e. the word on the
command line consists of multiple parts, separated by a dot in this
example, where each part should be completed separately -- note,
however, that the case where each part of the word, i.e. `<TT>comp</TT>',
`<TT>source</TT>' and `<TT>unix</TT>' in this example, is to be completed from
separate sets of matches
is a different problem to be solved by the implementation of the
completion widget.  The example can be handled by:


<P>

<PRE>
compadd -M 'r:|.=* r:|=*' \ 
  - comp.sources.unix comp.sources.misc ...
</PRE>

<P>
The first specification says that <VAR>lpat</VAR> is the empty string, while
<VAR>anchor</VAR> is a dot; <VAR>tpat</VAR> is <TT>*</TT>, so this can match anything
except for the `<TT>.</TT>' from the anchor in
the trial completion word.  So in `<TT>c.s.u</TT>', the matcher sees `<TT>c</TT>',
followed by the empty string, followed by the anchor `<TT>.</TT>', and
likewise for the second dot, and replaces the empty strings before the
anchors, giving `<TT>c</TT>[<TT>omp</TT>]<TT>.s</TT>[<TT>ources</TT>]<TT>.u</TT>[<TT>nix</TT>]', where
the last part of the completion is just as normal.


<P>
With the pattern shown above, the string `<TT>c.u</TT>' could not be
completed to `<TT>comp.sources.unix</TT>' because the single star means
that no dot (matched by the anchor) can be skipped. By using two stars 
as in `<TT>r:|.=**</TT>', however, `<TT>c.u</TT>' could be completed to
`<TT>comp.sources.unix</TT>'. This also shows that in some cases,
especially if the anchor is a real pattern, like a character class,
the form with two stars may result in more matches than one would like.


<P>
The second specification is needed to make this work when the cursor is
in the middle of the string on the command line and the option
<TT>COMPLETE_IN_WORD</TT> is set. In this case the completion code would
normally try to match trial completions that end with the string as
typed so far, i.e. it will only insert new characters at the cursor
position rather then at the end.  However in our example we would like
the code to recognise matches which contain extra characters after the
string on the line (the `<TT>nix</TT>' in the example).  Hence we say that the
empty string at the end of the string on the line matches any characters
at the end of the trial completion.


<P>
More generally, the specification


<P>

<PRE>
compadd -M 'r:|[.,_-]=* r:|=*' ... 
</PRE>

<P>
allows one to complete words with abbreviations before any of the
characters in the square brackets.  For example, to
complete <TT>veryverylongfile.c</TT> rather than <TT>veryverylongheader.h</TT>
with the above in effect, you can just type <TT>very.c</TT> before attempting
completion.


<P>
The specifications with both a left and a right anchor are useful to
complete partial words whose parts are not separated by some
special character. For example, in some places strings have to be
completed that are formed `<TT>LikeThis</TT>' (i.e. the separate parts are
determined by a leading uppercase letter) or maybe one has to
complete strings with trailing numbers. Here one could use the simple
form with only one anchor as in:


<P>

<PRE>
compadd -M 'r:|[A-Z0-9]=* r:|=*' LikeTHIS FooHoo 5foo123 5bar234
</PRE>

<P>
But with this, the string `<TT>H</TT>' would neither complete to `<TT>FooHoo</TT>'
nor to `<TT>LikeTHIS</TT>' because in each case there is an uppercase
letter before the `<TT>H</TT>' and that is matched by the anchor. Likewise, 
a `<TT>2</TT>' would not be completed. In both cases this could be changed
by using `<TT>r:|[A-Z0-9]=**</TT>', but then `<TT>H</TT>' completes to both
`<TT>LikeTHIS</TT>' and `<TT>FooHoo</TT>' and a `<TT>2</TT>' matches the other
strings because characters can be inserted before every uppercase
letter and digit. To avoid this one would use:


<P>

<PRE>
compadd -M 'r:[^A-Z0-9]||[A-Z0-9]=** r:|=*' \ 
    LikeTHIS FooHoo foo123 bar234
</PRE>

<P>
By using these two anchors, a `<TT>H</TT>' matches only uppercase `<TT>H</TT>'s that 
are immediately preceded by something matching the left anchor
`<TT>[^A-Z0-9]</TT>'. The effect is, of course, that `<TT>H</TT>' matches only
the string `<TT>FooHoo</TT>', a `<TT>2</TT>' matches only `<TT>bar234</TT>' and so on.


<P>
When using the completion system (see
section <A HREF="zsh_19.html#SEC105">Completion System</A>), users can define match specifications that are to be used for
specific contexts by using the <TT>matcher</TT> and <TT>matcher-list</TT>
styles. The values for the latter will be used everywhere.


<P>




<H2><A NAME="SEC104" HREF="zsh_toc.html#TOC104">Completion Widget Example</A></H2>
<P>
<A NAME="IDX1074"></A>


<P>
The first step is to define the widget:


<P>

<PRE>
zle -C complete complete-word complete-files
</PRE>

<P>
Then the widget can be bound to a key using the <TT>bindkey</TT> builtin
command:


<P>

<PRE>
bindkey '^X\t' complete
</PRE>

<P>
After that the shell function <TT>complete-files</TT> will be invoked
after typing control-X and TAB. The function should then generate the
matches, e.g.:


<P>

<PRE>
complete-files () { compadd - * }
</PRE>

<P>
This function will complete files in the current directory matching the 
current word.


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