Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Re PATCH _file_systems & Re zstyle for _arguments feature request



Oliver Kiddle wrote:

> ...
> 
> On the subject of the fake style, if we find that there is demand for
> something more powerful, using _alternative like specs would probably
> be sufficient though I'm not sure whether that could be made to work
> because the functions need to be called from somewhere. Using zstyle -e
> with the current fake style allows some fairly powerful things to be
> done but there can be problems..

Yes, it's a first try at something that can be made very powerful
anyway.  Using _alternative there is dangerous (I think, I haven't
tried it), but the fake style can be made more powerful without that
and without much work.  We only need to wait for ideas.

> While I'm on the subject of recent patches, the man page sectioning
> patch is great so thanks for that Sven. I only wonder that the
> separate-sections style shouldn't be the default. For people who don't
> like it, the group-name style can re-group them but is there any way to
> have one description for the re-grouped sections.

You mean removing the separate-sections style?  I've added that
because I couldn't think of a way to get the other description (for
the case when the matches from all sections are shown together)
without adding it.  That would require some (probably serious) changes
to the group-name style, whose implementation is currently nicely
simple, so I was reluctant to even try that.  Is the solution with the
new style so ugly that we have to try?

> ...
> 
> > I've done this for _chown as an example (to show you how simple it
> 
> Note that the tag in this _chown change should be `options' instead
> of `option'.

Oops.  M-w no good ;-}  Thanks!

> I have found one small thing which I don't think is right though:
>   zstyle ':completion::complete:grep:argument-1:*' fake one two three
>   grep x<tab>
> Because x doesn't match one two or three, it is now not displaying the
> message `pattern' but it isn't saying `No matches for <tag>' either.

Oops, again.  Buglet in the C-code change, of course I wanted to
achieve:

