* Re: PATCH: yet another completer
@ 2000-02-11 10:56 Sven Wischnowsky
0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2000-02-11 10:56 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer wrote:
> On Feb 10, 3:03pm, Sven Wischnowsky wrote:
> } Subject: PATCH: yet another completer
> }
> } This almost makes me think that we could actually remove $compmatchers
> } and leave only the compctl-with-only-`-M' thing for those who still
> } use compctl.
>
> I'd be in favor of this, since I always found compmatchers needlessly
> confusing.
After thinking some more about this yesterday evening, I find that
even more interesting, too. So here is what would be the patch for it.
Still, I'd like to know on how many toes we are stepping when we
remove it. At least we should make a remark about it somewhere for
next release (`$compmatchers superseeded by the _matcher completer' or
some such).
Small comment about the patch: most of the stuff is moved into the
compctl module, but, as with other things (like the support for
compctl's -y option) there are still things that had to be left in the
complete module to make this work. Namely the ability to handle match
specs coming from different sources (or multiple match spec lists at
all). Make me think: one fine day...
Bye
Sven
diff -ru ../z.old/Completion/Commands/_read_comp Completion/Commands/_read_comp
--- ../z.old/Completion/Commands/_read_comp Fri Feb 11 09:23:35 2000
+++ Completion/Commands/_read_comp Fri Feb 11 10:29:21 2000
@@ -26,14 +26,7 @@
setopt localoptions extendedglob nobadpattern # xtrace promptsubst
# local PS4='%N:%i:$((#key))> '
-# Took me ages to work this out. If we're not on the first global
-# matcher specification, we mustn't do any I/O.
-if [[ compstate[matcher] -gt 1 && -z $_read_comp ]]; then
- return 1
-fi
-
-if [[ compstate[matcher] -gt 1 ||
- ( ${+NUMERIC} = 0 && -n $_read_comp ) ]]; then
+if [[ ${+NUMERIC} = 0 && -n $_read_comp ]]; then
if [[ $_read_comp = _* ]]; then
eval $_read_comp
else
diff -ru ../z.old/Completion/Core/_approximate Completion/Core/_approximate
--- ../z.old/Completion/Core/_approximate Fri Feb 11 09:23:36 2000
+++ Completion/Core/_approximate Fri Feb 11 10:30:04 2000
@@ -8,10 +8,6 @@
local _comp_correct _correct_expl comax cfgacc
local curcontext="${curcontext}" oldcontext opm="$compstate[pattern_match]"
-# Only if all global matchers have been tried.
-
-[[ compstate[matcher] -ne compstate[total_matchers] ]] && return 1
-
# We don't try correction if the string is too short.
[[ "${#:-$PREFIX$SUFFIX}" -le 1 ]] && return 1
@@ -60,16 +56,7 @@
builtin compadd "$_correct_expl[@]" "$@"
}
-# Now initialise our counter. We also set `compstate[matcher]'
-# to `-1'. This allows completion functions to use the simple
-# `[[ compstate[matcher] -gt 1 ]] && return' to avoid being
-# called for multiple global match specs and still be called
-# again when correction is done. Also, this makes it easy to
-# test if correction is attempted since `compstate[matcher]'
-# will never be set to a negative value by the completion code.
-
_comp_correct=1
-compstate[matcher]=-1
[[ -z "$compstate[pattern_match]" ]] && compstate[pattern_match]='*'
@@ -98,7 +85,6 @@
[[ "$compstate[list]" != list* ]] &&
compstate[list]="$compstate[list] force"
fi
- compstate[matcher]="$compstate[total_matchers]"
unfunction compadd
compstate[pattern_match]="$opm"
@@ -109,7 +95,6 @@
(( _comp_correct++ ))
done
-compstate[matcher]="$compstate[total_matchers]"
unfunction compadd
compstate[pattern_match]="$opm"
diff -ru ../z.old/Completion/Core/_expand Completion/Core/_expand
--- ../z.old/Completion/Core/_expand Fri Feb 11 09:23:36 2000
+++ Completion/Core/_expand Fri Feb 11 10:30:14 2000
@@ -18,10 +18,6 @@
return 1
fi
-# Do this only for the first global matcher.
-
-[[ "$compstate[matcher]" -le 1 ]] || return 1
-
# In exp we will collect the expansion.
exp=("$word")
diff -ru ../z.old/Completion/Core/_main_complete Completion/Core/_main_complete
--- ../z.old/Completion/Core/_main_complete Fri Feb 11 09:23:37 2000
+++ Completion/Core/_main_complete Fri Feb 11 10:31:33 2000
@@ -128,8 +128,7 @@
fi
fi
fi
-elif [[ compstate[matcher] -eq compstate[total_matchers] &&
- $#_lastdescr -ne 0 ]] &&
+elif [[ $#_lastdescr -ne 0 ]] &&
zstyle -s ":completion:${curcontext}:warnings" format format; then
local str
@@ -148,34 +147,30 @@
compadd -UX "$format" -n ''
fi
-if [[ compstate[matcher] -eq compstate[total_matchers] ||
- compstate[nmatches] -ne 0 ]]; then
+# See which tags were or were not used.
- # See which tags were or were not used.
+_used_tags=( "${(@)_tried_tags:#${(j:|:)~${(@)_failed_tags//\[/\\[}//\]/\\]}}" )
+_unused_tags=( "${(@)_offered_tags:#${(j:|:)~${(@)_used_tags//\[/\\[}//\]/\\]}}" )
- _used_tags=( "${(@)_tried_tags:#${(j:|:)~${(@)_failed_tags//\[/\\[}//\]/\\]}}" )
- _unused_tags=( "${(@)_offered_tags:#${(j:|:)~${(@)_used_tags//\[/\\[}//\]/\\]}}" )
+# Now call the post-functions.
- # Now call the post-functions.
-
- for post in "$comppostfuncs[@]"; do
- "$post"
- done
- comppostfuncs=()
-
- _lastcomp=( "${(@kv)compstate}" )
- _lastcomp[completer]="$comp"
- _lastcomp[prefix]="$PREFIX"
- _lastcomp[suffix]="$SUFFIX"
- _lastcomp[iprefix]="$IPREFIX"
- _lastcomp[isuffix]="$ISUFFIX"
- _lastcomp[qiprefix]="$QIPREFIX"
- _lastcomp[qisuffix]="$QISUFFIX"
- _lastcomp[offered_tags]="${(j.:.)_offered_tags}"
- _lastcomp[tried_tags]="${(j.:.)_tried_tags}"
- _lastcomp[failed_tags]="${(j.:.)_failed_tags}"
- _lastcomp[unused_tags]="${(j.:.)_unused_tags}"
- _lastcomp[used_tags]="${(j.:.)_used_tags}"
-fi
+for post in "$comppostfuncs[@]"; do
+ "$post"
+done
+comppostfuncs=()
+
+_lastcomp=( "${(@kv)compstate}" )
+_lastcomp[completer]="$comp"
+_lastcomp[prefix]="$PREFIX"
+_lastcomp[suffix]="$SUFFIX"
+_lastcomp[iprefix]="$IPREFIX"
+_lastcomp[isuffix]="$ISUFFIX"
+_lastcomp[qiprefix]="$QIPREFIX"
+_lastcomp[qisuffix]="$QISUFFIX"
+_lastcomp[offered_tags]="${(j.:.)_offered_tags}"
+_lastcomp[tried_tags]="${(j.:.)_tried_tags}"
+_lastcomp[failed_tags]="${(j.:.)_failed_tags}"
+_lastcomp[unused_tags]="${(j.:.)_unused_tags}"
+_lastcomp[used_tags]="${(j.:.)_used_tags}"
return ret
diff -ru ../z.old/Completion/Core/_match Completion/Core/_match
--- ../z.old/Completion/Core/_match Fri Feb 11 09:23:37 2000
+++ Completion/Core/_match Fri Feb 11 10:32:19 2000
@@ -12,12 +12,10 @@
local tmp opm="$compstate[pattern_match]" ret=0 orig ins
local curcontext="${curcontext/:[^:]#:/:match:}"
-# Do nothing if we don't have a pattern or there are still global
-# match specifications to try.
+# Do nothing if we don't have a pattern.
tmp="${${:-$PREFIX$SUFFIX}#[~=]}"
-[[ "$tmp:q" = "$tmp" ||
- compstate[matcher] -ne compstate[total_matchers] ]] && return 1
+[[ "$tmp:q" = "$tmp" ]] && return 1
zstyle -s ":completion:${curcontext}:" original orig
zstyle -b ":completion:${curcontext}:" insert-unambiguous ins
@@ -25,11 +23,9 @@
# Try completion without inserting a `*'?
if [[ -n "$orig" ]]; then
- compstate[matcher]=-1
compstate[pattern_match]='-'
_complete && ret=1
compstate[pattern_match]="$opm"
- compstate[matcher]="$compstate[total_matchers]"
if (( ret )); then
[[ "$ins" = yes &&
@@ -43,11 +39,9 @@
[[ "$orig" = only ]] && return 1
-compstate[matcher]=-1
compstate[pattern_match]='*'
_complete && ret=1
compstate[pattern_match]="$opm"
-compstate[matcher]="$compstate[total_matchers]"
[[ ret -eq 1 && "$ins" = yes &&
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] &&
diff -ru ../z.old/Doc/Zsh/compctl.yo Doc/Zsh/compctl.yo
--- ../z.old/Doc/Zsh/compctl.yo Fri Feb 11 09:23:15 2000
+++ Doc/Zsh/compctl.yo Fri Feb 11 10:54:14 2000
@@ -131,10 +131,19 @@
options specified by the tt(-D) flag.
The form with tt(-M) as the first and only option defines global
-matching specifications, as described in
+matching specifications (see
ifzman(zshcompwid)\
ifnzman(noderef(Matching Control))\
-.
+). The match specifications given will be used for every completion
+attempt (only when using tt(compctl), not with the new completion
+system) and are tried in the order in which they are defined until one
+generates at least one match. E.g.:
+
+example(compctl -M '' 'm:{a-zA-Z}={A-Za-z}')
+
+This will first try completion without any global match specifications
+(the empty string) and, if that generates no matches, will try case
+insensitive completion.
texinode(Option Flags)(Alternative Completion)(Command Flags)(Programmable Completion Using compctl)
sect(Option Flags)
diff -ru ../z.old/Doc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- ../z.old/Doc/Zsh/compsys.yo Fri Feb 11 09:23:16 2000
+++ Doc/Zsh/compsys.yo Fri Feb 11 10:46:03 2000
@@ -12,17 +12,6 @@
completion behaviour and which may be bound to keystrokes, are referred to
as `widgets'.
-Note that with the function-based completions described here, it
-is also possible to use the
-tt(compmatchers) special array to specify
-global matching control, such as case-insensitivity (`tt(abc)' will complete
-to a string beginning `tt(ABC)'), or wildcard behaviour on
-certain anchors (`tt(a-d)' will complete to abc-def as if there were a
-`tt(*)' after the `a'). See
-ifzman(the section `Matching Control' in zmanref(zshcompwid))\
-ifnzman(noderef(Matching Control))
-for further details.
-
Note also, that it is possible to use old completion definitions using
the tt(compctl) builtin command together with the functions for the
new completion system. To enable this, the tt(_default) function from
@@ -1594,7 +1583,8 @@
ifzman(the section `Matching Control' in zmanref(zshcompwid))\
ifnzman(noderef(Matching Control))\
) that is to be used by all following completers. This is comparable
-to the tt(compmatchers) special array, but gives finer control. The match
+to the global match specifications that can be defined for the
+tt(compctl) builtin, but gives much better control. The match
specification to use is looked up using the tt(matcher) style. For
this, the completer field of the context name will contain the string
`tt(matcher-)var(n)', where `var(n)' is the number of the call to
diff -ru ../z.old/Doc/Zsh/compwid.yo Doc/Zsh/compwid.yo
--- ../z.old/Doc/Zsh/compwid.yo Fri Feb 11 09:23:16 2000
+++ Doc/Zsh/compwid.yo Fri Feb 11 10:57:30 2000
@@ -207,21 +207,6 @@
put into the alternate set using the tt(-a) option of the tt(compadd)
builtin command (see below) are not counted.
)
-item(tt(matcher))(
-When completion is performed with a global match specification as defined
-by
-
-indent(tt(compmatchers=)tt(LPAR()) var(spec1 ... specN ...) tt(RPAR()))
-
-this gives the number of the specification string currently in use.
-In this case, matching is performed with each specification in turn.
-)
-item(tt(matcher_string))(
-The global match specification string var(specN) currently used.
-)
-item(tt(total_matchers))(
-The total number of global match specifications.
-)
item(tt(restore))(
This is set to tt(auto) before a function is entered, which forces the
special parameters mentioned above (tt(words), tt(CURRENT), tt(PREFIX),
@@ -741,7 +726,7 @@
texinode(Matching Control)(Examples)(Condition Codes)(Completion Widgets)
sect(Matching Control)
-It is possible by use of the tt(compmatchers) special array and the
+It is possible by use of the
tt(-M) option of the tt(compadd) 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
@@ -842,17 +827,16 @@
already been typed on the command line (in particular the prefix
tt(no)) will not be deleted.
-The second example makes completion case insensitive. By setting the
-tt(compmatchers) array this applies to every
-completion. This is just the same as in the option example, except
-here we wish to retain the characters in the list of completions:
+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:
-example(compmatchers=( 'm:{a-z}={A-Z}' ) )
+example(compadd -M 'm:{a-z}={A-Z}' ... )
This makes lowercase letters match their uppercase counterparts.
To make uppercase letters match the lowercase forms as well:
-example(compmatchers=( 'm:{a-zA-Z}={A-Za-z}' ) )
+example(compadd -M 'm:{a-zA-Z}={A-Za-z}' ... )
A nice example for the use of tt(*) patterns is partial word
completion. Sometimes you would like to make strings like tt(c.s.u)
@@ -889,37 +873,21 @@
More generally, the specification
-example(compmatchers=( 'r:|[.,_-]=* r:|=*' ) )
+example(compadd -M 'r:|[.,_-]=* r:|=*' ... )
allows one to complete words with abbreviations before any of the
-characters in the square brackets in any completion. For example, to
+characters in the square brackets. For example, to
complete tt(veryverylongfile.c) rather than tt(veryverylongheader.h)
with the above in effect, you can just type tt(very.c) before attempting
completion.
-The tt(compmatchers) array that defines global matching can actually
-contain any number of specification strings, unlike the case where the
-tt(-M) option is used with the tt(compadd) builtin command. In this case, when
-completion is attempted for any command, the code will try the
-specifications in order until one matches. This allows one to define
-simple and fast matches to be used first, more powerful matchers as a
-second choice, and so on.
-
-For example, one can make the code match trial completions that contain
-the string on the command line as a substring, not just at the
-beginning. Since this might produce more matches than we want,
-we arrange for it to be tried only if the matchers described above don't
-produce any matches:
-
-example(compmatchers=( 'r:|[.,_-]=* r:|=*' 'l:|=* r:|=*' ) )
-
-Here, if the string on the command line is tt(foo.bar), the completion
-code first tries matching tt(foo)var(anything)tt(.bar)var(anything), as
-with the previous example. If that fails, the two descriptions in the
-second string say that the blanks at the beginning
-and end of the string on the command line can match any set of
-characters at the beginning or end of the trial completion, so it will
-look for var(anything)tt(foo.bar)var(anything).
+When using the completion system (see
+ifzman(zmanref(zshcompsys))\
+ifnzman(noderef(Completion System))\
+), users can define match specifications that are to be used for
+specific contexts by using the tt(matcher) style and match
+specifications that are to be used everywhere can be defined by the
+use of the tt(_matcher) completer.
texinode(Examples)()(Matching Control)(Completion Widgets)
sect(Examples)
diff -ru ../z.old/Src/Zle/comp.h Src/Zle/comp.h
--- ../z.old/Src/Zle/comp.h Fri Feb 11 09:23:07 2000
+++ Src/Zle/comp.h Fri Feb 11 10:23:50 2000
@@ -309,70 +309,62 @@
#define CPN_NMATCHES 0
#define CP_NMATCHES (1 << CPN_NMATCHES)
-#define CPN_MATCHER 1
-#define CP_MATCHER (1 << CPN_MATCHER)
-#define CPN_MATCHERSTR 2
-#define CP_MATCHERSTR (1 << CPN_MATCHERSTR)
-#define CPN_MATCHERTOT 3
-#define CP_MATCHERTOT (1 << CPN_MATCHERTOT)
-#define CPN_CONTEXT 4
+#define CPN_CONTEXT 1
#define CP_CONTEXT (1 << CPN_CONTEXT)
-#define CPN_PARAMETER 5
+#define CPN_PARAMETER 2
#define CP_PARAMETER (1 << CPN_PARAMETER)
-#define CPN_REDIRECT 6
+#define CPN_REDIRECT 3
#define CP_REDIRECT (1 << CPN_REDIRECT)
-#define CPN_QUOTE 7
+#define CPN_QUOTE 4
#define CP_QUOTE (1 << CPN_QUOTE)
-#define CPN_QUOTING 8
+#define CPN_QUOTING 5
#define CP_QUOTING (1 << CPN_QUOTING)
-#define CPN_RESTORE 9
+#define CPN_RESTORE 6
#define CP_RESTORE (1 << CPN_RESTORE)
-#define CPN_LIST 10
+#define CPN_LIST 7
#define CP_LIST (1 << CPN_LIST)
-#define CPN_INSERT 11
+#define CPN_INSERT 8
#define CP_INSERT (1 << CPN_INSERT)
-#define CPN_EXACT 12
+#define CPN_EXACT 9
#define CP_EXACT (1 << CPN_EXACT)
-#define CPN_EXACTSTR 13
+#define CPN_EXACTSTR 10
#define CP_EXACTSTR (1 << CPN_EXACTSTR)
-#define CPN_PATMATCH 14
+#define CPN_PATMATCH 11
#define CP_PATMATCH (1 << CPN_PATMATCH)
-#define CPN_PATINSERT 15
+#define CPN_PATINSERT 12
#define CP_PATINSERT (1 << CPN_PATINSERT)
-#define CPN_UNAMBIG 16
+#define CPN_UNAMBIG 13
#define CP_UNAMBIG (1 << CPN_UNAMBIG)
-#define CPN_UNAMBIGC 17
+#define CPN_UNAMBIGC 14
#define CP_UNAMBIGC (1 << CPN_UNAMBIGC)
-#define CPN_LISTMAX 18
+#define CPN_LISTMAX 15
#define CP_LISTMAX (1 << CPN_LISTMAX)
-#define CPN_LASTPROMPT 19
+#define CPN_LASTPROMPT 16
#define CP_LASTPROMPT (1 << CPN_LASTPROMPT)
-#define CPN_TOEND 20
+#define CPN_TOEND 17
#define CP_TOEND (1 << CPN_TOEND)
-#define CPN_OLDLIST 21
+#define CPN_OLDLIST 18
#define CP_OLDLIST (1 << CPN_OLDLIST)
-#define CPN_OLDINS 22
+#define CPN_OLDINS 19
#define CP_OLDINS (1 << CPN_OLDINS)
-#define CPN_VARED 23
+#define CPN_VARED 20
#define CP_VARED (1 << CPN_VARED)
-#define CPN_ANMATCHES 24
+#define CPN_ANMATCHES 21
#define CP_ANMATCHES (1 << CPN_ANMATCHES)
-#define CPN_LISTLINES 25
+#define CPN_LISTLINES 22
#define CP_LISTLINES (1 << CPN_LISTLINES)
-#define CPN_QUOTES 26
+#define CPN_QUOTES 23
#define CP_QUOTES (1 << CPN_QUOTES)
-#define CP_KEYPARAMS 27
-#define CP_ALLKEYS ((unsigned int) 0x7ffffff)
+#define CP_KEYPARAMS 24
+#define CP_ALLKEYS ((unsigned int) 0xffffff)
/* Hooks. */
#define INSERTMATCHHOOK (comphooks + 0)
#define MENUSTARTHOOK (comphooks + 1)
#define COMPCTLMAKEHOOK (comphooks + 2)
-#define COMPCTLBEFOREHOOK (comphooks + 3)
-#define COMPCTLAFTERHOOK (comphooks + 4)
-#define COMPLISTMATCHESHOOK (comphooks + 5)
+#define COMPLISTMATCHESHOOK (comphooks + 3)
/* compctl hook data struct */
diff -ru ../z.old/Src/Zle/compcore.c Src/Zle/compcore.c
--- ../z.old/Src/Zle/compcore.c Fri Feb 11 09:23:07 2000
+++ Src/Zle/compcore.c Fri Feb 11 10:39:46 2000
@@ -808,59 +808,21 @@
static int
makecomplist(char *s, int incmd, int lst)
{
- struct cmlist ms;
- Cmlist m;
- char *p, *os = s;
- int onm = nmatches, osi = movefd(0);
+ char *p;
/* Inside $... ? */
if (compfunc && (p = check_param(s, 0, 0)))
- os = s = p;
-
- /* We build a copy of the list of matchers to use to make sure that this
- * works even if a shell function called from the completion code changes
- * the global matchers. */
-
- if ((m = cmatcher)) {
- Cmlist mm, *mp = &mm;
- int n;
-
- for (n = 0; m; m = m->next, n++) {
- *mp = (Cmlist) zhalloc(sizeof(struct cmlist));
- (*mp)->matcher = m->matcher;
- (*mp)->next = NULL;
- (*mp)->str = dupstring(m->str);
- mp = &((*mp)->next);
- addlinknode(matchers, m->matcher);
- if (m->matcher)
- m->matcher->refc++;
- }
- m = mm;
- compmatcher = 1;
- compmatchertot = n;
- } else
- compmatcher = 0;
+ s = p;
linwhat = inwhat;
- /* Walk through the global matchers. */
- for (;;) {
+ if (compfunc) {
+ char *os = s;
+ int onm = nmatches, osi = movefd(0);
+
bmatchers = NULL;
- zsfree(compmatcherstr);
- if (m) {
- ms.next = NULL;
- ms.matcher = m->matcher;
- mstack = &ms;
-
- /* Store the matchers used in the bmatchers list which is used
- * when building new parts for the string to insert into the
- * line. */
- add_bmatchers(m->matcher);
- compmatcherstr = ztrdup(m->str);
- } else {
- mstack = NULL;
- compmatcherstr = ztrdup("");
- }
+ mstack = NULL;
+
ainfo = (Aminfo) hcalloc(sizeof(struct aminfo));
fainfo = (Aminfo) hcalloc(sizeof(struct aminfo));
@@ -877,24 +839,10 @@
begcmgroup("default", 0);
menucmp = menuacc = newmatches = onlyexpl = 0;
- runhookdef(COMPCTLBEFOREHOOK, NULL);
-
s = dupstring(os);
- if (compfunc)
- callcompfunc(s, compfunc);
- else {
- struct ccmakedat dat;
-
- dat.str = s;
- dat.incmd = incmd;
- dat.lst = lst;
- runhookdef(COMPCTLMAKEHOOK, (void *) &dat);
- }
+ callcompfunc(s, compfunc);
endcmgroup(NULL);
- runhookdef(COMPCTLAFTERHOOK,
- (void *) ((amatches && !oldlist) ? 1L : 0L));
-
if (oldlist) {
nmatches = onm;
validlist = 1;
@@ -933,14 +881,18 @@
return 0;
}
- if (!m || !(m = m->next))
- break;
+ redup(osi, 0);
+ return 1;
+ } else {
+ struct ccmakedat dat;
+
+ dat.str = s;
+ dat.incmd = incmd;
+ dat.lst = lst;
+ runhookdef(COMPCTLMAKEHOOK, (void *) &dat);
- errflag = 0;
- compmatcher++;
+ return dat.lst;
}
- redup(osi, 0);
- return 1;
}
/**/
diff -ru ../z.old/Src/Zle/compctl.c Src/Zle/compctl.c
--- ../z.old/Src/Zle/compctl.c Fri Feb 11 09:23:07 2000
+++ Src/Zle/compctl.c Fri Feb 11 10:38:00 2000
@@ -30,6 +30,11 @@
#include "compctl.mdh"
#include "compctl.pro"
+/* Global matcher. */
+
+/**/
+static Cmlist cmatcher;
+
/* Default completion infos */
/**/
@@ -275,6 +280,53 @@
return 0;
}
+/* Copy a list of completion matchers. */
+
+/**/
+static Cmlist
+cpcmlist(Cmlist l)
+{
+ Cmlist r = NULL, *p = &r, n;
+
+ while (l) {
+ *p = n = (Cmlist) zalloc(sizeof(struct cmlist));
+ n->next = NULL;
+ n->matcher = cpcmatcher(l->matcher);
+ n->str = ztrdup(l->str);
+
+ p = &(n->next);
+ l = l->next;
+ }
+ return r;
+}
+
+/* Set the global match specs. */
+
+/**/
+static int
+set_gmatcher(char *name, char **argv)
+{
+ Cmlist l = NULL, *q = &l, n;
+ Cmatcher m;
+
+ while (*argv) {
+ if ((m = parse_cmatcher(name, *argv)) == pcm_err)
+ return 1;
+ *q = n = (Cmlist) zhalloc(sizeof(struct cmlist));
+ n->next = NULL;
+ n->matcher = m;
+ n->str = *argv++;
+
+ q = &(n->next);
+ }
+ freecmlist(cmatcher);
+ PERMALLOC {
+ cmatcher = cpcmlist(l);
+ } LASTALLOC;
+
+ return 1;
+}
+
/* Try to get the global matcher from the given compctl. */
/**/
@@ -1709,39 +1761,134 @@
static int
ccmakehookfn(Hookdef dummy, struct ccmakedat *dat)
{
- makecomplistglobal(dat->str, dat->incmd, dat->lst, 0);
+ char *s = dat->str;
+ int incmd = dat->incmd, lst = dat->lst;
+ struct cmlist ms;
+ Cmlist m;
+ char *os = s;
+ int onm = nmatches, osi = movefd(0);
+ LinkNode n;
- return 0;
-}
+ /* We build a copy of the list of matchers to use to make sure that this
+ * works even if a shell function called from the completion code changes
+ * the global matchers. */
+
+ if ((m = cmatcher)) {
+ Cmlist mm, *mp = &mm;
+ int n;
+
+ for (n = 0; m; m = m->next, n++) {
+ *mp = (Cmlist) zhalloc(sizeof(struct cmlist));
+ (*mp)->matcher = m->matcher;
+ (*mp)->next = NULL;
+ (*mp)->str = dupstring(m->str);
+ mp = &((*mp)->next);
+ addlinknode(matchers, m->matcher);
+ if (m->matcher)
+ m->matcher->refc++;
+ }
+ m = mm;
+ }
+
+ /* Walk through the global matchers. */
+ for (;;) {
+ bmatchers = NULL;
+ if (m) {
+ ms.next = NULL;
+ ms.matcher = m->matcher;
+ mstack = &ms;
+
+ /* Store the matchers used in the bmatchers list which is used
+ * when building new parts for the string to insert into the
+ * line. */
+ add_bmatchers(m->matcher);
+ } else
+ mstack = NULL;
-static int
-ccbeforehookfn(Hookdef dummy, void *zdup)
-{
- ccused = newlinklist();
- ccstack = newlinklist();
+ ainfo = (Aminfo) hcalloc(sizeof(struct aminfo));
+ fainfo = (Aminfo) hcalloc(sizeof(struct aminfo));
- return 0;
-}
+ freecl = NULL;
-static int
-ccafterhookfn(Hookdef dummy, void *zdup)
-{
- LinkNode n;
+ if (!validlist)
+ lastambig = 0;
+ amatches = NULL;
+ mnum = 0;
+ unambig_mnum = -1;
+ isuf = NULL;
+ insmnum = insgnum = 1;
+ insgroup = oldlist = oldins = 0;
+ begcmgroup("default", 0);
+ menucmp = menuacc = newmatches = onlyexpl = 0;
- if (zdup) {
- if (lastccused)
- freelinklist(lastccused, (FreeFunc) freecompctl);
+ ccused = newlinklist();
+ ccstack = newlinklist();
- PERMALLOC {
- lastccused = newlinklist();
+ s = dupstring(os);
+ makecomplistglobal(s, incmd, lst, 0);
+ endcmgroup(NULL);
+
+ if (amatches && !oldlist) {
+ if (lastccused)
+ freelinklist(lastccused, (FreeFunc) freecompctl);
+
+ PERMALLOC {
+ lastccused = newlinklist();
+ for (n = firstnode(ccused); n; incnode(n))
+ addlinknode(lastccused, getdata(n));
+ } LASTALLOC;
+ } else
for (n = firstnode(ccused); n; incnode(n))
- addlinknode(lastccused, getdata(n));
+ if (((Compctl) getdata(n)) != &cc_dummy)
+ freecompctl((Compctl) getdata(n));
+
+ if (oldlist) {
+ nmatches = onm;
+ validlist = 1;
+ amatches = lastmatches;
+ lmatches = lastlmatches;
+ if (pmatches) {
+ freematches(pmatches);
+ pmatches = NULL;
+ hasperm = 0;
+ }
+ redup(osi, 0);
+
+ dat->lst = 0;
+ return 0;
+ }
+ PERMALLOC {
+ if (lastmatches) {
+ freematches(lastmatches);
+ lastmatches = NULL;
+ }
+ permmatches(1);
+ amatches = pmatches;
+ lastpermmnum = permmnum;
+ lastpermgnum = permgnum;
} LASTALLOC;
- } else
- for (n = firstnode(ccused); n; incnode(n))
- if (((Compctl) getdata(n)) != &cc_dummy)
- freecompctl((Compctl) getdata(n));
+ lastmatches = pmatches;
+ lastlmatches = lmatches;
+ pmatches = NULL;
+ hasperm = 0;
+ hasoldlist = 1;
+
+ if (nmatches && !errflag) {
+ validlist = 1;
+
+ redup(osi, 0);
+
+ dat->lst = 0;
+ return 0;
+ }
+ if (!m || !(m = m->next))
+ break;
+
+ errflag = 0;
+ }
+ redup(osi, 0);
+ dat->lst = 1;
return 0;
}
@@ -3755,8 +3902,6 @@
boot_(Module m)
{
addhookfunc("compctl_make", (Hookfn) ccmakehookfn);
- addhookfunc("compctl_before", (Hookfn) ccbeforehookfn);
- addhookfunc("compctl_after", (Hookfn) ccafterhookfn);
return (addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) != 1);
}
@@ -3765,8 +3910,6 @@
cleanup_(Module m)
{
deletehookfunc("compctl_make", (Hookfn) ccmakehookfn);
- deletehookfunc("compctl_before", (Hookfn) ccbeforehookfn);
- deletehookfunc("compctl_after", (Hookfn) ccafterhookfn);
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
return 0;
}
diff -ru ../z.old/Src/Zle/complete.c Src/Zle/complete.c
--- ../z.old/Src/Zle/complete.c Fri Feb 11 09:23:08 2000
+++ Src/Zle/complete.c Fri Feb 11 10:39:34 2000
@@ -30,19 +30,12 @@
#include "complete.mdh"
#include "complete.pro"
-/* Global matcher. */
-
-/**/
-mod_export Cmlist cmatcher;
-
/* global variables for shell parameters in new style completion */
/**/
mod_export zlong compcurrent;
/**/
-zlong compmatcher,
- compmatchertot,
- complistmax,
+zlong complistmax,
complistlines;
/**/
@@ -59,7 +52,6 @@
*complastprompt;
/**/
char *compiprefix,
- *compmatcherstr,
*compcontext,
*compparameter,
*compredirect,
@@ -131,26 +123,6 @@
}
}
-/* Copy a list of completion matchers. */
-
-/**/
-static Cmlist
-cpcmlist(Cmlist l)
-{
- Cmlist r = NULL, *p = &r, n;
-
- while (l) {
- *p = n = (Cmlist) zalloc(sizeof(struct cmlist));
- n->next = NULL;
- n->matcher = cpcmatcher(l->matcher);
- n->str = ztrdup(l->str);
-
- p = &(n->next);
- l = l->next;
- }
- return r;
-}
-
/* Copy a completion matcher list. */
/**/
@@ -201,33 +173,6 @@
return r;
}
-/* Set the global match specs. */
-
-/**/
-mod_export int
-set_gmatcher(char *name, char **argv)
-{
- Cmlist l = NULL, *q = &l, n;
- Cmatcher m;
-
- while (*argv) {
- if ((m = parse_cmatcher(name, *argv)) == pcm_err)
- return 1;
- *q = n = (Cmlist) zhalloc(sizeof(struct cmlist));
- n->next = NULL;
- n->matcher = m;
- n->str = *argv++;
-
- q = &(n->next);
- }
- freecmlist(cmatcher);
- PERMALLOC {
- cmatcher = cpcmlist(l);
- } LASTALLOC;
-
- return 1;
-}
-
/* Parse a string for matcher control, containing multiple matchers. */
/**/
@@ -943,9 +888,6 @@
static struct compparam compkparams[] = {
{ "nmatches", PM_INTEGER | PM_READONLY, NULL, NULL, VAL(get_nmatches) },
- { "matcher", PM_INTEGER, VAL(compmatcher), NULL, NULL },
- { "matcher_string", PM_SCALAR, VAL(compmatcherstr), NULL, NULL },
- { "total_matchers", PM_INTEGER, VAL(compmatchertot), NULL, NULL },
{ "context", PM_SCALAR, VAL(compcontext), NULL, NULL },
{ "parameter", PM_SCALAR, VAL(compparameter), NULL, NULL },
{ "redirect", PM_SCALAR, VAL(compredirect), NULL, NULL },
@@ -1322,42 +1264,6 @@
(id ? cond_str(a, 1, 1) : NULL), 0);
}
-/**/
-static void
-cmsetfn(Param pm, char **v)
-{
- set_gmatcher(pm->nam, v);
-}
-
-/**/
-static char **
-cmgetfn(Param pm)
-{
- int num;
- Cmlist p;
- char **ret, **q;
-
- for (num = 0, p = cmatcher; p; p = p->next, num++);
-
- ret = (char **) zhalloc((num + 1) * sizeof(char *));
-
- for (q = ret, p = cmatcher; p; p = p->next, q++)
- *q = dupstring(p->str);
- *q = NULL;
-
- return ret;
-}
-
-/**/
-static void
-cmunsetfn(Param pm, int exp)
-{
- char *dummy[1];
-
- dummy[0] = NULL;
- set_gmatcher(pm->nam, dummy);
-}
-
static struct builtin bintab[] = {
BUILTIN("compadd", 0, bin_compadd, 0, -1, 0, NULL, NULL),
BUILTIN("compset", 0, bin_compset, 1, 3, 0, NULL, NULL),
@@ -1374,10 +1280,6 @@
WRAPDEF(comp_wrapper),
};
-static struct paramdef patab[] = {
- PARAMDEF("compmatchers", PM_ARRAY|PM_SPECIAL, NULL, cmsetfn, cmgetfn, cmunsetfn)
-};
-
/* The order of the entries in this table has to match the *HOOK
* macros in comp.h */
@@ -1386,8 +1288,6 @@
HOOKDEF("insert_match", NULL, HOOKF_ALL),
HOOKDEF("menu_start", NULL, HOOKF_ALL),
HOOKDEF("compctl_make", NULL, 0),
- HOOKDEF("compctl_before", NULL, 0),
- HOOKDEF("compctl_after", NULL, 0),
HOOKDEF("comp_list_matches", ilistmatches, 0),
};
@@ -1400,7 +1300,7 @@
comprpms = compkpms = NULL;
compwords = NULL;
compprefix = compsuffix = compiprefix = compisuffix =
- compqiprefix = compqisuffix = compmatcherstr =
+ compqiprefix = compqisuffix =
compcontext = compparameter = compredirect = compquote =
compquoting = comprestore = complist = compinsert =
compexact = compexactstr = comppatmatch = comppatinsert =
@@ -1426,7 +1326,6 @@
addhookdefs(m->nam, comphooks, sizeof(comphooks)/sizeof(*comphooks));
if (!(addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) |
addconddefs(m->nam, cotab, sizeof(cotab)/sizeof(*cotab)) |
- addparamdefs(m->nam, patab, sizeof(patab)/sizeof(*patab)) |
!addwrapper(m, wrapper)))
return 1;
return 0;
@@ -1446,7 +1345,6 @@
deletehookdefs(m->nam, comphooks, sizeof(comphooks)/sizeof(*comphooks));
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
deleteconddefs(m->nam, cotab, sizeof(cotab)/sizeof(*cotab));
- deleteparamdefs(m->nam, patab, sizeof(patab)/sizeof(*patab));
deletewrapper(m, wrapper);
return 0;
}
@@ -1463,7 +1361,6 @@
zsfree(compisuffix);
zsfree(compqiprefix);
zsfree(compqisuffix);
- zsfree(compmatcherstr);
zsfree(compcontext);
zsfree(compparameter);
zsfree(compredirect);
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: PATCH: yet another completer
2000-02-10 14:03 Sven Wischnowsky
2000-02-10 15:58 ` Bart Schaefer
@ 2000-02-11 11:40 ` Andrej Borsenkow
1 sibling, 0 replies; 4+ messages in thread
From: Andrej Borsenkow @ 2000-02-11 11:40 UTC (permalink / raw)
To: Sven Wischnowsky, zsh-workers
> +
> +example(zstyle ':completion:::::' completer _matcher _complete
> _matcher _complete
> +zstyle ':completion:*:matcher-1:::' matcher 'm:{a-z-}={A-Z_}'
> +zstyle ':completion:*:matcher-2:::' matcher 'm:{a-z-}={A-Z_}'
> 'r:|[-_./]=* r:|=*')
> +
Question(s) and comment(s).
- Is it posssible to set match specs on per-command/per-argument basis? In
this case, it is better to include such example. Current one implies, that
you can only set globally valid match specs.
- The most common case so far is file name completion. Can I set default
match specs for _path_files only? That is, default match specs that affect
only file names but not anything else - non-file arguments, options etc
- This is nice as long as you have just a single completer ... but I have
e.g.
zstyle ':completion:*' completer _oldlist _complete _match
If I want to use two different matchers, should I now write
zstyle ':completion:*' completer _matcher _oldlist _complete _match _matcher
_oldlist _complete _match
Looks at least weird.
- This has the same pitfall as global match specs before - it is
position-dependent. Imagine, that I have to matchers and want to add one
more in between. Now, I have to change matcher-2 into matcher-3 in all
styles!
I'd prefer something like "match specs list" - list of match specs that
would be tried until any matches are found. Probably, on per-completer
basis. Or is it intended to be used (useful) only with _complete? Even then
the
zstyle ':completion:*:complete:::' match_specs_list 'm:{a-z-}={A-Z_}'
'r:|[-_./]=* r:|=*'
is much cleaner than
zstyle ':completion:*' completer _matcher _complete _matcher _complete
_match
zstyle ':completion:*:matcher-1:::' matcher 'm:{a-z-}={A-Z_}'
zstyle ':completion:*:matcher-2:::' matcher 'm:{a-z-}={A-Z_}' 'r:|[-_./]=*
r:|=*')
/andrej
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: yet another completer
2000-02-10 14:03 Sven Wischnowsky
@ 2000-02-10 15:58 ` Bart Schaefer
2000-02-11 11:40 ` Andrej Borsenkow
1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2000-02-10 15:58 UTC (permalink / raw)
To: zsh-workers
On Feb 10, 3:03pm, Sven Wischnowsky wrote:
} Subject: PATCH: yet another completer
}
} This almost makes me think that we could actually remove $compmatchers
} and leave only the compctl-with-only-`-M' thing for those who still
} use compctl.
I'd be in favor of this, since I always found compmatchers needlessly
confusing.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* PATCH: yet another completer
@ 2000-02-10 14:03 Sven Wischnowsky
2000-02-10 15:58 ` Bart Schaefer
2000-02-11 11:40 ` Andrej Borsenkow
0 siblings, 2 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2000-02-10 14:03 UTC (permalink / raw)
To: zsh-workers
I have been thinking for quite some time how we could get rid of
$compmatchers... some changes from not-so-long-ago finally gave me
this idea (it's the thing that compadd now uses all its -M options, at
least after this patch, there was a small thinko).
The _matcher completer (sorry for the name, it's similar to _match to
make me like it either, but it's named after the `matcher' style
(which already existed)) can be used to set up match specifications
that are to be used in all following completers. And using some zstyle
magic, this allows much finer control over when to use which match
specs than $compmatchers does.
And with this patch, $compmatchers is probably not that useful
anymore. Only for compctl and for custom made completion widgets, that
is (although those could use their own -M options so maybe it isn't
that useful there either; and if they use utility functions from the
completion system, they could probably be made to use _matcher, too).
This almost makes me think that we could actually remove $compmatchers
and leave only the compctl-with-only-`-M' thing for those who still
use compctl. That would also allow us to move some more code from the
complete module into the compctl module, although not much and the
code doesn't make things much slower as long as $compmatchers is not
set (or set to only one string). So, I haven't changed anything there
yet.
The hunks in _path_files only remove the mspec local -- something I
had voellig verpennt before. And the hunks in _prefix make it use
`prefix-<num>' in the completer field of the context name, too.
Bye
Sven
diff -ru ../z.old/Completion/Core/_approximate Completion/Core/_approximate
--- ../z.old/Completion/Core/_approximate Thu Feb 10 12:55:08 2000
+++ Completion/Core/_approximate Thu Feb 10 14:28:53 2000
@@ -6,7 +6,7 @@
# or get the corrected prefix.
local _comp_correct _correct_expl comax cfgacc
-local curcontext="${curcontext}" oldcontext
+local curcontext="${curcontext}" oldcontext opm="$compstate[pattern_match]"
# Only if all global matchers have been tried.
@@ -100,6 +100,7 @@
fi
compstate[matcher]="$compstate[total_matchers]"
unfunction compadd
+ compstate[pattern_match]="$opm"
return 0
fi
@@ -110,5 +111,6 @@
compstate[matcher]="$compstate[total_matchers]"
unfunction compadd
+compstate[pattern_match]="$opm"
return 1
diff -ru ../z.old/Completion/Core/_description Completion/Core/_description
--- ../z.old/Completion/Core/_description Thu Feb 10 12:55:09 2000
+++ Completion/Core/_description Thu Feb 10 13:31:02 2000
@@ -27,6 +27,8 @@
[[ -z "$gname" ]] && gname="$1"
zstyle -s ":completion:${curcontext}:$1" matcher match &&
opts=($opts -M "${(q)match}")
+[[ -n "$_comp_matcher" ]] && opts=($opts -M "${(q)_comp_matcher}")
+
if zstyle -a ":completion:${curcontext}:$1" ignored-patterns _comp_ignore; then
opts=( $opts -F _comp_ignore)
else
diff -ru ../z.old/Completion/Core/_main_complete Completion/Core/_main_complete
--- ../z.old/Completion/Core/_main_complete Thu Feb 10 12:55:09 2000
+++ Completion/Core/_main_complete Thu Feb 10 14:27:34 2000
@@ -20,7 +20,7 @@
unsetopt markdirs globsubst shwordsplit nounset ksharrays
local comp post ret=1 _compskip _prio_num=1 format _comp_ignore \
- _completers _completers_left \
+ _completers _completers_left _comp_matcher \
context state line opt_args val_args curcontext="$curcontext" \
_last_nmatches=-1 _last_menu_style _def_menu_style _menu_style sel \
_saved_exact="${compstate[exact]}" \
diff -ru ../z.old/Completion/Core/_matcher Completion/Core/_matcher
--- ../z.old/Completion/Core/_matcher Thu Feb 10 13:47:29 2000
+++ Completion/Core/_matcher Thu Feb 10 14:13:43 2000
@@ -0,0 +1,5 @@
+#autoload
+
+zstyle -s ":completion:${curcontext%%:*}:matcher-${(M)#${(@)_completers[1,-$#_completers_left]}:#_matcher}:${curcontext#[^:]#:[^:]#:}:" matcher _comp_matcher || _comp_matcher=''
+
+return 1
diff -ru ../z.old/Completion/Core/_path_files Completion/Core/_path_files
--- ../z.old/Completion/Core/_path_files Thu Feb 10 12:55:10 2000
+++ Completion/Core/_path_files Thu Feb 10 13:41:25 2000
@@ -6,7 +6,7 @@
local linepath realpath donepath prepath testpath exppath skips skipped
local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
local pats haspats=no ignore pfxsfx rem remt sopt gopt opt
-local nm=$compstate[nmatches] menu mspec matcher mopts atmp sort match
+local nm=$compstate[nmatches] menu matcher mopts atmp sort match
typeset -U prepaths exppaths
@@ -54,8 +54,6 @@
fi
fi
-(( $#matcher )) && mspec="${matcher[2]}"
-
if [[ -z "$_file_pat_checked" ]] &&
zstyle -s ":completion:${curcontext}:files" file-patterns tmp1 &&
[[ -n "$tmp1" ]]; then
@@ -92,7 +90,6 @@
fi
tmp1=$expl[(I)-M*]
if (( tmp1 )); then
- mspec="$mspec $expl[1+tmp1]"
if (( $#matcher )); then
matcher[2]="$matcher[2] $expl[1+tmp1]"
else
@@ -452,30 +449,26 @@
if [[ "$tmp3" = */* ]]; then
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \
-W "$prepath$realpath$testpath" \
- "$pfxsfx[@]" \
- -M "r:|/=* r:|=* $mspec" \
+ "$pfxsfx[@]" -M "r:|/=* r:|=*" \
- "${(@)tmp1%%/*}"
else
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
-W "$prepath$realpath$testpath" \
- "$pfxsfx[@]" \
- -M "r:|/=* r:|=* $mspec" \
+ "$pfxsfx[@]" -M "r:|/=* r:|=*" \
- "$tmp1[@]"
fi
else
if [[ "$tmp3" = */* ]]; then
atmp=( -Qf "$mopts[@]" -p "$linepath$tmp2"
-W "$prepath$realpath$testpath"
- "$pfxsfx[@]" \
- -M "r:|/=* r:|=* $mspec" )
+ "$pfxsfx[@]" -M "r:|/=* r:|=*" )
for i in "$tmp1[@]"; do
compadd "$atmp[@]" -s "/${i#*/}" - "${i%%/*}"
done
else
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
- -W "$prepath$realpath$testpath" \
- "$pfxsfx[@]" \
- -M "r:|/=* r:|=* $mspec" \
+ -W "$prepath$realpath$testpath" \
+ "$pfxsfx[@]" -M "r:|/=* r:|=*" \
- "$tmp1[@]"
fi
fi
@@ -522,11 +515,8 @@
fi
tmp4="$testpath"
compquote tmp4 tmp1
- compadd -Qf "$mopts[@]" -p "$linepath$tmp4" \
- -W "$prepath$realpath$testpath" \
- "$pfxsfx[@]" \
- -M "r:|/=* r:|=* $mspec" \
- - "$tmp1[@]"
+ compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -W "$prepath$realpath$testpath" \
+ "$pfxsfx[@]" -M "r:|/=* r:|=*" - "$tmp1[@]"
fi
done
@@ -542,8 +532,7 @@
if (( $#exppaths )); then
PREFIX="${opre}"
SUFFIX="${osuf}"
- compadd -Q "$mopts[@]" -S '' \
- -M "r:|/=* r:|=* $mspec" -p "$linepath" - "$exppaths[@]"
+ compadd -Q "$mopts[@]" -S '' -M "r:|/=* r:|=*" -p "$linepath" - "$exppaths[@]"
fi
fi
diff -ru ../z.old/Completion/Core/_prefix Completion/Core/_prefix
--- ../z.old/Completion/Core/_prefix Thu Feb 10 12:55:11 2000
+++ Completion/Core/_prefix Thu Feb 10 14:23:35 2000
@@ -4,7 +4,7 @@
[[ -n "$SUFFIX" ]] || return 1
-local curcontext="${curcontext/:[^:]#:/:prefix:}" comp i
+local curcontext="${curcontext/:[^:]#:/:prefix-${(M)#${(@)_completers[1,-$#_completers_left]}:#_prefix}:}" comp i
zstyle -a ":completion:${curcontext}:" completer comp ||
comp=( "${(@)_completers[1,-${#_completers_left}-1][(R)_prefix,-1]}" )
@@ -16,8 +16,14 @@
fi
SUFFIX=''
+local _completers _completer_left
+
+_completers=( "$comp[@]" )
+_completers_left=( "$comp[@]" )
+
for i in "$comp[@]"; do
[[ "$i" != _prefix ]] && "$i" && return 0
+ shift 1 _completers_left
done
return 1
diff -ru ../z.old/Doc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- ../z.old/Doc/Zsh/compsys.yo Thu Feb 10 12:54:49 2000
+++ Doc/Zsh/compsys.yo Thu Feb 10 14:48:48 2000
@@ -1097,6 +1097,11 @@
ifzman(the section `Matching Control' in zmanref(zshcompwid))\
ifnzman(noderef(Matching Control))\
.
+
+This style is also used by the tt(_matcher) completer, see
+ifzman(the section `Control Functions' below)\
+ifnzman(noderef(Control Functions))
+for more information.
)
item(tt(max-errors))(
This is used by the tt(_approximate) and tt(_correct) completer functions
@@ -1583,6 +1588,35 @@
Note that the matcher specifications defined globally or used by the
completion functions will not be used.
)
+findex(_matcher)
+item(tt(_matcher))(
+This completer allows to define a match specification (see
+ifzman(the section `Matching Control' in zmanref(zshcompwid))\
+ifnzman(noderef(Matching Control))\
+) that is to be used by all following completers. This is comparable
+to the tt(compmatchers) special array, but gives finer control. The match
+specification to use is looked up using the tt(matcher) style. For
+this, the completer field of the context name will contain the string
+`tt(matcher-)var(n)', where `var(n)' is the number of the call to
+tt(_matcher). For example:
+
+example(zstyle ':completion:::::' completer _matcher _complete _matcher _complete
+zstyle ':completion:*:matcher-1:::' matcher 'm:{a-z-}={A-Z_}'
+zstyle ':completion:*:matcher-2:::' matcher 'm:{a-z-}={A-Z_}' 'r:|[-_./]=* r:|=*')
+
+Since tt(_matcher) is called as the first completer, the tt(_complete)
+completer called after it will first use the match specification
+`tt(m:{a-z-}={A-Z_})'. If that doesn't generate any matches, the next
+call to tt(_matcher) will make the second call to tt(_complete) use
+the specification `tt(r:|[-_./]=* r:|=*)' in addition to the one
+already used by the first attempt (but note that the specification has
+to be given again).
+
+If the tt(matcher) style is not set for one of the invocations of
+tt(_matcher), this has the same effect as setting it to the empty
+string: it makes the following completion function not use any match
+specifications besides those used by the functions themselves.
+)
findex(_expand)
item(tt(_expand))(
This completer function does not really do completion, but instead
@@ -1639,7 +1673,10 @@
currently used by the whole completion are used -- except, of course,
the tt(_prefix) completer itself. Also, if this completer appears more
than once in the list of completers to use only those completers not
-already tried by the last invocation of tt(_prefix) will be called.
+already tried by the last invocation of tt(_prefix) will be
+called. The completer field used to look up styles contains the string
+`tt(prefix-)var(n)', where `var(n)' is the number of the call to
+tt(_prefix).
For example, consider this global tt(completer) style:
@@ -1653,7 +1690,7 @@
want it to try only normal completion, you need to do:
example(zstyle ':completion:::::' completer _complete ... _prefix
-zstyle ':completion::prefix:::' completer _complete)
+zstyle ':completion::prefix-1:::' completer _complete)
The tt(add-space) style is used, too. If it is set to `true' then
tt(_prefix) will insert a space between the matches generated (if any)
diff -ru ../z.old/Src/Zle/complete.c Src/Zle/complete.c
--- ../z.old/Src/Zle/complete.c Thu Feb 10 12:54:42 2000
+++ Src/Zle/complete.c Thu Feb 10 13:38:35 2000
@@ -595,6 +595,7 @@
mstr = tricat(mstr, " ", m);
else
mstr = ztrdup(m);
+ m = NULL;
}
}
}
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2000-02-11 11:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-11 10:56 PATCH: yet another completer Sven Wischnowsky
-- strict thread matches above, loose matches on Subject: below --
2000-02-10 14:03 Sven Wischnowsky
2000-02-10 15:58 ` Bart Schaefer
2000-02-11 11:40 ` Andrej Borsenkow
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).