zsh-workers
 help / color / mirror / code / Atom feed
* Using _values with ->state transitions?
@ 2001-05-05 17:20 Bart Schaefer
  2001-05-07  8:06 ` Sven Wischnowsky
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2001-05-05 17:20 UTC (permalink / raw)
  To: zsh-workers

This is supposed to work, isn't it?  There appears to be code for it in
_values, but there aren't any examples of it in the existing completion
system. I can't get it to do anything sensible in several attempts.

The zsh/computil documentation needs some improvement.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Using _values with ->state transitions?
  2001-05-05 17:20 Using _values with ->state transitions? Bart Schaefer
@ 2001-05-07  8:06 ` Sven Wischnowsky
  2001-05-07 15:08   ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sven Wischnowsky @ 2001-05-07  8:06 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> This is supposed to work, isn't it?  There appears to be code for it in
> _values, but there aren't any examples of it in the existing completion
> system. I can't get it to do anything sensible in several attempts.

Hm, the simple test:

  _values test 'a:arg:->foo' b c

  if [[ -n $state ]]; then compadd foo bar; fi

works for me.  How does this fail for you?

> The zsh/computil documentation needs some improvement.

I always think of computil as something too deeply hidden for ca. 99
percent of all users and programmers.  And most of those builtins are
useful only for the functions for which they were invented, so that
documenting them doesn't make much sense unless people would want their
own versions of _arguments and _values which behave the same as the
originals.  Maybe we should put some more comments in those functions.


Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Using _values with ->state transitions?
  2001-05-07  8:06 ` Sven Wischnowsky
@ 2001-05-07 15:08   ` Bart Schaefer
  2001-05-08 12:21     ` Sven Wischnowsky
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2001-05-07 15:08 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On May 7, 10:06am, Sven Wischnowsky wrote:
} Subject: Re: Using _values with ->state transitions?
}
} Bart Schaefer wrote:
} 
} > This is supposed to work, isn't it?  There appears to be code for it in
} > _values, but there aren't any examples of it in the existing completion
} > system. I can't get it to do anything sensible in several attempts.
} 
} Hm, the simple test:
} 
}   _values test 'a:arg:->foo' b c
} 
}   if [[ -n $state ]]; then compadd foo bar; fi
} 
} works for me.  How does this fail for you?

OK, that does work for me.  However, it sometimes ignores the -s option.
To wit:

schaefer[505] _tv() {
function> _values -s ':' test 'a:arg:->foo' b c
function> if [[ -n $state ]]; then compadd $state; fi
function> }
schaefer[506] compdef _tv :
schaefer[507] : a<TAB>
schaefer[507] : a=<TAB>
schaefer[508] : a=foo 
                      ^cursor here -- why did that space get added?
		      I expected `a=foo:'.

It would also be nice if there were a way to specify that something other
than an `=' comes between the value and its argument.
 
} > The zsh/computil documentation needs some improvement.
} 
} I always think of computil as something too deeply hidden for ca. 99
} percent of all users and programmers.

Well, then, it's the doc for _values that needs improvement.  The SPECS
for _values are no longer the same as those for _arguments (at best, they
now are a subset).

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Using _values with ->state transitions?
  2001-05-07 15:08   ` Bart Schaefer
@ 2001-05-08 12:21     ` Sven Wischnowsky
  2001-05-08 15:27       ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sven Wischnowsky @ 2001-05-08 12:21 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
> 
> OK, that does work for me.  However, it sometimes ignores the -s option.
> To wit:
> 
> schaefer[505] _tv() {
> function> _values -s ':' test 'a:arg:->foo' b c
> function> if [[ -n $state ]]; then compadd $state; fi
> function> }
> schaefer[506] compdef _tv :
> schaefer[507] : a<TAB>
> schaefer[507] : a=<TAB>
> schaefer[508] : a=foo 
>                       ^cursor here -- why did that space get added?
> 		      I expected `a=foo:'.

Er, how should _values do that?  At the time the `foo' is added as a
match _values isn't running anymore.  We could make _values store the
`-qS$sep' in some array that has to be declared by the calling function,
but then that function has to use it and probably could equally well do
it directly.  Should we add that or just document what the function
handling the `->state' would have to do?

(But it was broken for the (...)-forms of actions, too.  Ahem.)

> It would also be nice if there were a way to specify that something other
> than an `=' comes between the value and its argument.

