mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-25 10:01:05 +01:00
Restore standard widgets to fix segfault when re-sourcing autosuggestions.zsh
This commit is contained in:
parent
7a00bfa444
commit
8777836a1c
1 changed files with 52 additions and 49 deletions
|
@ -46,21 +46,23 @@ ZLE_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
||||||
vi-add-next vi-forward-blank-word vi-end-of-line end-of-line
|
vi-add-next vi-forward-blank-word vi-end-of-line end-of-line
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ZLE_AUTOSUGGEST_ALL_WIDGETS=(
|
||||||
|
self-insert magic-space backward-delete-char accept-line
|
||||||
|
$ZLE_AUTOSUGGEST_ACCEPT_WIDGETS
|
||||||
|
$ZLE_AUTOSUGGEST_SUSPEND_WIDGETS
|
||||||
|
$ZLE_AUTOSUGGEST_COMPLETION_WIDGETS
|
||||||
|
)
|
||||||
|
|
||||||
autosuggest-pause() {
|
autosuggest-pause() {
|
||||||
[[ -z $ZLE_AUTOSUGGESTING ]] && return
|
[[ -z $ZLE_AUTOSUGGESTING ]] && return
|
||||||
unset ZLE_AUTOSUGGESTING
|
unset ZLE_AUTOSUGGESTING
|
||||||
local widget
|
|
||||||
|
# Restore standard widgets except for self-insert, which triggers resume
|
||||||
|
autosuggest-restore-widgets
|
||||||
|
zle -A autosuggest-paused-self-insert self-insert
|
||||||
|
|
||||||
# When autosuggestions are disabled, kill the unmaterialized part
|
# When autosuggestions are disabled, kill the unmaterialized part
|
||||||
RBUFFER=''
|
RBUFFER=''
|
||||||
zle -A autosuggest-paused-self-insert self-insert
|
|
||||||
zle -A autosuggest-magic-space-orig magic-space
|
|
||||||
zle -A autosuggest-backward-delete-char-orig backward-delete-char
|
|
||||||
zle -A autosuggest-accept-line-orig accept-line
|
|
||||||
for widget in $ZLE_AUTOSUGGEST_ACCEPT_WIDGETS $ZLE_AUTOSUGGEST_SUSPEND_WIDGETS $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
|
|
||||||
[[ -z $widgets[$widget] || -z $widgets[autosuggest-${widget}-orig] ]] &&\
|
|
||||||
continue
|
|
||||||
eval "zle -A autosuggest-${widget}-orig ${widget}"
|
|
||||||
done
|
|
||||||
autosuggest-highlight-suggested-text
|
autosuggest-highlight-suggested-text
|
||||||
|
|
||||||
if [[ -n $ZLE_AUTOSUGGEST_CONNECTION ]]; then
|
if [[ -n $ZLE_AUTOSUGGEST_CONNECTION ]]; then
|
||||||
|
@ -71,27 +73,7 @@ autosuggest-pause() {
|
||||||
autosuggest-resume() {
|
autosuggest-resume() {
|
||||||
[[ -n $ZLE_AUTOSUGGESTING ]] && return
|
[[ -n $ZLE_AUTOSUGGESTING ]] && return
|
||||||
ZLE_AUTOSUGGESTING=1
|
ZLE_AUTOSUGGESTING=1
|
||||||
local widget
|
autosuggest-hook-widgets
|
||||||
# Replace prediction widgets by versions that will also highlight RBUFFER
|
|
||||||
zle -A autosuggest-insert-or-space self-insert
|
|
||||||
zle -A autosuggest-insert-or-space magic-space
|
|
||||||
zle -A autosuggest-backward-delete-char backward-delete-char
|
|
||||||
zle -A autosuggest-accept-line accept-line
|
|
||||||
# Hook into some default widgets that should suspend autosuggestion
|
|
||||||
# automatically
|
|
||||||
for widget in $ZLE_AUTOSUGGEST_ACCEPT_WIDGETS; do
|
|
||||||
[[ -z $widgets[$widget] ]] && continue
|
|
||||||
eval "zle -A autosuggest-accept-suggestion $widget"
|
|
||||||
done
|
|
||||||
for widget in $ZLE_AUTOSUGGEST_SUSPEND_WIDGETS; do
|
|
||||||
[[ -z $widgets[$widget] ]] && continue
|
|
||||||
eval "zle -A autosuggest-suspend $widget"
|
|
||||||
done
|
|
||||||
# Hook into completion widgets to trim RBUFFER before completion
|
|
||||||
for widget in $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
|
|
||||||
[[ -z $widgets[$widget] ]] && continue
|
|
||||||
eval "zle -A autosuggest-tab $widget"
|
|
||||||
done
|
|
||||||
if [[ -n $ZLE_AUTOSUGGEST_CONNECTION ]]; then
|
if [[ -n $ZLE_AUTOSUGGEST_CONNECTION ]]; then
|
||||||
# install listen for suggestions asynchronously
|
# install listen for suggestions asynchronously
|
||||||
zle -Fw $ZLE_AUTOSUGGEST_CONNECTION autosuggest-pop-suggestion
|
zle -Fw $ZLE_AUTOSUGGEST_CONNECTION autosuggest-pop-suggestion
|
||||||
|
@ -111,7 +93,7 @@ autosuggest-start() {
|
||||||
autosuggest-toggle() {
|
autosuggest-toggle() {
|
||||||
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
||||||
autosuggest-pause
|
autosuggest-pause
|
||||||
zle -A autosuggest-self-insert-orig self-insert
|
zle -A .self-insert self-insert
|
||||||
else
|
else
|
||||||
autosuggest-resume
|
autosuggest-resume
|
||||||
fi
|
fi
|
||||||
|
@ -194,7 +176,7 @@ autosuggest-paused-self-insert() {
|
||||||
autosuggest-resume
|
autosuggest-resume
|
||||||
zle self-insert
|
zle self-insert
|
||||||
else
|
else
|
||||||
zle autosuggest-self-insert-orig
|
zle .self-insert
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,21 +210,21 @@ autosuggest-pop-suggestion() {
|
||||||
|
|
||||||
autosuggest-suspend() {
|
autosuggest-suspend() {
|
||||||
autosuggest-pause
|
autosuggest-pause
|
||||||
zle autosuggest-${WIDGET}-orig "$@"
|
zle .${WIDGET} "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
autosuggest-tab() {
|
autosuggest-tab() {
|
||||||
RBUFFER=''
|
RBUFFER=''
|
||||||
zle autosuggest-${WIDGET}-orig "$@"
|
zle .${WIDGET} "$@"
|
||||||
autosuggest-invalidate-highlight-cache
|
autosuggest-invalidate-highlight-cache
|
||||||
autosuggest-highlight-suggested-text
|
autosuggest-highlight-suggested-text
|
||||||
}
|
}
|
||||||
|
|
||||||
autosuggest-accept-suggestion() {
|
autosuggest-accept-suggestion() {
|
||||||
if [[ AUTOSUGGESTION_ACCEPT_RIGHT_ARROW -eq 1 && ("$WIDGET" == 'forward-char' || "$WIDGET" == 'vi-forward-char') ]]; then
|
if [[ AUTOSUGGESTION_ACCEPT_RIGHT_ARROW -eq 1 && ("$WIDGET" == 'forward-char' || "$WIDGET" == 'vi-forward-char') ]]; then
|
||||||
zle autosuggest-end-of-line-orig "$@"
|
zle .end-of-line "$@"
|
||||||
else
|
else
|
||||||
zle autosuggest-${WIDGET}-orig "$@"
|
zle .${WIDGET} "$@"
|
||||||
fi
|
fi
|
||||||
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
||||||
autosuggest-invalidate-highlight-cache
|
autosuggest-invalidate-highlight-cache
|
||||||
|
@ -252,7 +234,7 @@ autosuggest-accept-suggestion() {
|
||||||
|
|
||||||
autosuggest-execute-suggestion() {
|
autosuggest-execute-suggestion() {
|
||||||
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
||||||
zle autosuggest-end-of-line-orig
|
zle .end-of-line
|
||||||
autosuggest-invalidate-highlight-cache
|
autosuggest-invalidate-highlight-cache
|
||||||
autosuggest-highlight-suggested-text
|
autosuggest-highlight-suggested-text
|
||||||
fi
|
fi
|
||||||
|
@ -264,6 +246,36 @@ autosuggest-invalidate-highlight-cache() {
|
||||||
_zsh_highlight_autosuggest_highlighter_cache=()
|
_zsh_highlight_autosuggest_highlighter_cache=()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autosuggest-restore-widgets() {
|
||||||
|
for widget in $ZLE_AUTOSUGGEST_ALL_WIDGETS; do
|
||||||
|
[[ -z $widgets[$widget] ]] && continue
|
||||||
|
zle -A .${widget} ${widget}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
autosuggest-hook-widgets() {
|
||||||
|
local widget
|
||||||
|
# Replace prediction widgets by versions that will also highlight RBUFFER
|
||||||
|
zle -A autosuggest-insert-or-space self-insert
|
||||||
|
zle -A autosuggest-insert-or-space magic-space
|
||||||
|
zle -A autosuggest-backward-delete-char backward-delete-char
|
||||||
|
zle -A autosuggest-accept-line accept-line
|
||||||
|
# Hook into some default widgets that should suspend autosuggestion
|
||||||
|
# automatically
|
||||||
|
for widget in $ZLE_AUTOSUGGEST_ACCEPT_WIDGETS; do
|
||||||
|
[[ -z $widgets[$widget] ]] && continue
|
||||||
|
eval "zle -A autosuggest-accept-suggestion $widget"
|
||||||
|
done
|
||||||
|
for widget in $ZLE_AUTOSUGGEST_SUSPEND_WIDGETS; do
|
||||||
|
[[ -z $widgets[$widget] ]] && continue
|
||||||
|
eval "zle -A autosuggest-suspend $widget"
|
||||||
|
done
|
||||||
|
for widget in $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
|
||||||
|
[[ -z $widgets[$widget] ]] && continue
|
||||||
|
eval "zle -A autosuggest-tab $widget"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
zle -N autosuggest-toggle
|
zle -N autosuggest-toggle
|
||||||
zle -N autosuggest-start
|
zle -N autosuggest-start
|
||||||
zle -N autosuggest-accept-suggested-small-word
|
zle -N autosuggest-accept-suggested-small-word
|
||||||
|
@ -279,13 +291,4 @@ zle -N autosuggest-tab
|
||||||
zle -N autosuggest-suspend
|
zle -N autosuggest-suspend
|
||||||
zle -N autosuggest-accept-suggestion
|
zle -N autosuggest-accept-suggestion
|
||||||
|
|
||||||
# Save all widgets
|
autosuggest-restore-widgets
|
||||||
zle -A self-insert autosuggest-self-insert-orig
|
|
||||||
zle -A magic-space autosuggest-magic-space-orig
|
|
||||||
zle -A backward-delete-char autosuggest-backward-delete-char-orig
|
|
||||||
zle -A accept-line autosuggest-accept-line-orig
|
|
||||||
|
|
||||||
for widget in ${ZLE_AUTOSUGGEST_ACCEPT_WIDGETS} ${ZLE_AUTOSUGGEST_SUSPEND_WIDGETS} ${ZLE_AUTOSUGGEST_COMPLETION_WIDGETS}; do
|
|
||||||
[[ -z $widgets[$widget] ]] && continue
|
|
||||||
eval "zle -A $widget autosuggest-${widget}-orig"
|
|
||||||
done
|
|
||||||
|
|
Loading…
Reference in a new issue