From dad6be4d5ec5c5446b7d67ada8b81ccd7074a9d4 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 30 Jun 2018 15:04:56 -0600 Subject: [PATCH 1/3] Remove unused feature detection Not needed after move away from zpty for async --- Makefile | 1 - src/features.zsh | 19 ------------------- zsh-autosuggestions.zsh | 19 ------------------- 3 files changed, 39 deletions(-) delete mode 100644 src/features.zsh diff --git a/Makefile b/Makefile index b89ff04..93b8d94 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ SRC_FILES := \ $(SRC_DIR)/setup.zsh \ $(SRC_DIR)/config.zsh \ $(SRC_DIR)/util.zsh \ - $(SRC_DIR)/features.zsh \ $(SRC_DIR)/bind.zsh \ $(SRC_DIR)/highlight.zsh \ $(SRC_DIR)/widgets.zsh \ diff --git a/src/features.zsh b/src/features.zsh deleted file mode 100644 index 7a5248f..0000000 --- a/src/features.zsh +++ /dev/null @@ -1,19 +0,0 @@ - -#--------------------------------------------------------------------# -# Feature Detection # -#--------------------------------------------------------------------# - -_zsh_autosuggest_feature_detect_zpty_returns_fd() { - typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD - typeset -h REPLY - - zpty zsh_autosuggest_feature_detect '{ zshexit() { kill -KILL $$; sleep 1 } }' - - if (( REPLY )); then - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1 - else - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0 - fi - - zpty -d zsh_autosuggest_feature_detect -} diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 4b617cc..83b2f7d 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -122,25 +122,6 @@ _zsh_autosuggest_escape_command() { echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" } -#--------------------------------------------------------------------# -# Feature Detection # -#--------------------------------------------------------------------# - -_zsh_autosuggest_feature_detect_zpty_returns_fd() { - typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD - typeset -h REPLY - - zpty zsh_autosuggest_feature_detect '{ zshexit() { kill -KILL $$; sleep 1 } }' - - if (( REPLY )); then - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1 - else - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0 - fi - - zpty -d zsh_autosuggest_feature_detect -} - #--------------------------------------------------------------------# # Widget Helpers # #--------------------------------------------------------------------# From 5529102afc618a3bff5fae75a969a1bb150fe270 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 30 Jun 2018 15:06:19 -0600 Subject: [PATCH 2/3] 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 From c0315e96d84a9f992d236131783aaecc9117004f Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 30 Jun 2018 16:54:33 -0600 Subject: [PATCH 3/3] Don't use `-s` option to `zmodload` It is not available in zsh versions older than 5.3 --- src/strategies/completion.zsh | 2 +- zsh-autosuggestions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strategies/completion.zsh b/src/strategies/completion.zsh index ff13b81..5f71d98 100644 --- a/src/strategies/completion.zsh +++ b/src/strategies/completion.zsh @@ -87,7 +87,7 @@ _zsh_autosuggest_capture_buffer() { } _zsh_autosuggest_capture_completion() { - zmodload -s zsh/zpty || return + zmodload zsh/zpty 2>/dev/null || return typeset -g completion local line REPLY diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 0052c69..41c659f 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -557,7 +557,7 @@ _zsh_autosuggest_capture_buffer() { } _zsh_autosuggest_capture_completion() { - zmodload -s zsh/zpty || return + zmodload zsh/zpty 2>/dev/null || return typeset -g completion local line REPLY