zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: arguments for typeset (and variants)
@ 2000-05-09 16:50 Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2000-05-09 16:50 UTC (permalink / raw)
  To: Zsh workers

I've included here a patch to complete options after the typeset
command and its variants (_vars_eq). When the function directories are
rearranged, it might be better to rename it to _typeset.

Should I incorporate completion for autoload and functions into this? I
think they should be in here and that unfunction should be handled by a
new _unhash. _functions should still exist but should be moved to be
alongside _options etc and should be called from other completion
functions. Do you agree - if so, I'll do this tomorrow?

I had a few problems with the + options in _vars_eq but I must have been
doing something wrong. There should be +g, +h, +r, +t, +x (any maybe
some others) options but when I put them in the completion spec as
something like '(-f)-+x[ex...', completion for typeset hangs zsh.

I've done this _vars_eq in a slightly weird way because there didn't
seem to be an easy way to handle all the different variants to typeset.
If you can think if a better way, please change it. I think there are
still a few things missing from the mutexes but I'm not very sure of
which options really make sense together. What should be the case for
example with arrays and lowercase. The array values are never actually
converted so it would never make sense to use them together though the
variable is actually tagged as lower and typeset will not give you an
error. My opinion is that they should be considered mutually exclusive
because completion is more useful if fewer things are completed.

Oliver

Index: Completion/Builtins/_vars_eq
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_vars_eq,v
retrieving revision 1.3
diff -u -r1.3 _vars_eq
--- Completion/Builtins/_vars_eq	2000/04/17 08:22:44	1.3
+++ Completion/Builtins/_vars_eq	2000/05/09 16:45:53
@@ -1,9 +1,70 @@
-#compdef declare export integer local readonly typeset
+#compdef declare export integer float local readonly typeset
 
-if [[ "$PREFIX" = *\=* ]]; then
-  compstate[parameter]="${PREFIX%%\=*}"
-  compset -P 1 '*='
-  _value
-else
-  _parameters -q -S '='
+local expl state line func i use curcontext="$curcontext"
+local -A allargs
+local -a args
+
+allargs=( \
+  A '(-E -F -L -R -T -U -Z -a -f -i -m)-A[specify that arguments refer to associative arrays]' \
+  E '(-A -F -L -R -T -U -Z -a -f -i -m)-E[represent internally as floating point, use engineering notation on output]' \
+  F '(-A -E -L -R -T -U -Z -a -f -i -m)-F[represent internally as floating point, use fixed point decimal on output]' \
+  L '(-A -E -F -f -i)-L+[left justify and remove leading blanks from value]:width' \
+  R '(-A -E -F -f -i)-R+[right justify and fill with leading blanks]:width' \
+  T '(-A -E -F -a -f -g -h -i -l -m -t)-T[tie scalar to array]' \
+  U '(-A -E -F -i)-U[keep array values unique and suppress alias expansion for functions]' \
+  Uf '(-E -F -i)-U[suppress alias expansion for functions]' \
+  Up '(-E -F -i)-U[keep array values unique]' \
+  Z '(-A -E -F -f -i)-Z+[right justify and fill with leading zeros]:width' \
+  a '(-A -E -F -T -f -i)-a[specify that arguments refer to arrays]' \
+  f '(-A -E -F -L -R -T -Z -a -g -h -i -l -r -x)-f[specify that arguments refer to functions]' \
+  g '(-T -f)-g[do not restrict parameter to local scope]' \
+  h '(-T -f)-h[hide parameter]' \
+  i '(-A -E -F -T -f)-i[represent internally as an integer]' \
+  l '(-T -f)-l[convert the value to lowercase]' \
+  m '(-A -E -F -T -i)-m[treat arguments as patterns]' \
+  r '(-f)-r[mark parameters as readonly]' \
+  t '(-T)-t[tag parameters and turn on execution tracing for functions]' \
+  tf '(-T)-t[turn on execution tracing for functions]' \
+  tp '(-T)-t[tag parameters]' \
+  u '-u[convert the value to uppercase or mark function for autoloading]' \
+  uf '-u[mark function for autoloadling]' \
+  up '-u[convert the value to uppercase]' \
+  x '(-f)-x[export parameter]' )
+
+use="AEFLRTUZafghilmrtux"
+
+case ${words[1]} in
+  float) use="EFghlrtux";;
+  functions)
+    use="Umtu"
+    func=f
+  ;;
+  integer) use="ghlrtux" ;;
+  readonly) use="${use/r/}" ;;
+  local) use="${use/f/}" ;&
+  export) use="${${use/g/}/x/}" ;;
+esac
+
+[[ -z "${words[(r)-*f*]]}" ]] || func=f
+[[ -z "${words[(r)-*[aA]*]}" ]] || func=p
+   
+for ((i=1;i<=$#use;++i)); do
+  args=( "${args[@]}" \
+      ${allargs[${use[$i]}${${(s::)use[$i]}[(r)[Uut]]:+$func}]} )
+done
+
+_arguments -C -s "${args[@]}" '*:vars:->vars_eq'
+
+if [[ "$state" = vars_eq ]]; then
+  if [[ $func = f ]]; then
+    _functions
+  elif [[ "$PREFIX" = *\=* ]]; then
+    compstate[parameter]="${PREFIX%%\=*}"
+    compset -P 1 '*='
+    _value
+  elif (( $+opt_args[-a] || $+opt_args[-A] )); then
+    _parameters -q
+  else
+    _parameters -q -S '='
+  fi
 fi


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

* Re: PATCH: arguments for typeset (and variants)
@ 2000-05-10  8:18 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2000-05-10  8:18 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> ...
> 
> I had a few problems with the + options in _vars_eq but I must have been
> doing something wrong. There should be +g, +h, +r, +t, +x (any maybe
> some others) options but when I put them in the completion spec as
> something like '(-f)-+x[ex...', completion for typeset hangs zsh.

No, my fault. The -+ works by using the spec twice, but it used the
whole spec, not only the `-+...' part.

Bye
 Sven

Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.15
diff -u -r1.15 computil.c
--- Src/Zle/computil.c	2000/05/09 09:05:36	1.15
+++ Src/Zle/computil.c	2000/05/10 08:16:57
@@ -651,7 +651,7 @@
 	    Caopt opt;
 	    Caarg oargs = NULL;
 	    int multi, otype = CAO_NEXT, again = 0;
-	    char *name, *descr, c;
+	    char *name, *descr, c, *againp = NULL;
 
 	    rec:
 
@@ -665,6 +665,7 @@
 		p[2] != '=' && p[2] != '-' && p[2] != '+') {
 		/* It's a -+ or +- definition. We just execute the whole
 		 * stuff twice for such things. */
+		againp = dupstring(p);
 		name = ++p;
 		*p = (again ? '-' : '+');
 		again++;
@@ -838,7 +839,7 @@
 
 	    if (again == 1) {
 		/* Do it all again for `*-...'. */
-		p = dupstring(*args);
+		p = againp;
 		goto rec;
 	    }
 	} else if (*p == '*') {

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


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

end of thread, other threads:[~2000-05-10  8:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-09 16:50 PATCH: arguments for typeset (and variants) Oliver Kiddle
2000-05-10  8:18 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).