#autoload

local prev


if [[ "$1" = -- ]]; then
  prev=-
  shift
fi

if (( $# )); then


  local curcontext="$curcontext" order tag nodef tmp

  if [[ "$1" = -C?* ]]; then
    curcontext="${curcontext%:*}:${1[3,-1]}"
    shift
  elif [[ "$1" = -C ]]; then
    curcontext="${curcontext%:*}:${2}"
    shift 2
  fi

  [[ "$1" = -(|-) ]] && shift

  zstyle -a ":completion:${curcontext}:" group-order order &&
      compgroups "$order[@]"


  comptags "-i$prev" "$curcontext" "$@"


  if [[ -n "$_sort_tags" ]]; then
    "$_sort_tags" "$@"
  else
    zstyle -a ":completion:${curcontext}:" tag-order order ||
        (( ! ${@[(I)options]} )) ||
        order=('(|*-)argument-* (|*-)option[-+]* values' options)

    for tag in $order; do
      case $tag in
      -)     nodef=yes;;
      \!*)   comptry "${(@)argv:#(${(j:|:)~${=~tag[2,-1]}})}";;
      ?*)    comptry -m "$tag";;
      esac
    done

    [[ -z "$nodef" ]] && comptry "$@"
  fi


  comptags "-T$prev"

  return
fi


comptags "-N$prev"
