about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2003-03-13 18:37:34 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2003-03-13 18:37:34 +0000
commit9cd59570345a3db2b58ead9816fc16b307b0b55e (patch)
tree57f58a57f06e7f785c1d83570cce27af44c9d34e
parent5ba6538fb3146f1ce00c4970a8fb0e6830bf6de4 (diff)
downloadzsh-9cd59570345a3db2b58ead9816fc16b307b0b55e.tar.gz
zsh-9cd59570345a3db2b58ead9816fc16b307b0b55e.tar.xz
zsh-9cd59570345a3db2b58ead9816fc16b307b0b55e.zip
18347: fix problems with having more than one ((val\:desc ...)) style action
-rw-r--r--ChangeLog5
-rw-r--r--Completion/Base/Utility/_alternative81
2 files changed, 86 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6a877e3e9..e05b8f3b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-03-13  Oliver Kiddle  <opk@zsh.org>
+
+	* 18347: Completion/Base/Utility/_alternative: fix problems
+	with having more than one ((val\:desc ...)) style action
+
 2003-03-07  Peter Stephenson  <pws@csr.com>
 
 	* 18325: Src/Modules/parameter.c: options on by default weren't
diff --git a/Completion/Base/Utility/_alternative b/Completion/Base/Utility/_alternative
new file mode 100644
index 000000000..f26e8f354
--- /dev/null
+++ b/Completion/Base/Utility/_alternative
@@ -0,0 +1,81 @@
+#autoload
+
+local tags def expl descr action mesgs nm="$compstate[nmatches]" subopts
+local opt ws curcontext="$curcontext"
+
+subopts=()
+while getopts 'O:C:' opt; do
+  case "$opt" in
+  O) subopts=( "${(@P)OPTARG}" ) ;;
+  C) curcontext="${curcontext%:*}:$OPTARG" ;;
+  esac
+done
+
+shift OPTIND-1
+
+[[ "$1" = -(|-) ]] && shift
+
+mesgs=()
+
+_tags "${(@)argv%%:*}"
+
+while _tags; do
+  for def; do
+    if _requested "${def%%:*}"; then
+      descr="${${def#*:}%%:*}"
+      action="${def#*:*:}"
+
+      _description "${def%%:*}" expl "$descr"
+
+      if [[ "$action" = \ # ]]; then
+
+        # An empty action means that we should just display a message.
+
+        mesgs=( "$mesgs[@]" "$descr")
+      elif [[ "$action" = \(\(*\)\) ]]; then
+
+        # ((...)) contains literal strings with descriptions.
+
+        eval ws\=\( "${action[3,-3]}" \)
+
+        _describe -t "${def%%:*}" "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]"
+      elif [[ "$action" = \(*\) ]]; then
+
+        # Anything inside `(...)' is added directly.
+
+        _all_labels "${def%%:*}" expl "$descr" \
+            compadd "$subopts[@]" - ${=action[2,-2]}
+      elif [[ "$action" = \{*\} ]]; then
+
+        # A string in braces is evaluated.
+
+        while _next_label "${def%%:*}" expl "$descr"; do
+          eval "$action[2,-2]"
+        done
+      elif [[ "$action" = \ * ]]; then
+
+        # If the action starts with a space, we just call it.
+
+        eval "action=( $action )"
+        while _next_label "${def%%:*}" expl "$descr"; do
+          "$action[@]"
+        done
+      else
+
+        # Otherwise we call it with the description-arguments built above.
+
+        eval "action=( $action )"
+	while _next_label "${def%%:*}" expl "$descr"; do
+          "$action[1]" "$subopts[@]" "$expl[@]" "${(@)action[2,-1]}"
+        done
+      fi
+    fi
+  done
+  [[ nm -ne compstate[nmatches] ]] && return 0
+done
+
+for descr in "$mesgs[@]"; do
+  _message "$descr"
+done
+
+return 1