Fix segfaults once and for all?

This commit is contained in:
Eric Freese
2016-02-15 08:31:00 -07:00
parent 76f415bf43
commit 2461a98857
4 changed files with 41 additions and 38 deletions

View File

@@ -12,7 +12,7 @@ _zsh_autosuggest_bind_widget() {
# Save a reference to the original widget
case $widgets[$widget] in
# Already bound
user:_zsh_autosuggest_(widget|orig)_*);;
user:_zsh_autosuggest_(bound|orig)_*);;
# User-defined widget
user:*)
@@ -31,8 +31,18 @@ _zsh_autosuggest_bind_widget() {
;;
esac
# Pass the original widget's name explicitly into the autosuggest
# function. Use this passed in widget name to call the original
# widget instead of relying on the $WIDGET variable being set
# correctly. $WIDGET cannot be trusted because other plugins call
# zle without the `-w` flag (e.g. `zle self-insert` instead of
# `zle self-insert -w`).
eval "_zsh_autosuggest_bound_$widget() {
_zsh_autosuggest_widget_$autosuggest_action $prefix$widget $@
}"
# Create the bound widget
zle -N $widget _zsh_autosuggest_widget_$autosuggest_action
zle -N $widget _zsh_autosuggest_bound_$widget
}
# Map all configured widgets to the right autosuggest widgets
@@ -54,9 +64,11 @@ _zsh_autosuggest_bind_widgets() {
done
}
# Given the name of a widget, invoke the original we saved, if it exists
# Given the name of an original widget and args, invoke it, if it exists
_zsh_autosuggest_invoke_original_widget() {
local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$WIDGET"
local original_widget_name=$1
shift
if [ $widgets[$original_widget_name] ]; then
zle $original_widget_name -- $@