#compdef compdef

local expl func base=2

while [[ $words[base] = -* ]]; do
  case $words[base] in
    -d) delete=yes ;;
    -p) type=pattern ;;
    -k) type=key ;;
  esac  
  (( base++ ))
done

if [ "$delete" ]; then
  _wanted commands expl 'completed command' &&
      compadd "$expl[@]" - ${(k)_comps}
else
  if [[ CURRENT -eq base ]]; then
    _wanted functions expl 'completion function' &&
        compadd "$expl[@]" - ${^fpath:/.}/_(|*[^~])(N:t)
  else
    _command_names
  fi
fi
