about summary refs log tree commit diff
path: root/Completion/Commands/_complete_help
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Commands/_complete_help')
-rw-r--r--Completion/Commands/_complete_help73
1 files changed, 59 insertions, 14 deletions
diff --git a/Completion/Commands/_complete_help b/Completion/Commands/_complete_help
index cfefdcf90..cfc922df5 100644
--- a/Completion/Commands/_complete_help
+++ b/Completion/Commands/_complete_help
@@ -1,35 +1,80 @@
 #compdef -k complete-word \C-xh
 
 _complete_help() {
-  local _sort_tags=_help_sort_tags text i
-  typeset -A help_tags
-  typeset -U help_contexts
-
-  help_contexts=()
+  local _sort_tags=_help_sort_tags text i j k
+  typeset -A help_funcs help_tags help_sfuncs help_styles
 
   compadd() { return 1 }
+  zstyle() {
+    local _f="${${(@)${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}% *}"
+
+    [[ -z "$_f" ]] && _f="${${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}"
+
+    if [[ "$help_sfuncs[$2]" != *${_f}* ||
+          "$help_styles[${2}${_f}]" != *${3}* ]]; then
+      [[ "$help_sfuncs[$2]" != *${_f}* ]] &&
+          help_sfuncs[$2]="${help_sfuncs[$2]}:${_f}"
+      local _t
+
+      case "$1" in
+      -s) _t='[string] ';;
+      -a) _t='[array]  ';;
+      -h) _t='[assoc]  ';;
+      *)  _t='[boolean]';;
+      esac
+      help_styles[${2}${_f}]="${help_styles[${2}${_f}]},${_t} ${3}:${_f}"
+    fi
+    builtin zstyle "$@"
+  }
 
   _main_complete
 
-  unfunction compadd
+  unfunction compadd zstyle
 
-  for i in "$help_contexts[@]"; do
+  for i in "${(@ok)help_funcs}"; do
     text="${text}
-tags in context \`${i}': ${help_tags[$i]}"
+tags in context :completion:${i}:"
+    tmp=()
+    for j in "${(@s.:.)help_funcs[$i][2,-1]}"; do
+      tmp=( "$tmp[@]" "${(@s.,.)help_tags[${i}${j}][2,-1]}" )
+    done
+    zformat -a tmp '  (' "$tmp[@]"
+    tmp=( '
+    '${^tmp}')' )
+    text="${text}${tmp}"
   done
 
-  compstate[list]=list
-  compstate[force_list]=yes
+  text="$text
+"
+  for i in "${(@ok)help_sfuncs}"; do
+    text="${text}
+styles in context ${i}"
+    tmp=()
+    for j in "${(@s.:.)help_sfuncs[$i][2,-1]}"; do
+      tmp=( "$tmp[@]" "${(@s.,.)help_styles[${i}${j}][2,-1]}" )
+    done
+    zformat -a tmp '  (' "$tmp[@]"
+    tmp=( '
+    '${^tmp}')' )
+    text="${text}${tmp}"
+  done
+
+  compstate[list]='list force'
   compstate[insert]=''
 
   compadd -UX "$text[2,-1]" -n ''
 }
 
 _help_sort_tags() {
-  help_contexts=( "$help_contexts[@]" "$curcontext" )
-  help_tags[$curcontext]="${help_tags[$curcontext]}
-    ${argv}"
-  comptry "$@"
+  local f="${${(@)${(@)funcstack[3,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}% *}"
+
+  if [[ "$help_funcs[$curcontext]" != *${f}* ||
+        "$help_tags[${curcontext}${f}]" != *(${(j:|:)~argv})* ]]; then
+    [[ "$help_funcs[$curcontext]" != *${f}* ]] &&
+        help_funcs[$curcontext]="${help_funcs[$curcontext]}:${f}"
+    help_tags[${curcontext}${f}]="${help_tags[${curcontext}${f}]},${argv}:${f}"
+    comptry "$@"
+  fi
 }
 
 _complete_help "$@"