summary refs log tree commit diff
path: root/Completion/Base
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-04-26 12:13:36 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-04-26 12:13:36 +0000
commitaa99b19c088324b17c0c5e1caee4fc3b5777deab (patch)
tree6489214ac325f9b473c254fb8f8c545b3255855d /Completion/Base
parent105009726b3276a16ad39930aba046032597a039 (diff)
downloadzsh-aa99b19c088324b17c0c5e1caee4fc3b5777deab.tar.gz
zsh-aa99b19c088324b17c0c5e1caee4fc3b5777deab.tar.xz
zsh-aa99b19c088324b17c0c5e1caee4fc3b5777deab.zip
rename -W option to -w, add new -W option which makes _arguments complete options even after options that get their argument in the same word; new _guard function for conditionally displaying messages (14105)
Diffstat (limited to 'Completion/Base')
-rw-r--r--Completion/Base/Utility/_arguments34
-rw-r--r--Completion/Base/Utility/_guard17
2 files changed, 38 insertions, 13 deletions
diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments
index 1c5411fe3..c68700763 100644
--- a/Completion/Base/Utility/_arguments
+++ b/Completion/Base/Utility/_arguments
@@ -4,7 +4,7 @@
 # descriptions given as arguments to this function.
 
 local long cmd="$words[1]" descr mesg subopts opt usecc autod
-local oldcontext="$curcontext" hasopts rawret optarg singopt
+local oldcontext="$curcontext" hasopts rawret optarg singopt alwopt
 
 long=$argv[(I)--]
 if (( long )); then
@@ -174,21 +174,22 @@ fi
 
 subopts=()
 singopt=()
-while [[ "$1" = -(O*|[CRWs]) ]]; do
+while [[ "$1" = -(O*|[CRWsw]) ]]; do
   case "$1" in
   -C)  usecc=yes; shift ;;
   -O)  subopts=( "${(@P)2}" ); shift 2 ;;
   -O*) subopts=( "${(@P)1[3,-1]}" ); shift ;;
   -R)  rawret=yes; shift;;
-  -W)  optarg=yes; shift;;
+  -w)  optarg=yes; shift;;
   -s)  singopt=(-s); shift;;
+  -W)  alwopt=yes; shift;;
   esac
 done
 
 zstyle -s ":completion:${curcontext}:options" auto-description autod
 
 if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then
-  local action noargs aret expl local tried
+  local action noargs aret expl local tried ret=1
   local next direct odirect equal single matcher matched ws tmp1 tmp2 tmp3
   local opts subc tc prefix suffix descrs actions subcs anum
   local origpre="$PREFIX" origipre="$IPREFIX" nm="$compstate[nmatches]"
@@ -280,7 +281,8 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then
 
               eval ws\=\( "${action[3,-3]}" \)
 
-              _describe -t "$subc" "$descr" ws -M "$matcher" "$subopts[@]"
+              _describe -t "$subc" "$descr" ws -M "$matcher" "$subopts[@]" ||
+                  alwopt=yes
 	      tried=yes
 
             elif [[ "$action" = \(*\) ]]; then
@@ -289,15 +291,17 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then
 
               eval ws\=\( "${action[2,-2]}" \)
 
-              _all_labels "$subc" expl "$descr" compadd "$subopts[@]" -a - ws
+              _all_labels "$subc" expl "$descr" compadd "$subopts[@]" -a - ws ||
+                  alwopt=yes
 	      tried=yes
             elif [[ "$action" = \{*\} ]]; then
 
               # A string in braces is evaluated.
 
               while _next_label "$subc" expl "$descr"; do
-                eval "$action[2,-2]"
+                eval "$action[2,-2]" && ret=0
               done
+              (( ret )) && alwopt=yes
 	      tried=yes
             elif [[ "$action" = \ * ]]; then
 
@@ -305,8 +309,9 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then
 
 	      eval "action=( $action )"
               while _next_label "$subc" expl "$descr"; do
-                "$action[@]"
+                "$action[@]" && ret=0
               done
+              (( ret )) && alwopt=yes
 	      tried=yes
             else
 
@@ -314,15 +319,17 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then
 
 	      eval "action=( $action )"
               while _next_label "$subc" expl "$descr"; do
-                "$action[1]" "$subopts[@]" "$expl[@]" "${(@)action[2,-1]}"
+                "$action[1]" "$subopts[@]" "$expl[@]" "${(@)action[2,-1]}" && ret=0
 	      done
+              (( ret )) && alwopt=yes
 	      tried=yes
             fi
           fi
         fi
       done
-
-      if [[ -z "$matched$hasopts" && ( -z "$aret" || "$PREFIX" = "$origpre" ) ]] &&
+      if [[ -z "$hasopts" &&
+            ( -z "$matched" || -n "$alwopt" ) &&
+            ( -z "$aret" || "$PREFIX" = "$origpre" ) ]] &&
           _requested options &&
           { ! zstyle -T ":completion:${curcontext}:options" prefix-needed ||
             [[ "$origpre" = [-+]* || -z "$aret$mesg$tried" ]] } ; then
@@ -378,9 +385,10 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then
 	PREFIX="$prevpre"
 	IPREFIX="$previpre"
       fi
-      [[ -n "$tried" && "$PREFIX" != [-+]* ]] && break
+      [[ -n "$tried" && "${${alwopt:+$origpre}:-$PREFIX}" != [-+]* ]] && break
     done
-    if [[ -n "$opts" && -z "$aret$matched$mesg" &&
+    if [[ -n "$opts" && -z "$aret" &&
+          ( -z "$matched$mesg" || -n "$alwopt" ) &&
           nm -eq compstate[nmatches] ]]; then
 
       PREFIX="$origpre"
diff --git a/Completion/Base/Utility/_guard b/Completion/Base/Utility/_guard
new file mode 100644
index 000000000..4c07fe1b9
--- /dev/null
+++ b/Completion/Base/Utility/_guard
@@ -0,0 +1,17 @@
+#autoload
+
+local mesg pat garbage
+
+mesg=()
+zparseopts -K -D -a garbage M: J: V: 1 2 n F: X:=mesg 
+
+[[ "$PREFIX$SUFFIX" != $~1 ]] && return 1
+
+if [[ $# -gt 1 || $#mesg -eq 0 ]]; then
+  shift
+  _message "$*"
+else
+  _message -r "$mesg[2]"
+fi
+
+[[ -n "$PREFIX$SUFFIX" ]]