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

PATCH: limit functions +/-blah completion



This is supposed to improve completion after "functions" so that, for
example, "functions +T <tab>" only completes functions where the -T
option has been set.  It relies on the last patch I posted.

Index: Completion/Zsh/Command/_typeset
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_typeset,v
retrieving revision 1.5
diff -p -u -r1.5 _typeset
--- Completion/Zsh/Command/_typeset	22 Apr 2012 18:10:43 -0000	1.5
+++ Completion/Zsh/Command/_typeset	22 Feb 2013 21:20:48 -0000
@@ -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

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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