1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-28 05:00:59 +01:00

zsh-workers/8442

This commit is contained in:
Tanaka Akira 1999-10-27 14:07:47 +00:00
parent f02f5b7f36
commit 0721143c49
2 changed files with 72 additions and 10 deletions

View file

@ -1786,4 +1786,32 @@ item(tt(incremental_list))(
If set to a non-empty string, the matches will be listed on every If set to a non-empty string, the matches will be listed on every
key-press. key-press.
) )
item(tt(predict_completer))(
The keys starting with tt(predict_) are used by the functions in the
tt(predict-on) file in the tt(Functions/Zle) directory of the tt(zsh)
source distribution.
A colon separated list of completer functions (like the tt(completer)
key for normal completion) to be used when attempting completion.
)
item(tt(predict_cursor))(
This describes where the cursor should be left after completion was
attempted. If it is set to `tt(complete)' the cursor is left where
completion put it if it is after the character typed, otherwise this
behaves like the value `tt(key)'. If it is set to `tt(key)' the
prediction function will try to place the cursor after the character
which corresponds to the last character typed. This is useful if one
uses global match specifications with patterns for partial word
completion. If no sensible place could be found or this configuration
key is set to any other value (or unset), the cursor is moved back to
the original position. With global match specifications as described
above this sometimes means that the character typed does not appear on
the line.
)
item(tt(predict_list))(
If this is set to `tt(always)' the list of possible matches when
completion was tried will always be shown, even if there is only one
match. Otherwise the listing behavior is as usual, i.e. the list will
only be shown if there are multiple matches.
)
enditem() enditem()

View file

@ -23,17 +23,28 @@
# Note that all functions are defined when you first type the predict-on # 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 # key, which means typing the predict-off key before that gives a harmless
# error message. # error message.
#
# This uses the configuration keys starting with `predict_'.
predict-on() { predict-on() {
zle -N self-insert insert-and-predict zle -N self-insert insert-and-predict
zle -N magic-space insert-and-predict zle -N magic-space insert-and-predict
zle -N backward-delete-char delete-backward-and-predict zle -N backward-delete-char delete-backward-and-predict
zle -N delete-char-or-list delete-no-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() { predict-off() {
zle -A .self-insert self-insert zle -A .self-insert self-insert
zle -A .magic-space magic-space zle -A .magic-space magic-space
zle -A .backward-delete-char backward-delete-char zle -A .backward-delete-char backward-delete-char
[[ -n $_predict_am ]] && setopt automenu
} }
insert-and-predict () { insert-and-predict () {
emulate -L zsh emulate -L zsh
@ -50,11 +61,33 @@ insert-and-predict () {
RBUFFER="" RBUFFER=""
if [[ ${KEYS[-1]} != ' ' ]] if [[ ${KEYS[-1]} != ' ' ]]
then then
integer curs=$CURSOR integer curs=$CURSOR pos nchar=${#LBUFFER//[^${KEYS[-1]}]}
local -a +h comppostfuncs local -a +h comppostfuncs
comppostfuncs=( predict-limit-list ) comppostfuncs=( predict-limit-list )
zle complete-word zle complete-word ${(s.:.)compconfig[predict_completer]}
CURSOR=$curs # 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 fi
fi fi
@ -91,6 +124,7 @@ predict-limit-list() {
compstate[list]='' compstate[list]=''
compstate[force_list]=yes compstate[force_list]=yes
fi fi
[[ $compconfig[predict_list] = always ]] && compstate[force_list]=yes
} }
# Handle zsh autoloading conventions # Handle zsh autoloading conventions