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

PATCH: Re: Completion in the first character position

Bart Schaefer wrote:

> ...
> Even sillier is that ^D in this same position _does_ produce a list,
> rather than exiting from `select'.  That doesn't appear to be the case
> any longer with the new completion system.

In 3.1.dunno I added the -e option to vared to make it exit on a ^D
on an empty line.

> ...
> Which reminds me:  `zed' should do something similar.  As should vared
> when editing an element of the functions assoc -- is there a way to be
> that specific about the vared context?

For zed I would prefer a solution with $curcontext  as you suggested.

For the other thing: _value (which is called from _in_vared) allows
to override completion for specific parameters by defining functions
like `_value:foo'. For elements of associations this was a bit stupid
because it could only be done on a per-key basis (`_value:foo-key'). 
The patch below fixes that so that one can change completion for all
elements of an assoc by defining `_value:<assoc>'. Should have though
of that before, sorry (although that calling-of-_value:* was added by
someone else, Akira, I think). Should we add a default for

In a different message Bart Schaefer wrote:

> On Jul 25,  3:39pm, Bart Schaefer wrote:
> } Subject: Re: Completion in the first character position
> }
> }     local curcontext=${0}:::
> }     zstyle ":completion:${0}:*" insert-tab no
> } 
> } Which reminds me:  `zed' should do something similar.
> Anybody object to this patch?  Perhaps the patterns used/tested in the
> zstyle commands should be more specific?

No objections. But, yes, I've been wishing for a more generic approach 
for overriding completion styles (or giving them defaults) from
outside of the completion system.

Even something as simple as local styles might be interesting to
have... hm, that actually seems doable. Defined by, say, `zstyle -l'
and adding a wrapper function to remove them at the appropriate
time. But that doesn't solve the problem that there may be other
settings for the styles with more specific patterns that wouldn't be
overridden. Maybe together with a (locally-)delete-styles that's
independent of the context patterns?


Index: Completion/Base/_value
RCS file: /cvsroot/zsh/zsh/Completion/Base/_value,v
retrieving revision 1.4
diff -u -r1.4 _value
--- Completion/Base/_value	2000/05/31 09:38:26	1.4
+++ Completion/Base/_value	2000/07/26 08:01:13
@@ -2,10 +2,16 @@
 _value () {
   # You can customize completion for different parameters by writing a
-  # function `_value:<name>'.
+  # function `_value:<name>', where <name> is the name of the parameter.
+  # When completing values of elements of associative arrays, we first
+  # search for a function `_value:<assoc>-<key>' and then for 
+  # `_value:<assoc>', so it's simple to define different functions
+  # for different keys or one function for a whole association.
   if (( $+functions[_value:$compstate[parameter]] )); then
     "_value:$compstate[parameter]" "$@"
+  elif (( $+functions[_value:${compstate[parameter]%%-*}] )); then
+    "_value:${compstate[parameter]%%-*}" "$@"
   elif [[ "$compstate[parameter]" != *-* &&
           "${(Pt)${compstate[parameter]}}" = assoc* ]]; then
     if (( CURRENT & 1 )); then

Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx

Messages sorted by: Reverse Date, Date, Thread, Author