about summary refs log tree commit diff
path: root/Completion/Core/_tags
blob: 2dfa56f9d6b3e2f7577477966e519969d77735c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#autoload

local prev

# A `--' as the first argument says that we should tell comptags to use
# the preceding function nesting level. This is only documented here because
# if everythings goes well, users won't have to worry about it and should
# not mess with it.

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

if (( $# )); then

  # We have arguments: the tags supported in this context.

  local curcontext="$curcontext" order tag nodef

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

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

  if zstyle -a ":completion:${curcontext}:" group-order order; then
    local name

    for name in "$order[@]"; do
      compadd -J "$name"
      compadd -V "$name"
      compadd -J "$name" -1
      compadd -V "$name" -1
      compadd -J "$name" -2
      compadd -V "$name" -2
    done
  fi

  # Set and remember offered tags.

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

  # Sort the tags.

  if [[ -n "$_sort_tags" ]]; then
    "$_sort_tags" "$@"
  elif zstyle -a ":completion:${curcontext}:" tag-order order; then

    for tag in $order; do
      case $tag in
      -)     nodef=yes;;
      *\(\)) if ! "${${tag%%[ 	]#\(\)}##[ 	]#}" "$@"; then
               nodef=yes
               break
             fi
             ;;
      \!*)   comptry "${(@)argv:#(${(j:|:)~${=tag[2,-1]}})}";;
      ?*)    comptry ${${(ps: :)${tag//\\\\ /$'\0'}}//$'\0'/ };;
      esac
    done

    if [[ -z "$nodef" ]]; then
      if (( $+_comp_default_tags )); then
        for tag in "$_comp_default_tags[@]"; do
          comptry "$tag"
        done
      else
        comptry "$@"
      fi
    fi
  else

    # Use default tags...

    if (( $+_comp_default_tags )); then
      for tag in "$_comp_default_tags[@]"; do
        comptry "$tag"
      done
    else
      comptry arguments values
      comptry options
    fi
    comptry "$@"
  fi

  # Return non-zero if at least one set of tags should be used.

  comptags "-T$prev"

  return
fi

# The other mode: switch to the next set of tags.

comptags "-N$prev"