1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-04 20:40:57 +02:00

new match spec characters bBeE, match only word/line not both (11977)

This commit is contained in:
Sven Wischnowsky 2000-06-19 10:48:21 +00:00
parent a295e82c1e
commit 083befef2b
9 changed files with 70 additions and 19 deletions

View file

@ -1,5 +1,11 @@
2000-06-19 Sven Wischnowsky <wischnow@zsh.org>
* 11977: Completion/Core/_options, Completion/Core/_set_options,
Completion/Core/_unset_options, Doc/Zsh/compwid.yo,
Src/Zle/comp.h, Src/Zle/complete.c, Src/Zle/compmatch.c,
Test/54compmatch.ztst: new match spec characters bBeE, match only
word/line not both
* 11973: Completion/Builtins/_zstyle, Completion/Core/_description,
Completion/Core/_expand, Doc/Zsh/compsys.yo, Src/Zle/zle_tricky.c:
allow _expand to expand braces; better detection of braces to

View file

@ -5,4 +5,4 @@
local expl
_wanted zsh-options expl 'zsh option' \
compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -k options
compadd "$@" -M 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' -k options

View file

@ -7,4 +7,4 @@
local expl
_wanted zsh-options expl 'set zsh option' \
compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -a _set_options
compadd "$@" -M 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' -a _set_options

View file

@ -7,4 +7,4 @@
local expl
_wanted zsh-options expl 'unset zsh option' \
compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -a _unset_options
compadd "$@" -M 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' -a _unset_options

View file

