split dual-roled function into two distinct ones
This commit is contained in:
parent
56d178984e
commit
9fd4576ae7
1 changed files with 83 additions and 73 deletions
|
|
@ -43,12 +43,8 @@ F_ordinary_highlight="bg=magenta,fg=white,bold"
|
||||||
F_out_of_matches_highlight="bg=red,fg=white,bold"
|
F_out_of_matches_highlight="bg=red,fg=white,bold"
|
||||||
F_max_buffer_size=250000
|
F_max_buffer_size=250000
|
||||||
|
|
||||||
history-substring-search-backward() {
|
history-substring-search-begin() {
|
||||||
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
setopt extendedglob
|
setopt extendedglob
|
||||||
|
|
||||||
zmodload -i zsh/parameter
|
zmodload -i zsh/parameter
|
||||||
|
|
||||||
F_zsh_highlighting_available=0
|
F_zsh_highlighting_available=0
|
||||||
|
|
@ -81,8 +77,20 @@ history-substring-search-backward() {
|
||||||
# initial value of $F_match_number, which can initially only be decreased by
|
# initial value of $F_match_number, which can initially only be decreased by
|
||||||
# ${WIDGET/forward/backward}
|
# ${WIDGET/forward/backward}
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
history-substring-search-end() {
|
||||||
|
CURSOR=${#BUFFER}
|
||||||
|
#"zle .end-of-line" does not move CURSOR to the final end of line in multi-line buffers.
|
||||||
|
|
||||||
|
# for debugging purposes:
|
||||||
|
# zle -R "mn: "$F_match_number" m#: "${#F_matches}
|
||||||
|
# read -k -t 200 && zle -U $REPLY
|
||||||
|
}
|
||||||
|
|
||||||
|
history-substring-search-backward() {
|
||||||
|
history-substring-search-begin
|
||||||
|
|
||||||
if [[ $WIDGET = *backward* ]]; then # we have pressed arrow-up
|
|
||||||
if [[ ($F_match_number -ge 2 && $F_match_number -le $F_number_of_matches_plus_one) ]]; then
|
if [[ ($F_match_number -ge 2 && $F_match_number -le $F_number_of_matches_plus_one) ]]; then
|
||||||
let "F_match_number = $F_match_number - 1"
|
let "F_match_number = $F_match_number - 1"
|
||||||
F_command_to_be_retrieved=$history[$F_matches[$F_match_number]]
|
F_command_to_be_retrieved=$history[$F_matches[$F_match_number]]
|
||||||
|
|
@ -130,7 +138,13 @@ history-substring-search-backward() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else # arrow-down
|
|
||||||
|
history-substring-search-end
|
||||||
|
}
|
||||||
|
|
||||||
|
history-substring-search-forward() {
|
||||||
|
history-substring-search-begin
|
||||||
|
|
||||||
if [[ ($F_match_number -eq $F_number_of_matches_plus_one ) ]]; then
|
if [[ ($F_match_number -eq $F_number_of_matches_plus_one ) ]]; then
|
||||||
let "F_match_number = $F_match_number"
|
let "F_match_number = $F_match_number"
|
||||||
F_old_buffer_forward=$BUFFER
|
F_old_buffer_forward=$BUFFER
|
||||||
|
|
@ -183,16 +197,12 @@ history-substring-search-backward() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
CURSOR=${#BUFFER}
|
|
||||||
#"zle .end-of-line" does not move CURSOR to the final end of line in multi-line buffers.
|
|
||||||
|
|
||||||
# for debugging purposes:
|
history-substring-search-end
|
||||||
# zle -R "mn: "$F_match_number" m#: "${#F_matches}
|
|
||||||
# read -k -t 200 && zle -U $REPLY
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zle -N history-substring-search-forward history-substring-search-backward
|
|
||||||
zle -N history-substring-search-backward
|
zle -N history-substring-search-backward
|
||||||
|
zle -N history-substring-search-forward
|
||||||
|
|
||||||
bindkey '\e[A' history-substring-search-backward
|
bindkey '\e[A' history-substring-search-backward
|
||||||
bindkey '\e[B' history-substring-search-forward
|
bindkey '\e[B' history-substring-search-forward
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue