Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve ZLE_KILL and ZLE_YANK flags #551

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/bind.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +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 for ZSH >= 5.2
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
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
Expand Down
31 changes: 30 additions & 1 deletion src/config.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,41 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
run-help
set-local-history
which-command
yank
yank-pop
zle-\*
)
if [[ "${ZSH_VERSION}" < 5.2 ]]; then
ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(yank)
fi
}

# 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
)
}
51 changes: 44 additions & 7 deletions zsh-autosuggestions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -108,16 +108,45 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
run-help
set-local-history
which-command
yank
yank-pop
zle-\*
)
if [[ "${ZSH_VERSION}" < 5.2 ]]; then
ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(yank)
fi
}

# 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
)
}

#--------------------------------------------------------------------#
# Utility Functions #
#--------------------------------------------------------------------#
Expand Down Expand Up @@ -181,8 +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 for ZSH >= 5.2
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
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
Expand Down Expand Up @@ -856,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