about summary refs log tree commit diff
path: root/Completion/Core/_prefix
blob: 18e6e32704063a63f53beca1f2e8270dc5872766 (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
#autoload

# Try to ignore the suffix. A bit like e-o-c-prefix.

[[ _matcher_num -gt 1 || -z "$SUFFIX" ]] && return 1

local comp curcontext="$curcontext" tmp \
      _completer _completer_num _matcher _matchers _matcher_num

zstyle -a ":completion:${curcontext}:" completer comp ||
  comp=( "${(@)_completers[1,_completer_num-1][(R)_prefix(|:*),-1]}" )

if zstyle -t ":completion:${curcontext}:" add-space; then
  ISUFFIX=" $SUFFIX"
else
  ISUFFIX="$SUFFIX"
fi
SUFFIX=''

_completer_num=1

for tmp in "$comp[@]"; do
  if [[ "$tmp" = *:-* ]]; then
    _completer="${${tmp%:*}[2,-1]//_/-}${tmp#*:}"
    tmp="${tmp%:*}"
  elif [[ $tmp = *:* ]]; then
    _completer="${tmp#*:}"
    tmp="${tmp%:*}"
  else
    _completer="${tmp[2,-1]//_/-}"
  fi
  curcontext="${curcontext/:[^:]#:/:${_completer}:}"

  zstyle -a ":completion:${curcontext}:" matcher-list _matchers ||
      _matchers=( '' )

  _matcher_num=1
  for _matcher in "$_matchers[@]"; do
    [[ "$tmp" != _prefix ]] && "$tmp" && return 0
    (( _matcher_num++ ))
  done
  (( _completer_num++ ))
done

return 1