Simplified the accept-line call. Still doing a stack overflow

This commit is contained in:
Arnaud Venturi 2017-12-04 16:11:17 +01:00
parent d4c6aab96c
commit daaedc8e3d
3 changed files with 122 additions and 46 deletions

View File

@ -109,6 +109,7 @@ _zsh_autosuggest_invoke_original_widget() {
[ $# -gt 0 ] || return
local original_widget_name="$1"
print $original_widget_name
shift

View File

@ -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

View File

@ -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