diff options
author | Bart Schaefer <barts@users.sourceforge.net> | 2000-09-04 21:10:29 +0000 |
---|---|---|
committer | Bart Schaefer <barts@users.sourceforge.net> | 2000-09-04 21:10:29 +0000 |
commit | dc1f7c5a3429321b10c6e05c11d99c94ff5c3e87 (patch) | |
tree | 904366741d50f3a05e55ecf909aaf41f14c1380f /Functions/Zle/predict-on | |
parent | 88b886e6034b1902c929eb6e6e2a06b9f4854c03 (diff) | |
download | zsh-dc1f7c5a3429321b10c6e05c11d99c94ff5c3e87.tar.gz zsh-dc1f7c5a3429321b10c6e05c11d99c94ff5c3e87.tar.xz zsh-dc1f7c5a3429321b10c6e05c11d99c94ff5c3e87.zip |
Create "User Contributions" doc and make some assoctiated changes.
Diffstat (limited to 'Functions/Zle/predict-on')
-rw-r--r-- | Functions/Zle/predict-on | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/Functions/Zle/predict-on b/Functions/Zle/predict-on index bd7212050..1ce368bfa 100644 --- a/Functions/Zle/predict-on +++ b/Functions/Zle/predict-on @@ -29,20 +29,27 @@ predict-on() { 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 + zstyle -t :predict verbose && zle -M predict-on + return 0 } predict-off() { zle -A .self-insert self-insert zle -A .magic-space magic-space zle -A .backward-delete-char backward-delete-char + zstyle -t :predict verbose && zle -M predict-off + return 0 } insert-and-predict () { setopt localoptions noshwordsplit noksharrays - if [[ $LBUFFER = *$'\012'* ]] + + if [[ $LBUFFER == *$'\012'* ]] || (( PENDING )) then - # Editing a multiline buffer, it's unlikely prediction is wanted + # Editing a multiline buffer or pasting in a chunk of text; + # it's unlikely prediction is wanted + zstyle -t ":predict" toggle && predict-off zle .$WIDGET "$@" return - elif [[ ${RBUFFER[1]} = ${KEYS[-1]} ]] + elif [[ ${RBUFFER[1]} == ${KEYS[-1]} ]] then # Same as what's typed, just move on ((++CURSOR)) @@ -58,10 +65,7 @@ insert-and-predict () { unsetopt automenu recexact integer curs=$CURSOR pos nchar=${#LBUFFER//[^${KEYS[-1]}]} local -a +h comppostfuncs - local crs curcontext="${curcontext}" - - [[ -z "$curcontext" ]] && curcontext=::: - curcontext="predict:${curcontext#*:}" + local crs curcontext="predict:${${curcontext:-:::}#*:}" comppostfuncs=( predict-limit-list ) zle complete-word @@ -69,7 +73,7 @@ insert-and-predict () { # get out of that `case'. repeat 1 do - zstyle -s ":completion:${curcontext}:" cursor crs + zstyle -s ":predict" cursor crs case $crs in (complete) # At the place where the completion left it, if it is after @@ -92,27 +96,28 @@ insert-and-predict () { done fi fi + else + zstyle -t ":predict" toggle && predict-off fi fi return 0 } delete-backward-and-predict() { - if [[ -n "$LBUFFER" ]] + if (( $#LBUFFER > 1 )) then setopt localoptions noshwordsplit noksharrays - if [[ $LBUFFER = *$'\012'* ]] then - # Editing a multiline buffer, it's unlikely prediction is wanted - zle .$WIDGET "$@" - # If the last widget was e.g. a motion, then probably the intent is + # When editing a multiline buffer, it's unlikely prediction is wanted; + # or if the last widget was e.g. a motion, then probably the intent is # to actually edit the line, not change the search prefix. - elif [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ]] + if [[ $LBUFFER = *$'\012'* || + $LASTWIDGET != (self-insert|magic-space|backward-delete-char) ]] then + zstyle -t ":predict" toggle && predict-off + LBUFFER="$LBUFFER[1,-2]" + else ((--CURSOR)) zle .history-beginning-search-forward || RBUFFER="" return 0 - else - # Depending on preference, you might call "predict-off" here. - LBUFFER="$LBUFFER[1,-2]" fi fi } @@ -130,7 +135,7 @@ predict-limit-list() { compstate[nmatches] > compstate[list_max] ) )) then compstate[list]='' - elif zstyle -t ":completion:predict::::" list always + elif zstyle -t ":predict" list always then compstate[list]='force list' fi |