From 7682c13860597ce09e672faeae7d3429d5460dcc Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 25 Jan 2020 07:47:23 -0700 Subject: [PATCH 1/2] cleanup: Pull built-in widget actions into global variable --- src/widgets.zsh | 26 +++++++++++++++++--------- zsh-autosuggestions.zsh | 26 +++++++++++++++++--------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/widgets.zsh b/src/widgets.zsh index 8f09792..3c543d9 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -205,8 +205,21 @@ _zsh_autosuggest_partial_accept() { } () { + typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS + + _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=( + clear + fetch + suggest + accept + execute + enable + disable + toggle + ) + local action - for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do + for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do eval "_zsh_autosuggest_widget_$action() { local -i retval @@ -223,12 +236,7 @@ _zsh_autosuggest_partial_accept() { }" done - zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch - zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest - zle -N autosuggest-accept _zsh_autosuggest_widget_accept - zle -N autosuggest-clear _zsh_autosuggest_widget_clear - zle -N autosuggest-execute _zsh_autosuggest_widget_execute - zle -N autosuggest-enable _zsh_autosuggest_widget_enable - zle -N autosuggest-disable _zsh_autosuggest_widget_disable - zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle + for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do + zle -N autosuggest-$action _zsh_autosuggest_widget_$action + done } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index a8ef6c4..3354988 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -467,8 +467,21 @@ _zsh_autosuggest_partial_accept() { } () { + typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS + + _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=( + clear + fetch + suggest + accept + execute + enable + disable + toggle + ) + local action - for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do + for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do eval "_zsh_autosuggest_widget_$action() { local -i retval @@ -485,14 +498,9 @@ _zsh_autosuggest_partial_accept() { }" done - zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch - zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest - zle -N autosuggest-accept _zsh_autosuggest_widget_accept - zle -N autosuggest-clear _zsh_autosuggest_widget_clear - zle -N autosuggest-execute _zsh_autosuggest_widget_execute - zle -N autosuggest-enable _zsh_autosuggest_widget_enable - zle -N autosuggest-disable _zsh_autosuggest_widget_disable - zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle + for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do + zle -N autosuggest-$action _zsh_autosuggest_widget_$action + done } #--------------------------------------------------------------------# From c114bd2298dcb8a4d30f2c9c61393bf2bd1186dd Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 25 Jan 2020 07:47:58 -0700 Subject: [PATCH 2/2] Be more specific about the built-in widgets we want to avoid wrapping To avoid wrapping the built-in widgets (e.g. `autosuggest-fetch`, `autosuggest-toggle`), we were ignoring all widgets whose names start with `autosuggest-`. This had the downside of preventing wrapping of user-defined widgets whose names happened to also start with that prefix. By being more specific about the exact built-in widgets we want to avoid wrapping, we can allow users to define widgets whose names start with `autosuggest-`. See GitHub issue #496. --- src/bind.zsh | 2 +- zsh-autosuggestions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bind.zsh b/src/bind.zsh index fc2da9e..1dde137 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -69,7 +69,7 @@ _zsh_autosuggest_bind_widgets() { ignore_widgets=( .\* _\* - autosuggest-\* + ${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-} $ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* $ZSH_AUTOSUGGEST_IGNORE_WIDGETS ) diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 3354988..3edf01f 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -199,7 +199,7 @@ _zsh_autosuggest_bind_widgets() { ignore_widgets=( .\* _\* - autosuggest-\* + ${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-} $ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* $ZSH_AUTOSUGGEST_IGNORE_WIDGETS )