diff options
Diffstat (limited to 'Functions')
-rw-r--r-- | Functions/Zle/predict-on | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/Functions/Zle/predict-on b/Functions/Zle/predict-on index 07ce0703a..e2b6ebd5b 100644 --- a/Functions/Zle/predict-on +++ b/Functions/Zle/predict-on @@ -1,31 +1,43 @@ # This set of functions implements a sort of magic history searching. # After predict-on, typing characters causes the editor to look backward -# in the history for the first line beginning with what you have typed -# so far. After predict-off, editing returns to normal for the line found. +# in the history for the first line beginning with what you have typed so +# far. After predict-off, editing returns to normal for the line found. # In fact, you often don't even need to use predict-off, because if the -# line doesn't match something in the history, adding a key at the end -# behaves as normal --- though editing in the middle is liable to delete +# line doesn't match something in the history, adding a key performs +# standard completion --- though editing in the middle is liable to delete # the rest of the line. # +# The setting of compmatchers means that if you use the completion system, +# you should be able to type TAB at almost any point to advance the cursor +# to the next "interesting" character position (usually the end of the +# current word, but sometimes somewhere in the middle of the word). And +# of course as soon as the entire line is what you want, you can accept +# with RETURN, without needing to move the cursor to the end first. +# # To use it: # autoload -U predict-on # zle -N predict-on # zle -N predict-off # bindkey '...' predict-on # bindkey '...' predict-off -# Note that all the functions are defined when you first call type the -# predict-on key, which means typing the predict-off key before that gives -# a harmless error message. +# 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. predict-on() { + setopt localoptions nounset noksharrays zle -N self-insert insert-and-predict zle -N magic-space insert-and-predict zle -N backward-delete-char delete-backward-and-predict + [[ $compmatchers[2] != 'r:|=*' ]] && + compmatchers=('' 'r:|=*' $compmatchers) } predict-off() { + setopt localoptions nounset noksharrays zle -A .self-insert self-insert zle -A .magic-space magic-space zle -A .backward-delete-char backward-delete-char + [[ $compmatchers[2] != 'r:|=*' ]] || shift 2 compmatchers } insert-and-predict () { emulate -L zsh @@ -37,7 +49,16 @@ insert-and-predict () { LBUFFER="$LBUFFER$KEYS" if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ]] then - zle .history-beginning-search-backward || RBUFFER="" + if ! zle .history-beginning-search-backward + then + RBUFFER="" + if [[ ${KEYS[-1]} != ' ' ]] + then + integer curs=$CURSOR + zle complete-word + CURSOR=$curs + fi + fi fi fi return 0 |