diff --git a/src/start.zsh b/src/start.zsh index 5991039..ca9f966 100644 --- a/src/start.zsh +++ b/src/start.zsh @@ -18,6 +18,14 @@ _zsh_autosuggest_start() { _zsh_autosuggest_bind_widgets } -# Start the autosuggestion widgets on the next precmd -autoload -Uz add-zsh-hook -add-zsh-hook precmd _zsh_autosuggest_start +# Mark for auto-loading the functions that we use +autoload -Uz add-zsh-hook is-at-least + +# If zle is already running, go ahead and start the autosuggestion widgets. +# Otherwise, wait until the next precmd. +if zle; then + _zsh_autosuggest_start + (( ! ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )) && add-zsh-hook precmd _zsh_autosuggest_start +else + add-zsh-hook precmd _zsh_autosuggest_start +fi diff --git a/src/strategies/completion.zsh b/src/strategies/completion.zsh index 4290f0c..e2d114c 100644 --- a/src/strategies/completion.zsh +++ b/src/strategies/completion.zsh @@ -45,8 +45,6 @@ _zsh_autosuggest_capture_completion_widget() { zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget _zsh_autosuggest_capture_setup() { - autoload -Uz is-at-least - # There is a bug in zpty module in older zsh versions by which a # zpty that exits will kill all zpty processes that were forked # before it. Here we set up a zsh exit hook to SIGKILL the zpty diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 8aa8591..ad8d9f1 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -549,8 +549,6 @@ _zsh_autosuggest_capture_completion_widget() { zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget _zsh_autosuggest_capture_setup() { - autoload -Uz is-at-least - # There is a bug in zpty module in older zsh versions by which a # zpty that exits will kill all zpty processes that were forked # before it. Here we set up a zsh exit hook to SIGKILL the zpty @@ -861,6 +859,14 @@ _zsh_autosuggest_start() { _zsh_autosuggest_bind_widgets } -# Start the autosuggestion widgets on the next precmd -autoload -Uz add-zsh-hook -add-zsh-hook precmd _zsh_autosuggest_start +# Mark for auto-loading the functions that we use +autoload -Uz add-zsh-hook is-at-least + +# If zle is already running, go ahead and start the autosuggestion widgets. +# Otherwise, wait until the next precmd. +if zle; then + _zsh_autosuggest_start + (( ! ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )) && add-zsh-hook precmd _zsh_autosuggest_start +else + add-zsh-hook precmd _zsh_autosuggest_start +fi