summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2013-02-22 21:58:16 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2013-02-22 21:58:16 +0000
commita45b45eeabe6325ba1c00deaccafd1ec64cdc981 (patch)
treeab856dfe4d214c0614df40f897a81f7fd816a8d5
parentfeb6b8b7b16aa4601d29ea44b2452beeeb91af53 (diff)
downloadzsh-a45b45eeabe6325ba1c00deaccafd1ec64cdc981.tar.gz
zsh-a45b45eeabe6325ba1c00deaccafd1ec64cdc981.tar.xz
zsh-a45b45eeabe6325ba1c00deaccafd1ec64cdc981.zip
31061: "functions" completion takes account of options already
on the command line
-rw-r--r--ChangeLog4
-rw-r--r--Completion/Zsh/Command/_typeset28
2 files changed, 28 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index f9b7c9081..7a634d4fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
 2013-02-22  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* 31061: Completion/Zsh/Command/_typeset: "functions" completion
-	takes accout of options already on the command line.
+	takes account of options already on the command line.
 
 	* 31060: Src/builtin.c: "+" before a flag for "functions" or
 	"autoload" should suppress display of function body.
@@ -540,5 +540,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5806 $
+* $Revision: 1.5807 $
 *****************************************************
diff --git a/Completion/Zsh/Command/_typeset b/Completion/Zsh/Command/_typeset
index d44783d64..0920e3fb5 100644
--- a/Completion/Zsh/Command/_typeset
+++ b/Completion/Zsh/Command/_typeset
@@ -12,7 +12,9 @@ allargs=(
   F "($fopts -A -E -L -R -T -U -Z -a -i -m)-F[floating point, use fixed point decimal on output]"
   L "($fopts -A -E -F -i)-L+[left justify and remove leading blanks from value]:width"
   R "($fopts -A -E -F -i)-R+[right justify and fill with leading blanks]:width"
-  T "($fopts -A -E -F -a -g -h -i -l -m -t)-T[tie scalar to array]"
+  T "($fopts -A -E -F -a -g -h -i -l -m -t)-T[tie scalar to array or trace function]"
+  Tf "($popts -t)-T[trace execution of this function only]"
+  Tp "($fopts -A -E -F -a -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 '-U[suppress alias expansion for functions]'
   Up '(-E -F -i)-+U[keep array values unique]'
@@ -49,7 +51,7 @@ case ${service} in
   ;;
   float) use="EFHghlprtux";;
   functions)
-    use="Ukmtuz"
+    use="UkmTtuz"
     func=f
   ;;
   integer)
@@ -64,6 +66,12 @@ esac
 [[ -z "${words[(r)-*[aA]*]}" ]] || func=p
 [[ -z "${words[(r)-*f*]}" ]] || func=f
 
+# This function uses whacky features of _arguments which means we
+# need to look for options to the command beforehand.
+local onopts offopts
+onopts=${(j..)${${words[1,CURRENT-1]:#^-*}##-}}
+offopts=${(j..)${${words[1,CURRENT-1]:#^+*}##+}}
+
 for ((i=1;i<=$#use;++i)); do
   args+=( ${allargs[${use[$i]}${${(s::)use[$i]}[(r)[Uut]]:+$func}]} )
 done
@@ -81,6 +89,22 @@ if [[ "$state" = vars_eq ]]; then
       funckeys=(${(k)functions})
       args=(${args:|funckeys})
       _wanted functions expl 'shell function' compadd -a args
+    elif [[ -n $onopts$offopts ]]; then
+      if [[ -n $offopts ]]; then
+	args=(${(f)"$(functions +$offopts)"})
+      else
+	args=(${(k)functions})
+      fi
+      if [[ -n $onopts ]]; then
+	local -a funckeys
+	funckeys=(${(f)"$(functions +$onopts)"})
+	args=(${args:|funckeys})
+      fi
+      if zstyle -t ":completion:${curcontext}:functions" prefix-needed &&
+	[[ $PREFIX != [_.]* ]]; then
+	args=(${args:#_*})
+      fi
+      _wanted functions expl 'shell functions' compadd -a args
     else
       _functions
     fi