about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-10-27 14:07:47 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-10-27 14:07:47 +0000
commit0721143c491d430068dfa70ac4937afe26229154 (patch)
tree332c693b971d166edda279c2597f12a55e6f1d17 /Functions
parentf02f5b7f362ef6c2e3528c23f89391ca5a71ebf7 (diff)
downloadzsh-0721143c491d430068dfa70ac4937afe26229154.tar.gz
zsh-0721143c491d430068dfa70ac4937afe26229154.tar.xz
zsh-0721143c491d430068dfa70ac4937afe26229154.zip
zsh-workers/8442
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Zle/predict-on54
1 files changed, 44 insertions, 10 deletions
diff --git a/Functions/Zle/predict-on b/Functions/Zle/predict-on
index db129e45c..159f723d4 100644
--- a/Functions/Zle/predict-on
+++ b/Functions/Zle/predict-on
@@ -23,17 +23,28 @@
 # Note that all functions are defined when you first type the predict-on
 # key, which means typing the predict-off key before that gives a harmless
 # error message.
+#
+# This uses the configuration keys starting with `predict_'.
 
 predict-on() {
-    zle -N self-insert insert-and-predict
-    zle -N magic-space insert-and-predict
-    zle -N backward-delete-char delete-backward-and-predict
-    zle -N delete-char-or-list delete-no-predict
+  zle -N self-insert insert-and-predict
+  zle -N magic-space insert-and-predict
+  zle -N backward-delete-char delete-backward-and-predict
+  zle -N delete-char-or-list delete-no-predict
+
+  # Prediction doesn't work well with automenu set, so we unset it here
+  # and restore it in predict-off().
+  if [[ -o automenu ]]; then
+    unsetopt automenu
+    _predict_am=yes
+  fi
 }
 predict-off() {
-    zle -A .self-insert self-insert
-    zle -A .magic-space magic-space
-    zle -A .backward-delete-char backward-delete-char
+  zle -A .self-insert self-insert
+  zle -A .magic-space magic-space
+  zle -A .backward-delete-char backward-delete-char
+
+  [[ -n $_predict_am ]] && setopt automenu
 }
 insert-and-predict () {
   emulate -L zsh
@@ -50,11 +61,33 @@ insert-and-predict () {
 	RBUFFER=""
 	if [[ ${KEYS[-1]} != ' ' ]]
 	then
-	  integer curs=$CURSOR
+	  integer curs=$CURSOR pos nchar=${#LBUFFER//[^${KEYS[-1]}]}
 	  local -a +h comppostfuncs
 	  comppostfuncs=( predict-limit-list )
-	  zle complete-word
-	  CURSOR=$curs
+	  zle complete-word ${(s.:.)compconfig[predict_completer]}
+	  # Decide where to leave the cursor. The dummy loop is used to
+	  # get out of that `case'.
+	  while true; do
+	    case $compconfig[predict_cursor] in
+	    (complete)
+	      # At the place where the completion left it, if it is after
+	      # the character typed.
+	      [[ ${LBUFFER[-1]} = ${KEYS[-1]} ]] && break
+	      ;&
+	    (key)
+	      # Or maybe at the n'th occurrence of the character typed.
+	      pos=${BUFFER[(in:nchar:)${KEYS[-1]}]}
+	      if [[ pos -gt curs ]]; then
+	        CURSOR=$pos
+	        break
+	      fi
+	      ;&
+	    (*)
+	      # Or else at the previous position.
+	      CURSOR=$curs
+	    esac
+	    break
+	  done
 	fi
       fi
     fi
@@ -91,6 +124,7 @@ predict-limit-list() {
     compstate[list]=''
     compstate[force_list]=yes
   fi
+  [[ $compconfig[predict_list] = always ]] && compstate[force_list]=yes
 }
 
 # Handle zsh autoloading conventions