The patch below does that.  One can now use `_value -S : ...' to say
that values are separated from their arguments by colons, for example.

> } > The zsh/computil documentation needs some improvement.
> } 
> } I always think of computil as something too deeply hidden for ca. 99
> } percent of all users and programmers.
> 
> Well, then, it's the doc for _values that needs improvement.  The SPECS
> for _values are no longer the same as those for _arguments (at best, they
> now are a subset).

Hm, yes, the `= ...' prefix is not supported.  Anything else we need to
add?

Bye
  Sven

Index: Completion/Base/Utility/_values
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_values,v
retrieving revision 1.1
diff -u -r1.1 _values
--- Completion/Base/Utility/_values	2001/04/02 11:12:08	1.1
+++ Completion/Base/Utility/_values	2001/05/08 12:15:21
@@ -13,9 +13,12 @@
 
 if compvalues -i "$@"; then
 
-  local noargs args opts descr action expl sep subc
+  local noargs args opts descr action expl sep argsep subc test='*'
   local oldcontext="$curcontext"
 
+  compvalues -S argsep
+  compvalues -s sep && [[ -n "$sep" ]] && test="[^${(q)sep}]#"
+
   if ! compvalues -D descr action; then
 
     _tags values || return 1
@@ -24,17 +27,17 @@
 
     compvalues -V noargs args opts
 
-    if [[ "$PREFIX" = *\=* ]]; then
+    if [[ "$PREFIX" = *${argsep}${~test} ]]; then
       local name
 
-      name="${PREFIX%%\=*}"
+      name="${PREFIX%%${argsep}*}"
       if compvalues -L "$name" descr action; then
-        IPREFIX="${IPREFIX}${name}="
-        PREFIX="${PREFIX#*\=}"
+        IPREFIX="${IPREFIX}${name}${argsep}"
+        PREFIX="${PREFIX#*${argsep}}"
       else
         local prefix suffix
 
-	prefix="${PREFIX#*\=}"
+	prefix="${PREFIX#*${argsep}}"
 	suffix="$SUFFIX"
 	PREFIX="$name"
 	SUFFIX=''
@@ -45,7 +48,7 @@
 
         PREFIX="$prefix"
 	SUFFIX="$suffix"
-        IPREFIX="${IPREFIX}${args[1]%%:*}="
+        IPREFIX="${IPREFIX}${args[1]%%:*}${argsep}"
 	compvalues -L "${args[1]%%:*}" descr action subc
 	curcontext="${oldcontext%:*}:$subc"
       fi
@@ -59,8 +62,8 @@
 
       _describe "$descr" \
         noargs "$sep[@]" -M 'r:|[_-]=* r:|=*' -- \
-        args -S= -M 'r:|[_-]=* r:|=*' -- \
-        opts -qS= -M 'r:|[_-]=* r:|=*'
+        args -S "${argsep}" -M 'r:|[_-]=* r:|=*' -- \
+        opts -qS "${argsep}" -M 'r:|[_-]=* r:|=*'
 
       curcontext="$oldcontext"
 
