about summary refs log tree commit diff
path: root/Completion/Core/_display
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-09-14 14:55:37 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-09-14 14:55:37 +0000
commit11ecfb4d94d6aa5dc42156a5e1c57b8d0bfc0223 (patch)
tree09f756cfecb0c20133a6833522742f78d792326b /Completion/Core/_display
parent13862569077a80821c2272e9e484ad6a36010846 (diff)
downloadzsh-11ecfb4d94d6aa5dc42156a5e1c57b8d0bfc0223.tar.gz
zsh-11ecfb4d94d6aa5dc42156a5e1c57b8d0bfc0223.tar.xz
zsh-11ecfb4d94d6aa5dc42156a5e1c57b8d0bfc0223.zip
zsh-workers/7827
Diffstat (limited to 'Completion/Core/_display')
-rw-r--r--Completion/Core/_display96
1 files changed, 26 insertions, 70 deletions
diff --git a/Completion/Core/_display b/Completion/Core/_display
index d23361653..7a1072d92 100644
--- a/Completion/Core/_display
+++ b/Completion/Core/_display
@@ -1,82 +1,38 @@
 #autoload
 
-# This builds a display-list for the `-y' option of `compadd' and
-# `compgen' out of the arguments it gets. The first argument is
-# taken as the name of a parameter and the string built is stored
-# into it.
-# The second argument is the name of an array whose elements each
-# contains a string to complete, optionally followed by a colon
-# and a description. The display list created will contain one
-# line per string with the description after it, all nicely
-# aligned. Strings without descriptions are put at the end in a
-# column-oriented fashion.
-# All arguments after the second one are given as arguments to
-# `compadd'.
-# This function will also do the matching required to find out
-# which strings will be included in the list. All elements that
-# don't match will be removed from the array. This means that the
-# special parameters `PREFIX' and `SUFFIX' have to be set up 
-# correctly before this function is called.
+# This builds a display-list for the `-ld' option of `compadd'
+# out of the arguments it gets. The first argument is taken as
+# the name of a parameter and the array built is stored into it.
+# The other arguments are strings consisting of the match optionally
+# followed by a colon and a description. The display list created
+# will contain one element per match with the description after it,
+# all nicely aligned.
 
-local _param="$1" _arr _len _i _tmp _simple
+local _param="$1" _len _i _tmp _hasd
 
-# Remove all descriptions not matched by the string on the line.
 
-if [[ "${2[1]}" = \( ]]; then
-  _arr=( ${(Qo)=2[2,-2]} )
-else
-  _arr=( "${(@Po)2}" )
-fi
+shift
 
-_arr=( "${(@)_arr:#}" )
-compadd -D _arr "${(@)argv[3,-1]}" - "${(@)_arr%%:*}"
+# First get the length of the longest string (to be able to align them).
 
-[[ "${2[1]}" != \( ]] && eval "${2}=( \"\$_arr[@]\" )"
+_len=-1
+for _i; do
+  _tmp="${#_i%%:*}"
+  [[ "$_i" = *:?* && _tmp -gt _len ]] && _len="$_tmp"
+done
 
-if (( $#_arr )); then
+# Now we build the list in `_tmp'.
 
-  # There are strings left, first get the length of the longest of
-  # them (to be able to align them) and collect all strings without
-  # descriptions.
-
-  _simple=()
-  _len=-1
-  for _i in "$_arr[@]";  do
-    _tmp="${#_i%%:*}"
-    if [[ "$_i" = *:?* ]]; then
-      [[ _tmp -gt _len ]] && _len="$_tmp"
-    else
-      _simple=( "$_simple[@]" "${_i%:}" )
-    fi
-  done
-
-  if [[ _len -lt 0 ]]; then
-    eval "${_param}=''"
-    return 1
+_tmp=()
+for _i; do
+  if [[ "$_i" = *:?* ]]; then
+    _tmp=( "$_tmp[@]" "${(r:_len:: :)_i%%:*} -- ${_i#*:}" )
+    _hasd=yes
+  else
+    _tmp=( "$_tmp[@]" "${_i%:}" )
   fi
+done
 
-  # Now we build the list in `_tmp', adding one line per string.
-
-  _tmp=''
-  for _i in "$_arr[@]"; do
-    [[ "$_i" = *:?* ]] && _tmp="$_tmp
-${(r:_len:: :)_i%%:*} -- ${_i#*:}"
-  done
-
-  # If there were strings without descriptions, we just add them by
-  # calling `print -c'.
-
-  (( $#_simple )) && _tmp="${_tmp}
-$(print -c - $_simple)"
-
-  eval "${_param}=\"\${_tmp[2,-1]}\""
-
-  return 0
-else
-
-  # None of the strings matches what's on the line, signal this by
-  # setting the parameter to an empty string and by the return value.
+eval "${_param}=( \"\$_tmp[@]\" )"
 
-  eval "${_param}=''"
-  return 1
-fi
+[[ -n "$_hasd" ]]