@ -815,7 +815,9 @@ corresponding to var(tpat) which matches in the trial completion.
xitem(tt(l:)var(lanchor)tt(|)var(lpat)tt(=)var(tpat))
xitem(tt(L:)var(lanchor)tt(|)var(lpat)tt(=)var(tpat))
xitem(tt(l:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))
item(tt(L:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))(
xitem(tt(L:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))
xitem(tt(b:)var(lpat)tt(=)var(tpat))
item(tt(B:)var(lpat)tt(=)var(tpat))(
These letters are for patterns that are anchored by another pattern on
the left side. Matching for var(lpat) and var(tpat) is as for tt(m) and
tt(M), but the pattern var(lpat) matched on the command line must be
@ -828,14 +830,21 @@ If no var(lpat) is given but a var(ranchor) is, this matches the gap
between substrings matched by var(lanchor) and var(ranchor). Unlike
var(lanchor), the var(ranchor) only needs to match the trial
completion string.
The tt(b) and tt(B) forms are similar to tt(l) and tt(L) with an empty
anchor, but need to match only the beginning of the trial completion
or the word on the command line, respectively.
)
xitem(tt(r:)var(lpat)tt(|)var(ranchor)tt(=)var(tpat))
xitem(tt(R:)var(lpat)tt(|)var(ranchor)tt(=)var(tpat))
xitem(tt(r:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))
item(tt(R:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))(
As tt(l) and tt(L), with the difference that the command line and trial
completion patterns are anchored on the right side. Here an empty
var(ranchor) forces the match to the end of the command line string.
xitem(tt(R:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))
xitem(tt(e:)var(lpat)tt(=)var(tpat))
item(tt(E:)var(lpat)tt(=)var(tpat))(
As tt(l), tt(L), tt(b) and tt(B), with the difference that the command
line and trial completion patterns are anchored on the right side.
Here an empty var(ranchor) and the tt(e) and tt(E) forms force the
match to the end of the trial completion or command line string.
)
enditem()
@ -898,6 +907,18 @@ specification characters (tt(L) and tt(M)) guarantees that what has
already been typed on the command line (in particular the prefix
tt(no)) will not be deleted.
Note that the use of tt(L) 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)' would not be
completed to `tt(_NO_foo)', nor would `tt(NONO_f)' be completed to
`tt(NONO_foo)' because of the leading underscore or the second
`tt(NO)' on the line which makes the pattern fail even though they are
otherwise ignored. To fix this, one would use `tt(B:[nN][oO]=)'
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(spec)s.
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:

View file

@ -150,6 +150,7 @@ struct cmatcher {
#define CMF_LINE 1
#define CMF_LEFT 2
#define CMF_RIGHT 4
#define CMF_INTER 8
struct cpattern {
Cpattern next; /* next sub-pattern */

View file

@ -183,13 +183,13 @@ parse_cmatcher(char *name, char *s)
{
Cmatcher ret = NULL, r = NULL, n;
Cpattern line, word, left, right;
int fl, ll, wl, lal, ral, err, both;
int fl, fl2, ll, wl, lal, ral, err, both;
if (!*s)
return NULL;
while (*s) {
lal = ral = both = 0;
lal = ral = both = fl2 = 0;
left = right = NULL;
while (*s && inblank(*s)) s++;
@ -197,10 +197,14 @@ parse_cmatcher(char *name, char *s)
if (!*s) break;
switch (*s) {
case 'b': fl2 = CMF_INTER;
case 'l': fl = CMF_LEFT; break;
case 'e': fl2 = CMF_INTER;
case 'r': fl = CMF_RIGHT; break;
case 'm': fl = 0; break;
case 'B': fl2 = CMF_INTER;
case 'L': fl = CMF_LEFT | CMF_LINE; break;
case 'E': fl2 = CMF_INTER;
case 'R': fl = CMF_RIGHT | CMF_LINE; break;
case 'M': fl = CMF_LINE; break;
default:
@ -220,7 +224,7 @@ parse_cmatcher(char *name, char *s)
zwarnnam(name, "missing patterns", NULL, 0);
return pcm_err;
}
if (fl & CMF_LEFT) {
if ((fl & CMF_LEFT) && !fl2) {
left = parse_pattern(name, &s, &lal, '|', &err);
if (err)
return pcm_err;
@ -236,7 +240,8 @@ parse_cmatcher(char *name, char *s)
} else
left = NULL;
line = parse_pattern(name, &s, &ll, ((fl & CMF_RIGHT) ? '|' : '='),
line = parse_pattern(name, &s, &ll,
(((fl & CMF_RIGHT) && !fl2) ? '|' : '='),
&err);
if (err)
return pcm_err;
@ -246,10 +251,10 @@ parse_cmatcher(char *name, char *s)
line = NULL;
ll = 0;
}
if ((fl & CMF_RIGHT) && (!*s || !*++s)) {
if ((fl & CMF_RIGHT) && !fl2 && (!*s || !*++s)) {
if (name)
zwarnnam(name, "missing right anchor", NULL, 0);
} else if (!(fl & CMF_RIGHT)) {
} else if (!(fl & CMF_RIGHT) || fl2) {
if (!*s) {
if (name)
zwarnnam(name, "missing word pattern", NULL, 0);
@ -257,7 +262,7 @@ parse_cmatcher(char *name, char *s)
}
s++;
}
if (fl & CMF_RIGHT) {
if ((fl & CMF_RIGHT) && !fl2) {
if (*s == '|') {
left = line;
lal = ll;
@ -304,7 +309,7 @@ parse_cmatcher(char *name, char *s)
n = (Cmatcher) hcalloc(sizeof(*ret));
n->next = NULL;
n->flags = fl;
n->flags = fl | fl2;
n->line = line;
n->llen = ll;
n->word = word;

View file

@ -565,7 +565,9 @@ match_str(char *l, char *w, Brinfo *bpp, int bc, int *rwlp,
NULL, NULL)) ||
!match_parts(l + aoff, w + aoff, alen, part))))
continue;
} else if (!both || il || iw)
} else if (!both || ((mp->flags & CMF_INTER) ?
((mp->flags & CMF_LINE) ? iw : il) :
(il || iw)))
continue;
/* Fine, now we call ourselves recursively to find the
@ -734,7 +736,9 @@ match_str(char *l, char *w, Brinfo *bpp, int bc, int *rwlp,
tw - mp->lalen - mp->ralen,
NULL, NULL));
else
t = (!sfx && !il && !iw);
t = (!sfx && !((mp->flags & CMF_INTER) ?
((mp->flags & CMF_LINE) ? iw : il) :
(il || iw)));
}
if (mp->flags & CMF_RIGHT) {
/* Try to match the right anchor, if any. */
@ -753,7 +757,9 @@ match_str(char *l, char *w, Brinfo *bpp, int bc, int *rwlp,
mp->ralen - mp->lalen,
NULL, NULL));
else
t = (sfx && !il && !iw);
t = (sfx && !((mp->flags & CMF_INTER) ?
((mp->flags & CMF_LINE) ? iw : il) :
(il || iw)));
}
/* Now try to match the line and word patterns. */
if (!t ||

View file

@ -252,6 +252,18 @@
>NO:{___list_rowsfirst}
>NO:{___list_types}
>line: {tst ___list_beep__ }{}
>COMPADD:{}
test_code 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' example1_list
comptest $'tst __no_listbe\t'
0:Documentation example for options, input "__no_listbe"
>line: {tst __no_listbeep }{}
>COMPADD:{}
test_code 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' example1_list
comptest $'tst nonono_listbe\t'
0:Documentation example for options, input "nonono_listbe"
>line: {tst nonono_listbeep }{}
>COMPADD:{}
lower_insensitive_M="M:{a-z}={A-Z}"