zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: pws-21: _vars
@ 1999-06-10 10:22 Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 1999-06-10 10:22 UTC (permalink / raw)
  To: Zsh hackers list

This extends the _vars completion, used after things like read and vared,
to allow completion of the keys of associative arrays.  However, the [ has
to be added by hand because it can't tell whether you want
the parameter or an element.  Maybe there's a case for autoparamkeys
behaviour --- but that would need sensitivity to the command context, which
isn't really on.

--- Completion/Base/_vars.old	Tue Apr 13 09:37:37 1999
+++ Completion/Base/_vars	Thu Jun 10 12:17:04 1999
@@ -1,3 +1,20 @@
 #compdef getopts read unset vared
 
-compgen -v
+# This will handle completion of keys of associative arrays, e.g. at
+# `vared compconfig[<TAB>'.  However, in this version the [ must be
+# added by hand.
+
+if [[ $PREFIX = *\[ ]]; then
+  local var=${PREFIX%%\[*}
+  local elt="${PREFIX#*\]}${SUFFIX%\]}"
+  local addclose
+  compset -p $(( ${#var} + 1 ))
+  if ! compset -S \]; then
+    addclose=(-S ']')
+  fi
+  if [[ ${(tP)var} = assoc* ]]; then
+    compadd $addclose ${(kP)var}
+  fi
+else
+  compgen -v
+fi

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


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

* Re: PATCH: pws-21: _vars
@ 1999-06-10 11:07 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 1999-06-10 11:07 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> This extends the _vars completion, used after things like read and vared,
> to allow completion of the keys of associative arrays.

  % typeset -A foo
  % foo=(-bar baz)
  % vared 'foo[<TAB>
  compadd: bad option -b

I often forget to add the `-' before the words in compadd, too.

This also had a problem when there were characters after the `['.

Bye
 Sven

--- oc/Base/_vars	Thu Jun 10 13:00:40 1999
+++ Completion/Base/_vars	Thu Jun 10 13:03:38 1999
@@ -4,7 +4,7 @@
 # `vared compconfig[<TAB>'.  However, in this version the [ must be
 # added by hand.
 
-if [[ $PREFIX = *\[ ]]; then
+if [[ $PREFIX = *\[* ]]; then
   local var=${PREFIX%%\[*}
   local elt="${PREFIX#*\]}${SUFFIX%\]}"
   local addclose
@@ -13,7 +13,7 @@
     addclose=(-S ']')
   fi
   if [[ ${(tP)var} = assoc* ]]; then
-    compadd $addclose ${(kP)var}
+    compadd $addclose - ${(kP)var}
   fi
 else
   compgen -v

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


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

end of thread, other threads:[~1999-06-10 11:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-10 10:22 PATCH: pws-21: _vars Peter Stephenson
1999-06-10 11:07 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).