> Continuing to display `pattern' would perhaps be best because matches
> added with fake are probably not an exhaustive set. There are
> completion functions where we don't add an exhaustive set of matches
> either. An example would be after vncserver -geometry (any x y
> combination would be valid). Perhaps in these cases, by using -x
> instead of -X, the message should persist instead of getting `No
> matches for...'.
> 
> It would also be very useful in cases such as this in _cvs:
>   if (( $#vendor_branch )); then
>     _wanted values expl 'vendor branch' compadd -a vendor_branch
>   else
>     _message 'vendor branch'
>   fi
> 
> _wanted would need to be modified to take the -x option which would
> cause it (or _description) to change -X in expl to -x. _cvs would
> then only need to do:
> 
>   _wanted -x values expl 'vendor branch' compadd -a vendor_branch

Good idea (although I'd probably take a different option letter there
(where function writers can see it)).  The patch below doens't contain
this, because we should then change _description and all the functions
that call it (not only _wanted), I'll look into this.

The patch also doesn't contain changes to other command-completion
functions because that should then probably wait until the changes to
_description and friends are in place.

> > 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.
> 
> Looking at where we've used _guard, it certainly needs to be able to
> use the description-without-matches thing but whether _guard might ever
> be used for a plain message, I'm not sure. I can't see why it ever
> would. We could always add an option for that later if it is needed.

Yes.  Problem is the way _guard is called -- we can't easily get at
the tag there (inside _guard) which would be needed to make sure the
description is attached to the same group of matches as the faked
matches (when the group-name style is used) -- otherwise the
description would be shown more than once.  I'll think about this some
more.


Felix Rosencrantz wrote:

> Though there is a possible strange behavior.  I'm not sure how multiple
> matches are handled in other situations, so this might just be how
> completion works.
> 
> Given these commands:
> 
> host@ zstyle :completion::complete:cvs-admin:option-k-1:option-k-1 fake
> b:binary
> host@ cvs admin -k<TAB>
> ---- keyword substitution
> b  -- binary
> b    k    kv   kvl  o    v
> 
> I wanted to add help text to options to the -k flag.  I was able to do that,
> however, "b" is now listed twice. (As well as any other options to which I
> add help.)

This is one of the cases where the faked matches end up in a different
group, similar to what I described above.  We'll work on this.

And this time, I'm going to commit it, makes my bookkeeping easier.


Bye
  Sven

Index: Completion/Base/Completer/_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_complete,v
retrieving revision 1.2
diff -u -r1.2 _complete
--- Completion/Base/Completer/_complete	2002/01/21 16:13:18	1.2
+++ Completion/Base/Completer/_complete	2002/01/22 10:20:39
@@ -36,7 +36,7 @@
 
     case "$action" in
     \ #)
-      _message "$descr";;
+      _message -e "$tag" "$descr";;
 
     \(\(*\)\))
       eval ws\=\( "${action[3,-3]}" \)
Index: Completion/Base/Core/_description
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_description,v
retrieving revision 1.2
diff -u -r1.2 _description
--- Completion/Base/Core/_description	2001/05/08 08:47:00	1.2
+++ Completion/Base/Core/_description	2002/01/22 10:20:39
@@ -1,6 +1,6 @@
 #autoload
 
-local name gropt=-J format gname hidden hide match opts
+local name gropt=-J format gname hidden hide match opts tag
 
 opts=()
 
@@ -51,6 +51,8 @@
   _comp_ignore=()
 fi
 
+tag="$1"
+
 shift 2
 if [[ -z "$1" && $# -eq 1 ]]; then
   format=
@@ -70,6 +72,17 @@
   else
     set -A "$name" "$opts[@]" "$gropt" -default-
   fi
+fi
+
+if ! (( ${funcstack[2,-1][(I)_description]} )) &&
+   zstyle -a ":completion:${curcontext}:$tag" fake match; then
+
+  local descr
+
+  descr=( "${(@M)match:#*[^\\]:*}" )
+
+  compadd "${(@P)name}" - "${(@)${(@)match:#*[^\\]:*}:s/\\:/:/}"
+  (( $#descr )) && _describe -t "$tag" '' descr "${(@P)name}"
 fi
 
 return 0
Index: Completion/Base/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_main_complete,v
retrieving revision 1.4
diff -u -r1.4 _main_complete
--- Completion/Base/Core/_main_complete	2001/08/17 10:37:00	1.4
+++ Completion/Base/Core/_main_complete	2002/01/22 10:20:40
@@ -268,7 +268,7 @@
       fi
     fi
   fi
-elif [[ nm -le 1 && -n "$_comp_mesg" ]]; then
+elif [[ nm -lt 1 && -n "$_comp_mesg" ]]; then
   compstate[insert]=''
   compstate[list]='list force'
 elif [[ nm -eq 0 && -z "$_comp_mesg" &&
Index: Completion/Base/Core/_message
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_message,v
retrieving revision 1.1
diff -u -r1.1 _message
--- Completion/Base/Core/_message	2001/04/02 11:03:34	1.1
+++ Completion/Base/Core/_message	2002/01/22 10:20:40
@@ -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
Index: Completion/Base/Utility/_alternative
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_alternative,v
retrieving revision 1.1
diff -u -r1.1 _alternative
--- Completion/Base/Utility/_alternative	2001/04/02 11:12:39	1.1
+++ Completion/Base/Utility/_alternative	2002/01/22 10:20:40
@@ -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
Index: Completion/Base/Utility/_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_arguments,v
retrieving revision 1.9
diff -u -r1.9 _arguments
--- Completion/Base/Utility/_arguments	2001/07/30 08:42:56	1.9
+++ Completion/Base/Utility/_arguments	2002/01/22 10:20:40
@@ -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}
Index: Completion/Base/Utility/_values
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_values,v
retrieving revision 1.6
diff -u -r1.6 _values
--- Completion/Base/Utility/_values	2001/06/13 11:05:51	1.6
+++ Completion/Base/Utility/_values	2002/01/22 10:20:40
@@ -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
Index: Completion/Unix/Command/_chown
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_chown,v
retrieving revision 1.5
diff -u -r1.5 _chown
--- Completion/Unix/Command/_chown	2002/01/03 12:47:56	1.5
+++ Completion/Unix/Command/_chown	2002/01/22 10:20:40
@@ -5,7 +5,7 @@
 line=( "${(@)words[2,CURRENT-1]:#-*}" )
 
 if [[ -prefix - ]]; then
-  _message option
+  _message -e options option
 elif [[ $#line -eq 0 ]]; then
   if [[ $service = chgrp ]] || compset -P '*[:.]'; then
     if (( EGID && $+commands[groups] )); then  # except for root
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.140
diff -u -r1.140 compsys.yo
--- Doc/Zsh/compsys.yo	2002/01/21 16:13:18	1.140
+++ Doc/Zsh/compsys.yo	2002/01/22 10:20:40
@@ -1120,6 +1120,22 @@
 this will also cycle through the names of the files in pathname
 components after the first ambiguous one.
 )
+kindex(fake, completion style)
+item(tt(fake))(
+This style may be set for every completion context and is used to
+specify additional strings to complete in that context.  It's values
+are either the strings to complete with every colon quoted by a
+preceding backslash or strings of the form
+`var(string)tt(:)var(description)'.  In the latter case the var(string)s
+will be shown together with the var(description)s in completion
+listings.
+
+Note that you only really want to use this style for a narrow
+enough context, so that the additional string won't show up in other
+contexts.  Also note the styles tt(fake-files) and tt(fake-parameters)
+which give more control over additional strings to add when completing
+files or parameters.
+)
 kindex(fake-files, completion style)
 item(tt(fake-files))(
 This style is used when completing files and looked up 
@@ -3676,7 +3692,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
@@ -3691,6 +3708,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))(
Index: Src/Zle/comp.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/comp.h,v
retrieving revision 1.11
diff -u -r1.11 comp.h
--- Src/Zle/comp.h	2001/07/25 08:52:34	1.11
+++ Src/Zle/comp.h	2002/01/22 10:20:40
@@ -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 */
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.52
diff -u -r1.52 compcore.c
--- Src/Zle/compcore.c	2002/01/07 14:43:40	1.52
+++ Src/Zle/compcore.c	2002/01/22 10:20:41
@@ -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,31 @@
 
 /**/
 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;
+                nmessages++;
+                newmatches = 1;
+                mgroup->new = 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 +2839,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);
 		}
Index: Src/Zle/compctl.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compctl.c,v
retrieving revision 1.11
diff -u -r1.11 compctl.c
--- Src/Zle/compctl.c	2001/11/28 18:30:51	1.11
+++ Src/Zle/compctl.c	2002/01/22 10:20:41
@@ -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. */
Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.44
diff -u -r1.44 complist.c
--- Src/Zle/complist.c	2001/07/25 08:52:34	1.44
+++ Src/Zle/complist.c	2002/01/22 10:20:41
@@ -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;
 
Index: Src/Zle/compresult.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v
retrieving revision 1.42
diff -u -r1.42 compresult.c
--- Src/Zle/compresult.c	2001/10/05 12:44:01	1.42
+++ Src/Zle/compresult.c	2002/01/22 10:20:41
@@ -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