@@ -82,7 +85,7 @@
   # we have only one possible value left.
 
   [[ ${#snames}+${#names}+${#onames} -ne 1 ]] && compvalues -s sep &&
-      expl=( "-qS$sep" "$expl[@]" )
+      expl=( "-qS$sep" "$expl[@]" ) sep=( "-qS$sep" )
 
   if [[ "$action" = -\>* ]]; then
     compvalues -v val_args
@@ -113,7 +116,7 @@
 
       eval ws\=\( "${action[3,-3]}" \)
 
-      _describe "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]"
+      _describe "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]" "$sep[@]"
 
     elif [[ "$action" = \(*\) ]]; then
 
@@ -121,7 +124,7 @@
 
       eval ws\=\( "${action[2,-2]}" \)
 
-      _all_labels arguments expl "$descr" compadd "$subopts[@]" -a - ws
+      _all_labels arguments expl "$descr" compadd "$subopts[@]" "$sep[@]" -a - ws
     elif [[ "$action" = \{*\} ]]; then
 
       # A string in braces is evaluated.
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.122
diff -u -r1.122 compsys.yo
--- Doc/Zsh/compsys.yo	2001/05/08 08:47:00	1.122
+++ Doc/Zsh/compsys.yo	2001/05/08 12:15:25
@@ -3949,8 +3949,14 @@
 All other arguments describe the possible values and their
 arguments in the same format used for the description of options by
 the tt(_arguments) function (see above).  The only differences are that
-no minus or plus sign is required at the beginning and that
-values can have only one argument.
+no minus or plus sign is required at the beginning, that
+values can have only one argument and that those forms of actions
+beginning with an equal sign are not supported.
+
+The character separating a value from its argument can be set using the
+option tt(-S) (like tt(-s), followed by the character to use as the
+separator in the next argument).  If this option is not used, the equal
+sign will be used as the separator.
 
 Example:
 
Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.53
diff -u -r1.53 computil.c
--- Src/Zle/computil.c	2001/05/06 22:37:51	1.53
+++ Src/Zle/computil.c	2001/05/08 12:15:26
@@ -2029,6 +2029,7 @@
     char *descr;		/* global description */
     int hassep;			/* multiple values allowed */
     char sep;			/* separator character */
+    char argsep;                /* argument separator */
     Cvdef next;			/* next in cache */
     Cvval vals;			/* value definitions */
     char **defs;		/* original strings */
@@ -2090,16 +2091,21 @@
     Cvdef ret;
     Cvval val, *valp;
     Caarg arg;
-    char **oargs = args, sep = '\0', *name, *descr, *p, *q, **xor, c;
+    char **oargs = args, sep = '\0', asep = '=', *name, *descr, *p, *q, **xor, c;
     int xnum, multi, vtype, hassep = 0;
 
-    if (args[0][0] == '-' && args[0][1] == 's' && !args[0][2]) {
+    while (args[0][0] == '-' && (args[0][1] == 's' || args[0][1] == 'S') &&
+           !args[0][2]) {
 	if (args[1][0] && args[1][1]) {
 	    zwarnnam(nam, "invalid separator: %s", args[1], 0);
 	    return NULL;
 	}
-	hassep = 1;
-	sep = args[1][0];
+        if (args[0][1] == 's') {
+            hassep = 1;
+            sep = args[1][0];
+        } else
+            asep = args[1][0];
+
 	args += 2;
     }
     if (!args[0] || !args[1]) {
@@ -2112,6 +2118,7 @@
     ret->descr = ztrdup(descr);
     ret->hassep = hassep;
     ret->sep = sep;
+    ret->argsep = asep;
     ret->next = NULL;
     ret->vals = NULL;
     ret->defs = zarrdup(oargs);
@@ -2330,7 +2337,7 @@
 	    for (str = compprefix, end = strchr(str, d->sep); end;) {
 		*end = '\0';
 
-		if ((heq = !!(eq = strchr(str, '='))))
+		if ((heq = !!(eq = strchr(str, d->argsep))))
 		    *eq++ = '\0';
 		else
 		    eq = "";
@@ -2342,7 +2349,7 @@
 		    cv_inactive(d, ptr->xor);
 		}
 		if (heq)
-		    eq[-1] = '=';
+		    eq[-1] = d->argsep;
 
 		*end = d->sep;
 		str = end + 1;
@@ -2357,7 +2364,7 @@
 		    if ((end = strchr(str, d->sep)))
 			*end = '\0';
 
-		    if ((heq = !!(eq = strchr(str, '='))))
+		    if ((heq = !!(eq = strchr(str, d->argsep))))
 			*eq++ = '\0';
 		    else
 			eq = "";
@@ -2369,7 +2376,7 @@
 			cv_inactive(d, ptr->xor);
 		    }
 		    if (heq)
-			eq[-1] = '=';
+			eq[-1] = d->argsep;
 		    if (end)
 			*end++ = d->sep;
 		}
@@ -2408,16 +2415,16 @@
     compprefix = str;
     compsuffix = ztrdup("");
 
-    if ((eq = strchr(str, '='))) {
+    if ((eq = strchr(str, d->argsep))) {
 	*eq++ = '\0';
 
 	if ((ptr = cv_get_val(d, str)) && ptr->type != CVV_NOARG) {
-	    eq[-1] = '=';
+	    eq[-1] = d->argsep;
 	    ignore_prefix(eq - str);
 	    state.def = ptr->arg;
 	    state.val = ptr;
 	} else
-	    eq[-1] = '=';
+	    eq[-1] = d->argsep;
     }
     memcpy(&cv_laststate, &state, sizeof(state));
 }
@@ -2445,6 +2452,7 @@
     case 'C': min = 1; max =  1; break;
     case 'V': min = 3; max =  3; break;
     case 's': min = 1; max =  1; break;
+    case 'S': min = 1; max =  1; break;
     case 'd': min = 1; max =  1; break;
     case 'L': min = 3; max =  4; break;
     case 'v': min = 1; max =  1; break;
@@ -2546,6 +2554,15 @@
 	    return 0;
 	}
 	return 1;
+    case 'S':
+	{
+	    char tmp[2];
+
+	    tmp[0] = cv_laststate.d->argsep;
+	    tmp[1] = '\0';
+	    setsparam(args[1], ztrdup(tmp));
+	}
+	return 0;
     case 'd':
 	setsparam(args[1], ztrdup(cv_laststate.d->descr));
 	return 0;

-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Using _values with ->state transitions?
  2001-05-08 12:21     ` Sven Wischnowsky
@ 2001-05-08 15:27       ` Bart Schaefer
  2001-05-09  8:53         ` PATCH: " Sven Wischnowsky
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2001-05-08 15:27 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On May 8,  2:21pm, Sven Wischnowsky wrote:
} Subject: Re: Using _values with ->state transitions?
}
} Bart Schaefer wrote:
} 
} > function> _values -s ':' test 'a:arg:->foo' b c
[...]
} > schaefer[507] : a=<TAB>
} > schaefer[508] : a=foo 
} >                       ^cursor here -- why did that space get added?
} 
} Er, how should _values do that?  At the time the `foo' is added as a
} match _values isn't running anymore.

Er, um ... I was confusing the problem above with THIS problem:

} (But it was broken for the (...)-forms of actions, too.  Ahem.)

