Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: _file_systems & Re: zstyle for _arguments feature request
- X-seq: zsh-workers 16465
- From: Sven Wischnowsky <wischnow@xxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: PATCH: _file_systems & Re: zstyle for _arguments feature request
- Date: Fri, 18 Jan 2002 09:47:25 +0100
- In-reply-to: <20020114123414.2713.qmail@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <15421.39711.249899.991670@xxxxxxxxxxxxxxxxxx> <20020114123414.2713.qmail@xxxxxxxxxxxxxxxxxxxxxx>
Oliver Kiddle wrote:
> I'm having problems with outgoing e-mail so sorry if this turns up
> twice, in two weeks time, to Sven only or whatever.
>
> --- Sven Wischnowsky <wischnow@xxxxxxxxx> wrote: >
>
> > 2. The doubled description is the real problem. There is no action
> > in
> > the spec for --font. So the faked matches get added under that
> > default description mentioned above and later _arguments uses
> > message to add the explanation it always adds for an empty action
> > in a spec. And that's the reason why the C code doesn't put the
> > two groups together, which was irritating me before I looked.
> >
> > Hrm. I've got to think some more about this, or maybe someone else
> > has ideas?
>
> I mentioned before (14031, last two paragraphs) that using _message in
> these cases also has the problem that the format style for the
> descriptions tag is not looked up.
>
> There needs to be a way to add a type of match with description but
> without actually adding matches that can be used in those cases where
> adding matches isn't sensible. The interface to it can perhaps be
> _guard like for the pattern.
This took some time because I'm currently very busy here, but below is
a suggested patch.
With this, I agreee with Oliver that this might indeed be the real
problem, so I changed the implementation of `compadd -x'. Messages
added with that still always show up, but otherwise they are now like
the descriptions added with -X. Then I changed _message to accept the
option `-e <tag> <descr>' which adds such a description for the given
tag.
I'm still not going to commit this patch until I get positive replies,
but maybe it's already near enough to put it into the current
development version. We would have to look through the functions using
_message to see which of them should be changed to use `_message -e'.
I've done this for _chown as an example (to show you how simple it
would be), but there are other places. The utility and core functions
should be ok with this patch, except for _guard, where I'm not sure.
Maybe we have to give it an option to tell it if the description is
supposed to be a only message or such a new description-without-matches
thing.
Bye
Sven
diff -ur -r ../oz/Completion/Base/Completer/_complete ./Completion/Base/Completer/_complete
--- ../oz/Completion/Base/Completer/_complete Thu Jan 17 19:49:32 2002
+++ ./Completion/Base/Completer/_complete Thu Jan 17 22:22:56 2002
@@ -36,7 +36,7 @@
case "$action" in
\ #)
- _message "$descr";;
+ _message -e "$tag" "$descr";;
\(\(*\)\))
eval ws\=\( "${action[3,-3]}" \)
diff -ur -r ../oz/Completion/Base/Core/_message ./Completion/Base/Core/_message
--- ../oz/Completion/Base/Core/_message Thu Jan 17 19:49:32 2002
+++ ./Completion/Base/Core/_message Thu Jan 17 22:52:13 2002
@@ -2,6 +2,19 @@
local format raw
+if [[ "$1" = -e ]]; then
+ local expl ret=1
+
+ _comp_mesg=yes
+
+ _tags "$2" && while _next_label "$2" expl "$3"; do
+ compadd ${expl:/-X/-x}
+ ret=0
+ done
+
+ return ret
+fi
+
_tags messages || return 1
if [[ "$1" = -r ]]; then
diff -ur -r ../oz/Completion/Base/Utility/_alternative ./Completion/Base/Utility/_alternative
--- ../oz/Completion/Base/Utility/_alternative Thu Jan 17 19:49:32 2002
+++ ./Completion/Base/Utility/_alternative Thu Jan 17 22:22:32 2002
@@ -31,7 +31,7 @@
# An empty action means that we should just display a message.
- mesgs=( "$mesgs[@]" "$descr")
+ mesgs=( "$mesgs[@]" "${def%%:*}:$descr")
elif [[ "$action" = \(\(*\)\) ]]; then
local ws
@@ -76,7 +76,7 @@
done
for descr in "$mesgs[@]"; do
- _message "$descr"
+ _message -e "${descr%%:*}" "${desc#*:}"
done
return 1
diff -ur -r ../oz/Completion/Base/Utility/_arguments ./Completion/Base/Utility/_arguments
--- ../oz/Completion/Base/Utility/_arguments Thu Jan 17 19:49:32 2002
+++ ./Completion/Base/Utility/_arguments Thu Jan 17 22:12:54 2002
@@ -274,7 +274,7 @@
# An empty action means that we should just display a message.
- _message "$descr"
+ _message -e "$subc" "$descr"
mesg=yes
tried=yes
alwopt=${alwopt:-yes}
diff -ur -r ../oz/Completion/Base/Utility/_values ./Completion/Base/Utility/_values
--- ../oz/Completion/Base/Utility/_values Thu Jan 17 19:49:32 2002
+++ ./Completion/Base/Utility/_values Thu Jan 17 23:07:30 2002
@@ -103,7 +103,7 @@
# An empty action means that we should just display a message.
- _message "$descr"
+ _message -e arguments "$descr"
return 1
elif [[ "$action" = \(\(*\)\) ]]; then
diff -ur -r ../oz/Completion/Unix/Command/_chown ./Completion/Unix/Command/_chown
--- ../oz/Completion/Unix/Command/_chown Thu Jan 17 19:49:32 2002
+++ ./Completion/Unix/Command/_chown Thu Jan 17 23:08:26 2002
@@ -5,7 +5,7 @@
line=( "${(@)words[2,CURRENT-1]:#-*}" )
if [[ -prefix - ]]; then
- _message option
+ _message -e option option
elif [[ $#line -eq 0 ]]; then
if [[ $service = chgrp ]] || compset -P '*[:.]'; then
if (( EGID && $+commands[groups] )); then # except for root
diff -ur -r ../oz/Doc/Zsh/compsys.yo ./Doc/Zsh/compsys.yo
--- ../oz/Doc/Zsh/compsys.yo Thu Jan 17 19:49:30 2002
+++ ./Doc/Zsh/compsys.yo Thu Jan 17 23:16:07 2002
@@ -3679,7 +3679,8 @@
followed by another character, only options are completed.
)
findex(_message)
-item(tt(_message) [ -r ] var(descr))(
+xitem(tt(_message) [ tt(-r) ] var(descr))
+item(tt(_message -e) var(tag descr))(
The var(descr) is used like the third
argument to the tt(_description) function. However, the resulting
string will always be shown whether or not matches were
@@ -3694,6 +3695,10 @@
used literally as the string to display. This is only used in cases
where that string is taken from some pre-processed argument list
containing an expanded description.
+
+In the second form, the var(descr) is added like a description added
+by tt(_description) under the given var(tag), but the var(descr) will
+always be shown even if no matches are added for the var(tag).
)
findex(_multi_parts)
item(tt(_multi_parts) var(sep) var(array))(
diff -ur -r ../oz/Src/Zle/comp.h ./Src/Zle/comp.h
--- ../oz/Src/Zle/comp.h Thu Jan 17 19:49:31 2002
+++ ./Src/Zle/comp.h Thu Jan 17 20:30:20 2002
@@ -38,6 +38,7 @@
/* This is for explantion strings. */
struct cexpl {
+ int always; /* display even without matches */
char *str; /* the string */
int count; /* the number of matches */
int fcount; /* number of matches with fignore ignored */
diff -ur -r ../oz/Src/Zle/compcore.c ./Src/Zle/compcore.c
--- ../oz/Src/Zle/compcore.c Thu Jan 17 19:49:31 2002
+++ ./Src/Zle/compcore.c Thu Jan 17 21:22:30 2002
@@ -1618,6 +1618,18 @@
Brinfo bp, bpl = brbeg, obpl, bsl = brend, obsl;
Heap oldheap;
+ SWITCHHEAPS(oldheap, compheap) {
+ if (dat->mesg || dat->exp) {
+ curexpl = (Cexpl) zhalloc(sizeof(struct cexpl));
+ curexpl->always = !!dat->mesg;
+ curexpl->count = curexpl->fcount = 0;
+ curexpl->str = dupstring(dat->mesg ? dat->mesg : dat->exp);
+ if (dat->mesg)
+ addexpl(1);
+ } else
+ curexpl = NULL;
+ } SWITCHBACKHEAPS(oldheap);
+
if (!*argv && !dat->dummies && !(dat->aflags & CAF_ALL)) {
SWITCHHEAPS(oldheap, compheap) {
/* Select the group in which to store the matches. */
@@ -1631,8 +1643,6 @@
endcmgroup(NULL);
begcmgroup("default", 0);
}
- if (dat->mesg)
- addmesg(dat->mesg);
} SWITCHBACKHEAPS(oldheap);
return 1;
@@ -1689,13 +1699,6 @@
dparr = NULL;
dparl = newlinklist();
}
- if (dat->exp) {
- curexpl = (Cexpl) zhalloc(sizeof(struct cexpl));
- curexpl->count = curexpl->fcount = 0;
- curexpl->str = dupstring(dat->exp);
- } else
- curexpl = NULL;
-
/* Store the matcher in our stack of matchers. */
if (dat->match) {
mst.next = mstack;
@@ -1889,8 +1892,6 @@
endcmgroup(NULL);
begcmgroup("default", 0);
}
- if (dat->mesg)
- addmesg(dat->mesg);
if (*argv) {
if (dat->pre)
dat->pre = dupstring(dat->pre);
@@ -2057,7 +2058,7 @@
if (dat->dpar)
set_list_array(dat->dpar, dparl);
if (dat->exp)
- addexpl();
+ addexpl(0);
if (!hasallmatch && (dat->aflags & CAF_ALL)) {
addmatch("<all>", dat->flags | CMF_ALL, &disp, 1);
hasallmatch = 1;
@@ -2496,45 +2497,27 @@
/**/
mod_export void
-addexpl(void)
+addexpl(int always)
{
LinkNode n;
Cexpl e;
for (n = firstnode(expls); n; incnode(n)) {
e = (Cexpl) getdata(n);
- if (e->count >= 0 && !strcmp(curexpl->str, e->str)) {
+ if (!strcmp(curexpl->str, e->str)) {
e->count += curexpl->count;
e->fcount += curexpl->fcount;
-
+ if (always)
+ e->always = 1;
return;
}
}
addlinknode(expls, curexpl);
newmatches = 1;
-}
-
-/* Add a message to the current group. Make sure it is shown. */
-
-/**/
-mod_export void
-addmesg(char *mesg)
-{
- LinkNode n;
- Cexpl e;
-
- for (n = firstnode(expls); n; incnode(n)) {
- e = (Cexpl) getdata(n);
- if (e->count < 0 && !strcmp(mesg, e->str))
- return;
+ if (always) {
+ mgroup->new = 1;
+ nmessages++;
}
- e = (Cexpl) zhalloc(sizeof(*e));
- e->count = e->fcount = -1;
- e->str = dupstring(mesg);
- addlinknode(expls, e);
- newmatches = 1;
- mgroup->new = 1;
- nmessages++;
}
/* The comparison function for matches (used for sorting). */
@@ -2852,6 +2835,7 @@
for (eq = g->expls; (o = *eq); eq++, ep++) {
*ep = e = (Cexpl) zcalloc(sizeof(struct cexpl));
e->count = (fi ? o->fcount : o->count);
+ e->always = o->always;
e->fcount = 0;
e->str = ztrdup(o->str);
}
diff -ur -r ../oz/Src/Zle/compctl.c ./Src/Zle/compctl.c
--- ../oz/Src/Zle/compctl.c Thu Jan 17 19:49:31 2002
+++ ./Src/Zle/compctl.c Thu Jan 17 20:55:02 2002
@@ -3808,9 +3808,9 @@
if (cc->gname) {
endcmgroup(yaptr);
begcmgroup(cc->gname, gflags);
- addexpl();
+ addexpl(0);
} else {
- addexpl();
+ addexpl(0);
endcmgroup(yaptr);
begcmgroup("default", 0);
}
@@ -3825,7 +3825,7 @@
untokenize(tt);
}
curexpl->str = tt;
- addexpl();
+ addexpl(0);
}
if (cc->subcmd) {
/* Handle -l sub-completion. */
diff -ur -r ../oz/Src/Zle/complist.c ./Src/Zle/complist.c
--- ../oz/Src/Zle/complist.c Thu Jan 17 19:49:31 2002
+++ ./Src/Zle/complist.c Thu Jan 17 20:59:56 2002
@@ -1042,9 +1042,9 @@
lastused = 1;
}
while (*e) {
- if ((*e)->count &&
+ if (((*e)->count || (*e)->always) &&
(!listdat.onlyexpl ||
- (listdat.onlyexpl & ((*e)->count > 0 ? 1 : 2)))) {
+ (listdat.onlyexpl & ((*e)->always > 0 ? 2 : 1)))) {
if (pnl) {
if (dolistnl(ml) && compprintnl(ml))
goto end;
@@ -1058,8 +1058,9 @@
}
if (mlbeg < 0 && mfirstl < 0)
mfirstl = ml;
- l = compprintfmt((*e)->str, (*e)->count, dolist(ml), 1,
- ml, &stop);
+ l = compprintfmt((*e)->str,
+ ((*e)->always ? -1 : (*e)->count),
+ dolist(ml), 1, ml, &stop);
if (mselect >= 0) {
int mm = (mcols * ml), i;
diff -ur -r ../oz/Src/Zle/compresult.c ./Src/Zle/compresult.c
--- ../oz/Src/Zle/compresult.c Thu Jan 17 19:49:31 2002
+++ ./Src/Zle/compresult.c Thu Jan 17 21:02:12 2002
@@ -1494,10 +1494,12 @@
}
if ((e = g->expls)) {
while (*e) {
- if ((*e)->count &&
+ if (((*e)->count || (*e)->always) &&
(!onlyexpl ||
- (onlyexpl & ((*e)->count > 0 ? 1 : 2))))
- nlines += 1 + printfmt((*e)->str, (*e)->count, 0, 1);
+ (onlyexpl & ((*e)->always > 0 ? 2 : 1))))
+ nlines += 1 + printfmt((*e)->str,
+ ((*e)->always ? -1 : (*e)->count),
+ 0, 1);
e++;
}
}
@@ -1840,9 +1842,9 @@
int l;
while (*e) {
- if ((*e)->count &&
+ if (((*e)->count || (*e)->always) &&
(!listdat.onlyexpl ||
- (listdat.onlyexpl & ((*e)->count > 0 ? 1 : 2)))) {
+ (listdat.onlyexpl & ((*e)->always > 0 ? 2 : 1)))) {
if (pnl) {
putc('\n', shout);
pnl = 0;
@@ -1853,7 +1855,8 @@
tcout(TCCLEAREOD);
}
}
- l = printfmt((*e)->str, (*e)->count, 1, 1);
+ l = printfmt((*e)->str,
+ ((*e)->always ? -1 : (*e)->count), 1, 1);
ml += l;
if (cl >= 0 && (cl -= l) <= 1) {
cl = -1;
--
Sven Wischnowsky wischnow@xxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author