From 51b39e210ede9c436f976dc47d7635c22e401eab Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 13 Feb 2016 23:46:34 -0700 Subject: [PATCH] Bound widgets now handle arguments correctly --- src/bind.zsh | 8 ++++---- src/widgets.zsh | 12 ++++++------ zsh-autosuggestions.zsh | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/bind.zsh b/src/bind.zsh index d77715d..baf4494 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -34,9 +34,9 @@ _zsh_autosuggest_bind_widget() { # Set up widget to call $autosuggest_function if it exists # Otherwise just call the original widget if [ -n "$autosuggest_function" ]; then; - action=$autosuggest_function; + action="$autosuggest_function \$@"; else; - action="zle $prefix$widget \$@" + action="zle $prefix$widget -- \$@" fi # Create new function for the widget that highlights and calls the action @@ -72,9 +72,9 @@ _zsh_autosuggest_bind_widgets() { # Given the name of a widget, invoke the original we saved, if it exists _zsh_autosuggest_invoke_original_widget() { - local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$1" + local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$WIDGET" if [ $widgets[$original_widget_name] ]; then - zle $original_widget_name + zle $original_widget_name -- $@ fi } diff --git a/src/widgets.zsh b/src/widgets.zsh index a03c5a4..70c7965 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -8,13 +8,13 @@ _zsh_autosuggest_clear() { # Remove the suggestion unset POSTDISPLAY - _zsh_autosuggest_invoke_original_widget $WIDGET + _zsh_autosuggest_invoke_original_widget $@ } # Modify the buffer and get a new suggestion _zsh_autosuggest_modify() { # Original widget modifies the buffer - _zsh_autosuggest_invoke_original_widget $WIDGET + _zsh_autosuggest_invoke_original_widget $@ # Get a new suggestion if the buffer is not empty after modification local suggestion @@ -44,7 +44,7 @@ _zsh_autosuggest_accept() { CURSOR=${#BUFFER} fi - _zsh_autosuggest_invoke_original_widget $WIDGET + _zsh_autosuggest_invoke_original_widget $@ } # Partially accept the suggestion @@ -56,7 +56,7 @@ _zsh_autosuggest_partial_accept() { BUFFER="$BUFFER$POSTDISPLAY" # Original widget moves the cursor - _zsh_autosuggest_invoke_original_widget $WIDGET + _zsh_autosuggest_invoke_original_widget $@ # If we've moved past the end of the original buffer if [ $CURSOR -gt $#original_buffer ]; then @@ -73,13 +73,13 @@ _zsh_autosuggest_partial_accept() { _zsh_autosuggest_widget_accept() { _zsh_autosuggest_highlight_reset - _zsh_autosuggest_accept + _zsh_autosuggest_accept $@ _zsh_autosuggest_highlight_apply } _zsh_autosuggest_widget_clear() { _zsh_autosuggest_highlight_reset - _zsh_autosuggest_clear + _zsh_autosuggest_clear $@ _zsh_autosuggest_highlight_apply } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 842ccb7..5c68a0c 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -160,9 +160,9 @@ _zsh_autosuggest_bind_widget() { # Set up widget to call $autosuggest_function if it exists # Otherwise just call the original widget if [ -n "$autosuggest_function" ]; then; - action=$autosuggest_function; + action="$autosuggest_function \$@"; else; - action="zle $prefix$widget \$@" + action="zle $prefix$widget -- \$@" fi # Create new function for the widget that highlights and calls the action @@ -198,10 +198,10 @@ _zsh_autosuggest_bind_widgets() { # Given the name of a widget, invoke the original we saved, if it exists _zsh_autosuggest_invoke_original_widget() { - local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$1" + local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$WIDGET" if [ $widgets[$original_widget_name] ]; then - zle $original_widget_name + zle $original_widget_name -- $@ fi } @@ -236,13 +236,13 @@ _zsh_autosuggest_clear() { # Remove the suggestion unset POSTDISPLAY - _zsh_autosuggest_invoke_original_widget $WIDGET + _zsh_autosuggest_invoke_original_widget $@ } # Modify the buffer and get a new suggestion _zsh_autosuggest_modify() { # Original widget modifies the buffer - _zsh_autosuggest_invoke_original_widget $WIDGET + _zsh_autosuggest_invoke_original_widget $@ # Get a new suggestion if the buffer is not empty after modification local suggestion @@ -272,7 +272,7 @@ _zsh_autosuggest_accept() { CURSOR=${#BUFFER} fi - _zsh_autosuggest_invoke_original_widget $WIDGET + _zsh_autosuggest_invoke_original_widget $@ } # Partially accept the suggestion @@ -284,7 +284,7 @@ _zsh_autosuggest_partial_accept() { BUFFER="$BUFFER$POSTDISPLAY" # Original widget moves the cursor - _zsh_autosuggest_invoke_original_widget $WIDGET + _zsh_autosuggest_invoke_original_widget $@ # If we've moved past the end of the original buffer if [ $CURSOR -gt $#original_buffer ]; then @@ -301,13 +301,13 @@ _zsh_autosuggest_partial_accept() { _zsh_autosuggest_widget_accept() { _zsh_autosuggest_highlight_reset - _zsh_autosuggest_accept + _zsh_autosuggest_accept $@ _zsh_autosuggest_highlight_apply } _zsh_autosuggest_widget_clear() { _zsh_autosuggest_highlight_reset - _zsh_autosuggest_clear + _zsh_autosuggest_clear $@ _zsh_autosuggest_highlight_apply }