From daaedc8e3da91a1f4d39d81e01a85b1b73182a7f Mon Sep 17 00:00:00 2001 From: Arnaud Venturi Date: Mon, 4 Dec 2017 16:11:17 +0100 Subject: [PATCH] Simplified the accept-line call. Still doing a stack overflow --- src/bind.zsh | 1 + src/widgets.zsh | 83 +++++++++++++++++++++++++++++----------- zsh-autosuggestions.zsh | 84 ++++++++++++++++++++++++++++++----------- 3 files changed, 122 insertions(+), 46 deletions(-) diff --git a/src/bind.zsh b/src/bind.zsh index be0d164..3d84b43 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -109,6 +109,7 @@ _zsh_autosuggest_invoke_original_widget() { [ $# -gt 0 ] || return local original_widget_name="$1" + print $original_widget_name shift diff --git a/src/widgets.zsh b/src/widgets.zsh index 9d23248..851804a 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -113,30 +113,67 @@ _zsh_autosuggest_suggest() { } # Accept the entire suggestion +# _zsh_autosuggest_accept() { +# local -i max_cursor_pos=$#BUFFER +# +# # When vicmd keymap is active, the cursor can't move all the way +# # to the end of the buffer +# if [ "$KEYMAP" = "vicmd" ]; then +# max_cursor_pos=$((max_cursor_pos - 1)) +# fi +# +# # Only accept if the cursor is at the end of the buffer +# if [ $CURSOR -eq $max_cursor_pos ]; then +# # Add the suggestion to the buffer +# BUFFER="$BUFFER$POSTDISPLAY" +# +# # Remove the suggestion +# unset POSTDISPLAY +# +# # Move the cursor to the end of the buffer +# CURSOR=${#BUFFER} +# +# print "a" +# _zsh_autosuggest_invoke_original_widget "end-of-line" +# print "b" +# fi +# +# print "1" +# _zsh_autosuggest_invoke_original_widget $@ +# print "2" +# } +# +# # When vicmd keymap is active, the cursor can't move all the way +# # to the end of the buffer +# if [ "$KEYMAP" = "vicmd" ]; then +# max_cursor_pos=$((max_cursor_pos - 1)) +# fi +# +# # Only accept if the cursor is at the end of the buffer +# if [ $CURSOR -eq $max_cursor_pos ]; then +# # Add the suggestion to the buffer +# BUFFER="$BUFFER$POSTDISPLAY" +# +# # Remove the suggestion +# unset POSTDISPLAY +# +# # Move the cursor to the end of the buffer +# CURSOR=${#BUFFER} +# +# print "a" +# _zsh_autosuggest_invoke_original_widget "end-of-line" +# print "b" +# fi +# +# print "1" +# _zsh_autosuggest_invoke_original_widget $@ +# print "2" +# } _zsh_autosuggest_accept() { - local -i max_cursor_pos=$#BUFFER - - # When vicmd keymap is active, the cursor can't move all the way - # to the end of the buffer - if [ "$KEYMAP" = "vicmd" ]; then - max_cursor_pos=$((max_cursor_pos - 1)) - fi - - # Only accept if the cursor is at the end of the buffer - if [ $CURSOR -eq $max_cursor_pos ]; then - # Add the suggestion to the buffer - BUFFER="$BUFFER$POSTDISPLAY" - - # Remove the suggestion - unset POSTDISPLAY - - # Move the cursor to the end of the buffer - CURSOR=${#BUFFER} - - _zsh_autosuggest_invoke_original_widget end-of-line - fi - - _zsh_autosuggest_invoke_original_widget $@ + # Accepting the whole line is basically a specific case of + # accepting partially with "end-of-line" widget +# _zsh_autosuggest_partial_accept ".end-of-line" + _zsh_autosuggest_partial_accept "end-of-line" } # Accept the entire suggestion and execute it diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 37870bd..1e9bdda 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -230,6 +230,7 @@ _zsh_autosuggest_invoke_original_widget() { [ $# -gt 0 ] || return local original_widget_name="$1" + print $original_widget_name shift @@ -378,30 +379,67 @@ _zsh_autosuggest_suggest() { } # Accept the entire suggestion +# _zsh_autosuggest_accept() { +# local -i max_cursor_pos=$#BUFFER +# +# # When vicmd keymap is active, the cursor can't move all the way +# # to the end of the buffer +# if [ "$KEYMAP" = "vicmd" ]; then +# max_cursor_pos=$((max_cursor_pos - 1)) +# fi +# +# # Only accept if the cursor is at the end of the buffer +# if [ $CURSOR -eq $max_cursor_pos ]; then +# # Add the suggestion to the buffer +# BUFFER="$BUFFER$POSTDISPLAY" +# +# # Remove the suggestion +# unset POSTDISPLAY +# +# # Move the cursor to the end of the buffer +# CURSOR=${#BUFFER} +# +# print "a" +# _zsh_autosuggest_invoke_original_widget "end-of-line" +# print "b" +# fi +# +# print "1" +# _zsh_autosuggest_invoke_original_widget $@ +# print "2" +# } +# +# # When vicmd keymap is active, the cursor can't move all the way +# # to the end of the buffer +# if [ "$KEYMAP" = "vicmd" ]; then +# max_cursor_pos=$((max_cursor_pos - 1)) +# fi +# +# # Only accept if the cursor is at the end of the buffer +# if [ $CURSOR -eq $max_cursor_pos ]; then +# # Add the suggestion to the buffer +# BUFFER="$BUFFER$POSTDISPLAY" +# +# # Remove the suggestion +# unset POSTDISPLAY +# +# # Move the cursor to the end of the buffer +# CURSOR=${#BUFFER} +# +# print "a" +# _zsh_autosuggest_invoke_original_widget "end-of-line" +# print "b" +# fi +# +# print "1" +# _zsh_autosuggest_invoke_original_widget $@ +# print "2" +# } _zsh_autosuggest_accept() { - local -i max_cursor_pos=$#BUFFER - - # When vicmd keymap is active, the cursor can't move all the way - # to the end of the buffer - if [ "$KEYMAP" = "vicmd" ]; then - max_cursor_pos=$((max_cursor_pos - 1)) - fi - - # Only accept if the cursor is at the end of the buffer - if [ $CURSOR -eq $max_cursor_pos ]; then - # Add the suggestion to the buffer - BUFFER="$BUFFER$POSTDISPLAY" - - # Remove the suggestion - unset POSTDISPLAY - - # Move the cursor to the end of the buffer - CURSOR=${#BUFFER} - - _zsh_autosuggest_invoke_original_widget end-of-line - fi - - _zsh_autosuggest_invoke_original_widget $@ + # Accepting the whole line is basically a specific case of + # accepting partially with "end-of-line" widget +# _zsh_autosuggest_partial_accept ".end-of-line" + _zsh_autosuggest_partial_accept "end-of-line" } # Accept the entire suggestion and execute it