From 5529102afc618a3bff5fae75a969a1bb150fe270 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 30 Jun 2018 15:06:19 -0600 Subject: [PATCH] zpty module is only needed for `completion` strategy --- Makefile | 1 - README.md | 2 +- src/setup.zsh | 10 ---------- src/start.zsh | 1 + src/strategies/completion.zsh | 2 ++ zsh-autosuggestions.zsh | 13 +++---------- 6 files changed, 7 insertions(+), 22 deletions(-) delete mode 100644 src/setup.zsh diff --git a/Makefile b/Makefile index 93b8d94..f6d13a7 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ SRC_DIR := ./src SRC_FILES := \ - $(SRC_DIR)/setup.zsh \ $(SRC_DIR)/config.zsh \ $(SRC_DIR)/util.zsh \ $(SRC_DIR)/bind.zsh \ diff --git a/README.md b/README.md index 4507c6b..dc7d21f 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Set `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` to configure the style that the suggestion - `history`: Chooses the most recent match from history. - `match_prev_cmd`: Like `history`, but chooses the most recent match whose preceding history item matches the most recently executed command ([more info](src/strategies/match_prev_cmd.zsh)). Note that this strategy won't work as expected with ZSH options that don't preserve the history order such as `HIST_IGNORE_ALL_DUPS` or `HIST_EXPIRE_DUPS_FIRST`. -- `completion`: (experimental) Chooses a suggestion based on what tab-completion would suggest. +- `completion`: (experimental) Chooses a suggestion based on what tab-completion would suggest. (requires `zpty` and `zutil` modules) For example, setting `ZSH_AUTOSUGGEST_STRATEGY=(history completion)` will first try to find a suggestion from your history, but, if it can't find a match, will find a suggestion from the completion engine. diff --git a/src/setup.zsh b/src/setup.zsh deleted file mode 100644 index c74489f..0000000 --- a/src/setup.zsh +++ /dev/null @@ -1,10 +0,0 @@ - -#--------------------------------------------------------------------# -# Setup # -#--------------------------------------------------------------------# - -# Precmd hooks for initializing the library and starting pty's -autoload -Uz add-zsh-hook - -# Asynchronous suggestions are generated in a pty -zmodload zsh/zpty diff --git a/src/start.zsh b/src/start.zsh index a73ee3b..ff93fdf 100644 --- a/src/start.zsh +++ b/src/start.zsh @@ -17,4 +17,5 @@ _zsh_autosuggest_start() { } # Start the autosuggestion widgets on the next precmd +autoload -Uz add-zsh-hook add-zsh-hook precmd _zsh_autosuggest_start diff --git a/src/strategies/completion.zsh b/src/strategies/completion.zsh index 422f4cc..ff13b81 100644 --- a/src/strategies/completion.zsh +++ b/src/strategies/completion.zsh @@ -87,6 +87,8 @@ _zsh_autosuggest_capture_buffer() { } _zsh_autosuggest_capture_completion() { + zmodload -s zsh/zpty || return + typeset -g completion local line REPLY diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 83b2f7d..0052c69 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -25,16 +25,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. -#--------------------------------------------------------------------# -# Setup # -#--------------------------------------------------------------------# - -# Precmd hooks for initializing the library and starting pty's -autoload -Uz add-zsh-hook - -# Asynchronous suggestions are generated in a pty -zmodload zsh/zpty - #--------------------------------------------------------------------# # Global Configuration Variables # #--------------------------------------------------------------------# @@ -567,6 +557,8 @@ _zsh_autosuggest_capture_buffer() { } _zsh_autosuggest_capture_completion() { + zmodload -s zsh/zpty || return + typeset -g completion local line REPLY @@ -780,4 +772,5 @@ _zsh_autosuggest_start() { } # Start the autosuggestion widgets on the next precmd +autoload -Uz add-zsh-hook add-zsh-hook precmd _zsh_autosuggest_start