So I really wasn't thinking of the -> case at all, so ...

} We could make _values store the `-qS$sep' in some array that has to be
} declared by the calling function, but then that function has to use it
} and probably could equally well do it directly.

Right.

} Should we add that or just document what the function handling the
} `->state' would have to do?

Documenting what the ->state handler should do would be nice, yes.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* PATCH: Re: Using _values with ->state transitions?
  2001-05-08 15:27       ` Bart Schaefer
@ 2001-05-09  8:53         ` Sven Wischnowsky
  0 siblings, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 2001-05-09  8:53 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
> 
> } Should we add that or just document what the function handling the
> } `->state' would have to do?
> 
> Documenting what the ->state handler should do would be nice, yes.

...

Bye
  Sven

Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.123
diff -u -r1.123 compsys.yo
--- Doc/Zsh/compsys.yo	2001/05/08 12:24:21	1.123
+++ Doc/Zsh/compsys.yo	2001/05/09 08:52:20
@@ -4002,6 +4002,16 @@
 function the tt(context) parameter will be set to the name of the
 value whose argument is to be completed.
 
+Note also that tt(_values) normally adds the character used as the
+separator between values as a auto-removable suffix so that users don't
+have to type it themselves.  But when using a `tt(->)var(string)' action
+tt(_values) can't do that because the matches for the argument will be
+generated by the calling function.  To get the usual behaviour, the
+implementor of the calling function has to add the suffix directly by
+passing the options `tt(-qS) var(x)' (where var(x) is the separator
+character specified with the tt(-s) option of tt(_values)) to the
+function generating the matches or to the tt(compadd) builtin.
+
 Like tt(_arguments), tt(_values) supports the tt(-C) option in
 which case you have to make the parameter tt(curcontext) local instead 
 of tt(context) (as described above).

-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-05-09  8:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-05 17:20 Using _values with ->state transitions? Bart Schaefer
2001-05-07  8:06 ` Sven Wischnowsky
2001-05-07 15:08   ` Bart Schaefer
2001-05-08 12:21     ` Sven Wischnowsky
2001-05-08 15:27       ` Bart Schaefer
2001-05-09  8:53         ` PATCH: " Sven Wischnowsky

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).