about summary refs log tree commit diff
path: root/Completion/Base
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-07-11 08:22:02 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-07-11 08:22:02 +0000
commit027604400ba98f4c947784fc691dc7c93b9bf366 (patch)
tree96072e9c3b307111e1aaf8ca92c2c75570aa78f3 /Completion/Base
parent1f62b5acbe4a6e5c2c1f704ab1dcfd207afe9919 (diff)
downloadzsh-027604400ba98f4c947784fc691dc7c93b9bf366.tar.gz
zsh-027604400ba98f4c947784fc691dc7c93b9bf366.tar.xz
zsh-027604400ba98f4c947784fc691dc7c93b9bf366.zip
15352,15357
Diffstat (limited to 'Completion/Base')
-rw-r--r--Completion/Base/Completer/_prefix59
1 files changed, 59 insertions, 0 deletions
diff --git a/Completion/Base/Completer/_prefix b/Completion/Base/Completer/_prefix
new file mode 100644
index 000000000..3ec153245
--- /dev/null
+++ b/Completion/Base/Completer/_prefix
@@ -0,0 +1,59 @@
+#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 suf="$SUFFIX" \
+      _completer _completer_num \
+      _matcher _c_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
+  _matcher=''
+  for _c_matcher in "$_matchers[@]"; do
+    if [[ "$_c_matcher" == +* ]]; then
+      _matcher="$_matcher $_c_matcher[2,-1]"
+    else
+      _matcher="$_c_matcher"
+    fi
+
+    if [[ "$tmp" != _prefix ]] && "$tmp"; then
+      [[ compstate[nmatches] -gt 1 ]] && return 0
+      compadd -U -i "$IPREFIX" -I "$ISUFFIX" - "${compstate[unambiguous]%$suf}x"
+      compstate[list]=
+      compstate[insert]=unambiguous
+      return 0
+    fi
+    (( _matcher_num++ ))
+  done
+  (( _completer_num++ ))
+done
+
+return 1