zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: use _arguments in _which and _unhash
@ 2000-05-28 17:35 Oliver Kiddle
  2000-05-28 20:52 ` PATCH: _arguments (Re: PATCH: use _arguments in _which and _unhash) Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Kiddle @ 2000-05-28 17:35 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> I can reproduce this, but
> 
> } % zpty -w l <tab>
> } _arguments:shift:297: shift count must be <= $#
> 
> I can't reproduce that.

Are you sure? I can reproduce it on different platforms and when
starting with zsh -f. Maybe one of your options avoids it.

Totally unrelated to this, I've changed a couple more of the
completion functions to use _arguments (which and unhash).

Oliver


--- Completion/Builtins/_unhash	Thu Dec 30 18:28:37 1999
+++ Completion/Builtins/_unhash	Sun May 28 16:45:29 2000
@@ -1,14 +1,14 @@
 #compdef unhash
 
-local fl="$words[2]" args
+local expl state line curcontext="$curcontext"
 
-args=()
-[[ "$fl" = -*d* ]] &&
-    args=( 'named-directories:named directory:compadd - ${(@k)nameddirs}' )
-[[ "$fl" = -*a* ]] &&
-    args=( "$args[@]"
-           'aliases:alias:compadd - ${(@k)aliases} ${(@k)galiases} ${(@k)dis-aliases} ${(@k)dis-galiases}' )
-[[ "$fl" != -* ]] &&
-    args=( 'commands:: _command_names -e' )
+_arguments -C -s \
+  '(-a -f *)-d[remove named directories]:*:named directory:->nameddir' \
+  '(-d -f *)-a[remove aliases]:*:aliases:_aliases' \
+  '(-d -a *)-f[remove functions]:*:functions:_functions' \
+  '-m[treat arguments as patterns]' \
+  '*:commands:_command_names -e'  && return 0
 
-_alternative "$args[@]"
+if [[ "$state" = nameddir ]]; then
+  _wanted nameddir expl 'named directory' compadd - ${(@k)nameddirs}
+fi
--- Completion/Builtins/_which.bak	Mon Nov 15 12:01:47 1999
+++ Completion/Builtins/_which	Sun May 28 15:50:57 2000
@@ -1,6 +1,29 @@
 #compdef which whence where type
 
-local args
+local farg aarg cargs args state line curcontext="$curcontext"
+
+cargs=( \
+  '(-v -c)-w[print command type]' \
+  '-p[always do a path search]' \
+  '-m[treat the arguments as patterns]' \
+  '-s[print symlink free path as well]' \
+  '*:commands:->command' )
+farg='-f[output contents of functions]'
+aarg='-a[print all occurences in path]'
+
+case ${words[1]} in
+  whence)
+    _arguments -C -s \
+      '(-c -w)-v[verbose output]' \
+      '(-v -w)-c[csh-like output]' \
+      "${cargs[@]}" "$farg" "$aarg" && return 0
+  ;;
+  where) _arguments -C -s "${cargs[@]}" && return 0;;
+  which) _arguments -C -s "${cargs[@]}" "$aarg" && return 0;;
+  type) _arguments -C -s "${cargs[@]}" "$aarg" "$farg" && return 0;;
+esac
+
+if [[ "$state" = command ]]; then
 
 args=( "$@" )
 
@@ -10,3 +33,5 @@
   'functions:shell function:compadd - ${(k@)functions}' \
   'aliases:alias:compadd - ${(k@)aliases}' \
   'reserved-words:reserved word:compadd - ${(k@)reswords}'
+
+fi



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

* PATCH: _arguments (Re: PATCH: use _arguments in _which and _unhash)
  2000-05-28 17:35 PATCH: use _arguments in _which and _unhash Oliver Kiddle
@ 2000-05-28 20:52 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2000-05-28 20:52 UTC (permalink / raw)
  To: zsh-workers

On May 28,  6:35pm, Oliver Kiddle wrote:
} Subject: PATCH: use _arguments in _which and _unhash
}
} Bart Schaefer wrote:
} 
} > } % zpty -w l <tab>
} > } _arguments:shift:297: shift count must be <= $#
} > 
} > I can't reproduce that.
} 
} Are you sure? I can reproduce it on different platforms and when
} starting with zsh -f. Maybe one of your options avoids it.

Yup, you're right, I can reproduce it with -f.

Is there a more efficient fix than the following?  (This relies on the
first argument of shift being interpreted as a math expression.)

Index: Completion/Base/_arguments
===================================================================
@@ -285,7 +285,7 @@
 
               # Otherwise we call it with the description-arguments.
 
-              eval "action=( $action )"
+              set -A action ${=~action}
               while _next_label "$subc" expl "$descr"; do
                 "$action[1]" "$subopts[@]" "$expl[@]" "${(@)action[2,-1]}"
 	      done
@@ -293,9 +293,9 @@
             fi
           fi
         fi
-        shift 1 descrs
-        shift 1 actions
-        shift 1 subcs
+        shift "${#descrs} ? 1 : 0" descrs
+        shift "${#actions} ? 1 : 0" actions
+        shift "${#subcs} ? 1 : 0" subcs
       done
 
       if [[ -z "$matched$hasopts" ]] && _requested options &&

-- 
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] 2+ messages in thread

end of thread, other threads:[~2000-05-28 20:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-28 17:35 PATCH: use _arguments in _which and _unhash Oliver Kiddle
2000-05-28 20:52 ` PATCH: _arguments (Re: PATCH: use _arguments in _which and _unhash) Bart Schaefer

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