From 6e15a2d3de6f6f394cc29ee832fbf728f9ecc94c Mon Sep 17 00:00:00 2001 From: Maciej Dems Date: Wed, 8 Jul 2020 11:04:56 +0200 Subject: [PATCH 1/3] Preserve ZLE_KILL and ZLE_YANK flags --- src/bind.zsh | 6 ++++++ src/config.zsh | 28 +++++++++++++++++++++++++++- zsh-autosuggestions.zsh | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/bind.zsh b/src/bind.zsh index 1dde137..3380617 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -51,8 +51,14 @@ _zsh_autosuggest_bind_widget() { # 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`). + # Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets. eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() { _zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ + case ${(q)widget} in + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';; + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';; + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';; + esac }" # Create the bound widget diff --git a/src/config.zsh b/src/config.zsh index 5a0ebd8..9c54585 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -82,7 +82,6 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- run-help set-local-history which-command - yank yank-pop zle-\* ) @@ -91,3 +90,30 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- # Pty name for capturing completions for completion suggestion strategy (( ! ${+ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) && typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty + +# Widgets that should preserve ZLE_KILL flag +(( ! ${+ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS} )) && { + typeset -ga ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS + ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS=( + kill-\* + backward-kill-\* + ) +} + +# Widgets that should preserve ZLE_YANK flag +(( ! ${+ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS} )) && { + typeset -ga ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS + ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS=( + bracketed-paste + vi-put-after + yank + ) +} + +# Widgets that should preserve ZLE_YANKBEFORE flag +(( ! ${+ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS} )) && { + typeset -ga ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS + ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS=( + vi-put-before + ) +} diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index b19cac7..f43ae5b 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -108,7 +108,6 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- run-help set-local-history which-command - yank yank-pop zle-\* ) @@ -118,6 +117,33 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- (( ! ${+ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) && typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty +# Widgets that should preserve ZLE_KILL flag +(( ! ${+ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS} )) && { + typeset -ga ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS + ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS=( + kill-\* + backward-kill-\* + ) +} + +# Widgets that should preserve ZLE_YANK flag +(( ! ${+ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS} )) && { + typeset -ga ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS + ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS=( + bracketed-paste + vi-put-after + yank + ) +} + +# Widgets that should preserve ZLE_YANKBEFORE flag +(( ! ${+ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS} )) && { + typeset -ga ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS + ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS=( + vi-put-before + ) +} + #--------------------------------------------------------------------# # Utility Functions # #--------------------------------------------------------------------# @@ -181,8 +207,14 @@ _zsh_autosuggest_bind_widget() { # 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`). + # Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets. eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() { _zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ + case ${(q)widget} in + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';; + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';; + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';; + esac }" # Create the bound widget From 36f37f50d1bd940d7cbddf448d7dce5feb3b8f62 Mon Sep 17 00:00:00 2001 From: Maciej Dems Date: Wed, 8 Jul 2020 11:29:37 +0200 Subject: [PATCH 2/3] Added ZSH version check --- src/bind.zsh | 14 ++++++++------ src/config.zsh | 3 +++ zsh-autosuggestions.zsh | 17 +++++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/bind.zsh b/src/bind.zsh index 3380617..4305a33 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -51,14 +51,16 @@ _zsh_autosuggest_bind_widget() { # 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`). - # Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets. + # Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets for ZSH >= 5.2 eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() { _zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ - case ${(q)widget} in - (${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';; - (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';; - (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';; - esac + if [[ ! "${ZSH_VERSION}" < 5.2 ]]; then + case ${(q)widget} in + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';; + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';; + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';; + esac + fi }" # Create the bound widget diff --git a/src/config.zsh b/src/config.zsh index 9c54585..6b45647 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -85,6 +85,9 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- yank-pop zle-\* ) + if [[ "${ZSH_VERSION}" < 5.2 ]]; then + ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(yank) + fi } # Pty name for capturing completions for completion suggestion strategy diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index f43ae5b..00fcc86 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -111,6 +111,9 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- yank-pop zle-\* ) + if [[ "${ZSH_VERSION}" < 5.2 ]]; then + ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(yank) + fi } # Pty name for capturing completions for completion suggestion strategy @@ -207,14 +210,16 @@ _zsh_autosuggest_bind_widget() { # 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`). - # Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets. + # Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets for ZSH >= 5.2 eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() { _zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ - case ${(q)widget} in - (${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';; - (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';; - (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';; - esac + if [[ ! "${ZSH_VERSION}" < 5.2 ]]; then + case ${(q)widget} in + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';; + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';; + (${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';; + esac + fi }" # Create the bound widget From 33f442af079e789388abbc3267ae560435175f04 Mon Sep 17 00:00:00 2001 From: Maciej Dems Date: Fri, 9 Jun 2023 11:20:34 +0200 Subject: [PATCH 3/3] Disable async --- zsh-autosuggestions.zsh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 00fcc86..0e65259 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -3,7 +3,7 @@ # v0.7.0 # Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2016-2021 Eric Freese -# +# # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without @@ -12,10 +12,10 @@ # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: -# +# # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -893,9 +893,9 @@ autoload -Uz add-zsh-hook is-at-least # older versions because there is a bug when using async mode where ^C does not # work immediately after fetching a suggestion. # See https://github.com/zsh-users/zsh-autosuggestions/issues/364 -if is-at-least 5.0.8; then - typeset -g ZSH_AUTOSUGGEST_USE_ASYNC= -fi +# if is-at-least 5.0.8; then +# typeset -g ZSH_AUTOSUGGEST_USE_ASYNC= +# fi # Start the autosuggestion widgets on the next precmd add-zsh-hook precmd _zsh_autosuggest_start