From ca70612d3c7fa46ee56f6b7e8db6e1dc0618dd40 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sat, 28 May 2016 20:05:11 +0200 Subject: [PATCH 01/12] Document caveats of match_prev_cmd strategy This strategy relies on the history being exactly in the order in which commands have been entered. Therefore, options like suppressing duplicates or expiring duplicates first will lead to unexpected suggestions. --- README.md | 2 +- src/strategies/match_prev_cmd.zsh | 3 +++ zsh-autosuggestions.zsh | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bc6de0f..f1a0d20 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ Set `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` to configure the style that the suggestion Set `ZSH_AUTOSUGGEST_STRATEGY` to choose the strategy for generating suggestions. There are currently two to choose from: - `default`: Chooses the most recent match. -- `match_prev_cmd`: Chooses the most recent match whose preceding history item matches the most recently executed command ([more info](src/strategies/match_prev_cmd.zsh)). +- `match_prev_cmd`: 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`. ### Widget Mapping diff --git a/src/strategies/match_prev_cmd.zsh b/src/strategies/match_prev_cmd.zsh index e71957e..bf8bdd9 100644 --- a/src/strategies/match_prev_cmd.zsh +++ b/src/strategies/match_prev_cmd.zsh @@ -16,6 +16,9 @@ # will be 'ls foo' rather than 'ls bar' because your most recently # executed command (pwd) was previously followed by 'ls foo'. # +# 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`. _zsh_autosuggest_strategy_match_prev_cmd() { local prefix="$1" diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 4e3c62e..7e44a77 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -398,6 +398,9 @@ _zsh_autosuggest_strategy_default() { # will be 'ls foo' rather than 'ls bar' because your most recently # executed command (pwd) was previously followed by 'ls foo'. # +# 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`. _zsh_autosuggest_strategy_match_prev_cmd() { local prefix="$1" From b4b3a82ee32732fa250cd76cefceb2db644fce59 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Fri, 10 Jun 2016 13:19:30 -0600 Subject: [PATCH 02/12] Fix #168 and #130: Escape tildes when fetching suggestions --- src/suggestion.zsh | 2 +- test/strategies_test.zsh | 7 +++++++ zsh-autosuggestions.zsh | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/suggestion.zsh b/src/suggestion.zsh index 0a7ca1e..31a9f76 100644 --- a/src/suggestion.zsh +++ b/src/suggestion.zsh @@ -17,5 +17,5 @@ _zsh_autosuggest_escape_command() { setopt localoptions EXTENDED_GLOB # Escape special chars in the string (requires EXTENDED_GLOB) - echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}" + echo -E "${1//(#m)[\\()\[\]|*?~]/\\$MATCH}" } diff --git a/test/strategies_test.zsh b/test/strategies_test.zsh index 50d0a24..0a937f4 100644 --- a/test/strategies_test.zsh +++ b/test/strategies_test.zsh @@ -44,6 +44,12 @@ assertTildeSuggestion() { 'cd ~/something' } +assertTildeSuggestionWithExtendedGlob() { + setopt local_options extended_glob + + assertTildeSuggestion +} + assertParenthesesSuggestion() { set_history <<-'EOF' echo "$(ls foo)" @@ -87,6 +93,7 @@ testSpecialCharsForAllStrategies() { assertBackslashSuggestion assertDoubleBackslashSuggestion assertTildeSuggestion + assertTildeSuggestionWithExtendedGlob assertParenthesesSuggestion assertSquareBracketsSuggestion done diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 7e44a77..d2c7d2c 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -360,7 +360,7 @@ _zsh_autosuggest_escape_command() { setopt localoptions EXTENDED_GLOB # Escape special chars in the string (requires EXTENDED_GLOB) - echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}" + echo -E "${1//(#m)[\\()\[\]|*?~]/\\$MATCH}" } #--------------------------------------------------------------------# From 63816c5da84e177ecb1d509f7b7255df05022083 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Fri, 10 Jun 2016 13:24:45 -0600 Subject: [PATCH 03/12] Fix #164: Use `fc` builtin instead of `$history` array for lookup According to a few tests, the `fc` builtin appears to be quite a bit faster than searching through the `$history` associative array when dealing with large history files (500K+). --- src/strategies/default.zsh | 9 +-------- zsh-autosuggestions.zsh | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/strategies/default.zsh b/src/strategies/default.zsh index 42da24e..29333f5 100644 --- a/src/strategies/default.zsh +++ b/src/strategies/default.zsh @@ -7,12 +7,5 @@ # _zsh_autosuggest_strategy_default() { - local prefix="$1" - - # Get the keys of the history items that match - local -a histkeys - histkeys=(${(k)history[(r)$prefix*]}) - - # Echo the value of the first key - echo -E "${history[$histkeys[1]]}" + fc -lnrm "$1*" 1 2>/dev/null | head -n 1 } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index d2c7d2c..9f25514 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -371,14 +371,7 @@ _zsh_autosuggest_escape_command() { # _zsh_autosuggest_strategy_default() { - local prefix="$1" - - # Get the keys of the history items that match - local -a histkeys - histkeys=(${(k)history[(r)$prefix*]}) - - # Echo the value of the first key - echo -E "${history[$histkeys[1]]}" + fc -lnrm "$1*" 1 2>/dev/null | head -n 1 } #--------------------------------------------------------------------# From 7b81eb79b8d09f37fba8ffe13adcc0e5378273f9 Mon Sep 17 00:00:00 2001 From: Lorenzo Bolla Date: Fri, 15 Jul 2016 09:39:33 +0100 Subject: [PATCH 04/12] Disable autosuggest if buffer is too large Make buffer max size configurable, defaulted to infinity --- src/widgets.zsh | 4 +++- test/widgets/modify_test.zsh | 30 ++++++++++++++++++++++++++++++ zsh-autosuggestions.zsh | 4 +++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/widgets.zsh b/src/widgets.zsh index ee1129f..89b9f2c 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -25,7 +25,9 @@ _zsh_autosuggest_modify() { # Get a new suggestion if the buffer is not empty after modification local suggestion if [ $#BUFFER -gt 0 ]; then - suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")" + if [ -z "$ZSH_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_BUFFER_MAX_SIZE" ]; then + suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")" + fi fi # Add the suggestion to the POSTDISPLAY diff --git a/test/widgets/modify_test.zsh b/test/widgets/modify_test.zsh index 4dfd30d..8ba5b4b 100644 --- a/test/widgets/modify_test.zsh +++ b/test/widgets/modify_test.zsh @@ -9,6 +9,7 @@ oneTimeSetUp() { setUp() { BUFFER='' POSTDISPLAY='' + ZSH_BUFFER_MAX_SIZE='' } tearDown() { @@ -42,6 +43,35 @@ testModify() { "$POSTDISPLAY" } +testModifyBufferTooLarge() { + + ZSH_BUFFER_MAX_SIZE='20' + + stub_and_eval \ + _zsh_autosuggest_invoke_original_widget \ + 'BUFFER+="012345678901234567890"' + + stub_and_echo \ + _zsh_autosuggest_suggestion \ + '012345678901234567890123456789' + + _zsh_autosuggest_modify 'original-widget' + + assertTrue \ + 'original widget not invoked' \ + 'stub_called _zsh_autosuggest_invoke_original_widget' + + assertEquals \ + 'BUFFER was not modified' \ + '012345678901234567890' \ + "$BUFFER" + + assertEquals \ + 'POSTDISPLAY does not contain suggestion' \ + '' \ + "$POSTDISPLAY" +} + testRetval() { stub_and_eval \ _zsh_autosuggest_invoke_original_widget \ diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 9f25514..ff201b9 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -243,7 +243,9 @@ _zsh_autosuggest_modify() { # Get a new suggestion if the buffer is not empty after modification local suggestion if [ $#BUFFER -gt 0 ]; then - suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")" + if [ -z "$ZSH_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_BUFFER_MAX_SIZE" ]; then + suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")" + fi fi # Add the suggestion to the POSTDISPLAY From 2450c95d8a377192938bb49088b1cb74a3f41a5b Mon Sep 17 00:00:00 2001 From: Lorenzo Bolla Date: Mon, 18 Jul 2016 10:55:19 +0100 Subject: [PATCH 05/12] Rename and document new config var --- src/config.zsh | 3 +++ src/widgets.zsh | 2 +- test/widgets/modify_test.zsh | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/config.zsh b/src/config.zsh index 73d98fe..4353736 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -47,3 +47,6 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( vi-forward-blank-word vi-forward-blank-word-end ) + +# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound. +ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= diff --git a/src/widgets.zsh b/src/widgets.zsh index 89b9f2c..b2f8a0e 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -25,7 +25,7 @@ _zsh_autosuggest_modify() { # Get a new suggestion if the buffer is not empty after modification local suggestion if [ $#BUFFER -gt 0 ]; then - if [ -z "$ZSH_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_BUFFER_MAX_SIZE" ]; then + if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")" fi fi diff --git a/test/widgets/modify_test.zsh b/test/widgets/modify_test.zsh index 8ba5b4b..7ed6346 100644 --- a/test/widgets/modify_test.zsh +++ b/test/widgets/modify_test.zsh @@ -9,7 +9,7 @@ oneTimeSetUp() { setUp() { BUFFER='' POSTDISPLAY='' - ZSH_BUFFER_MAX_SIZE='' + ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE='' } tearDown() { @@ -45,7 +45,7 @@ testModify() { testModifyBufferTooLarge() { - ZSH_BUFFER_MAX_SIZE='20' + ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE='20' stub_and_eval \ _zsh_autosuggest_invoke_original_widget \ From cdf56a330514cdff64fd4e09a737e9c4b93869d5 Mon Sep 17 00:00:00 2001 From: Lorenzo Bolla Date: Mon, 18 Jul 2016 10:56:21 +0100 Subject: [PATCH 06/12] Include result of `make` --- zsh-autosuggestions.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index ff201b9..5ebd993 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -74,6 +74,9 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( vi-forward-blank-word-end ) +# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound. +ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= + #--------------------------------------------------------------------# # Handle Deprecated Variables/Widgets # #--------------------------------------------------------------------# @@ -243,7 +246,7 @@ _zsh_autosuggest_modify() { # Get a new suggestion if the buffer is not empty after modification local suggestion if [ $#BUFFER -gt 0 ]; then - if [ -z "$ZSH_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_BUFFER_MAX_SIZE" ]; then + if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -lt "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then suggestion="$(_zsh_autosuggest_suggestion "$BUFFER")" fi fi From a9c8efa04881395836f283f62091791280d44a26 Mon Sep 17 00:00:00 2001 From: Lorenzo Bolla Date: Mon, 18 Jul 2016 16:06:50 +0100 Subject: [PATCH 07/12] Update README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f1a0d20..2ce6bd5 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,12 @@ Widgets not in any of these lists will update the suggestion when invoked. **Note:** A widget shouldn't belong to more than one of the above arrays. +### Disabling suggestion for large buffers + +Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20. +This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for too long strings. + + ### Key Bindings This plugin provides three widgets that you can use with `bindkey`: From 25f4afb0584f61e16a9912adf74c89c5f3d87795 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sun, 31 Jul 2016 19:35:30 -0600 Subject: [PATCH 08/12] Add ZSH_AUTOSUGGEST_IGNORE_WIDGETS array --- README.md | 1 + src/bind.zsh | 14 ++++++++++++-- src/config.zsh | 10 ++++++++++ zsh-autosuggestions.zsh | 24 ++++++++++++++++++++++-- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2ce6bd5..e419134 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ This plugin works by triggering custom behavior when certain [zle widgets](http: - `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS`: Widgets in this array will accept the suggestion when invoked. - `ZSH_AUTOSUGGEST_EXECUTE_WIDGETS`: Widgets in this array will execute the suggestion when invoked. - `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked. +- `ZSH_AUTOSUGGEST_IGNORE_WIDGETS`: Widgets in this array will not trigger any custom behavior. Widgets not in any of these lists will update the suggestion when invoked. diff --git a/src/bind.zsh b/src/bind.zsh index 384ae08..49763e8 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -47,10 +47,20 @@ _zsh_autosuggest_bind_widget() { # Map all configured widgets to the right autosuggest widgets _zsh_autosuggest_bind_widgets() { - local widget; + local widget + local ignore_widgets + + ignore_widgets=( + .\* + _\* + zle-line-\* + autosuggest-\* + $ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* + $ZSH_AUTOSUGGEST_IGNORE_WIDGETS + ) # Find every widget we might want to bind and bind it appropriately - for widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|autosuggest-*|$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX*|zle-line-*|run-help|which-command|beep|set-local-history|yank)}; do + for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then _zsh_autosuggest_bind_widget $widget clear elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then diff --git a/src/config.zsh b/src/config.zsh index 4353736..f519f6f 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -48,5 +48,15 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( vi-forward-blank-word-end ) +# Widgets that should be ignored (globbing supported but must be escaped) +ZSH_AUTOSUGGEST_IGNORE_WIDGETS=( + orig-\* + beep + run-help + set-local-history + which-command + yank +) + # Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound. ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 5ebd993..1055388 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -74,6 +74,16 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( vi-forward-blank-word-end ) +# Widgets that should be ignored (globbing supported but must be escaped) +ZSH_AUTOSUGGEST_IGNORE_WIDGETS=( + orig-\* + beep + run-help + set-local-history + which-command + yank +) + # Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound. ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= @@ -161,10 +171,20 @@ _zsh_autosuggest_bind_widget() { # Map all configured widgets to the right autosuggest widgets _zsh_autosuggest_bind_widgets() { - local widget; + local widget + local ignore_widgets + + ignore_widgets=( + .\* + _\* + zle-line-\* + autosuggest-\* + $ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* + $ZSH_AUTOSUGGEST_IGNORE_WIDGETS + ) # Find every widget we might want to bind and bind it appropriately - for widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|autosuggest-*|$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX*|zle-line-*|run-help|which-command|beep|set-local-history|yank)}; do + for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then _zsh_autosuggest_bind_widget $widget clear elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then From a44aa593219e233502fe6e47449e6b83af334f67 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sun, 31 Jul 2016 20:09:26 -0600 Subject: [PATCH 09/12] Remove unnecessary reset of POSTDISPLAy --- src/widgets.zsh | 2 -- zsh-autosuggestions.zsh | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/widgets.zsh b/src/widgets.zsh index b2f8a0e..9e0b568 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -33,8 +33,6 @@ _zsh_autosuggest_modify() { # Add the suggestion to the POSTDISPLAY if [ -n "$suggestion" ]; then POSTDISPLAY="${suggestion#$BUFFER}" - else - unset POSTDISPLAY fi return $retval diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 1055388..9394cf8 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -274,8 +274,6 @@ _zsh_autosuggest_modify() { # Add the suggestion to the POSTDISPLAY if [ -n "$suggestion" ]; then POSTDISPLAY="${suggestion#$BUFFER}" - else - unset POSTDISPLAY fi return $retval From b377c39d0e893c1ca73163e663a3220a6d4e4f36 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sun, 31 Jul 2016 20:10:22 -0600 Subject: [PATCH 10/12] Only fetch a new suggestion if buffer has changed --- README.md | 2 +- src/widgets.zsh | 12 +++++++++++- zsh-autosuggestions.zsh | 12 +++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e419134..3a5c3f3 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ This plugin works by triggering custom behavior when certain [zle widgets](http: - `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked. - `ZSH_AUTOSUGGEST_IGNORE_WIDGETS`: Widgets in this array will not trigger any custom behavior. -Widgets not in any of these lists will update the suggestion when invoked. +Widgets that modify the buffer and are not found in any of these arrays will fetch a new suggestion after they are invoked. **Note:** A widget shouldn't belong to more than one of the above arrays. diff --git a/src/widgets.zsh b/src/widgets.zsh index 9e0b568..57f378e 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -15,13 +15,23 @@ _zsh_autosuggest_clear() { _zsh_autosuggest_modify() { local -i retval + # Save the contents of the buffer/postdisplay + local orig_buffer="$BUFFER" + local orig_postdisplay="$POSTDISPLAY" + # Clear suggestion while original widget runs unset POSTDISPLAY - # Original widget modifies the buffer + # Original widget may modify the buffer _zsh_autosuggest_invoke_original_widget $@ retval=$? + # Don't fetch a new suggestion if the buffer hasn't changed + if [ "$BUFFER" = "$orig_buffer" ]; then + POSTDISPLAY="$orig_postdisplay" + return $retval + fi + # Get a new suggestion if the buffer is not empty after modification local suggestion if [ $#BUFFER -gt 0 ]; then diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 9394cf8..a40cbdc 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -256,13 +256,23 @@ _zsh_autosuggest_clear() { _zsh_autosuggest_modify() { local -i retval + # Save the contents of the buffer/postdisplay + local orig_buffer="$BUFFER" + local orig_postdisplay="$POSTDISPLAY" + # Clear suggestion while original widget runs unset POSTDISPLAY - # Original widget modifies the buffer + # Original widget may modify the buffer _zsh_autosuggest_invoke_original_widget $@ retval=$? + # Don't fetch a new suggestion if the buffer hasn't changed + if [ "$BUFFER" = "$orig_buffer" ]; then + POSTDISPLAY="$orig_postdisplay" + return $retval + fi + # Get a new suggestion if the buffer is not empty after modification local suggestion if [ $#BUFFER -gt 0 ]; then From 9333f0653fd6e4c7aaf6c63948d5177eeecf6dda Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 17 Oct 2016 07:43:56 -0600 Subject: [PATCH 11/12] Update changelog for v0.3.3 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 608d17f..50a1e0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v0.3.3 +- Switch from $history array to fc builtin for better performance with large HISTFILEs (#164) +- Fix tilde handling when extended_glob is set (#168) +- Add config option for maximum buffer length to fetch suggestions for (#178) +- Add config option for list of widgets to ignore (#184) +- Don't fetch a new suggestion unless a modification widget actually modifies the buffer (#183) + ## v0.3.2 - Test runner now supports running specific tests and choosing zsh binary - Return code from original widget is now correctly passed through (#135) From 9cfaf5d3424ceb5fedd2c7e3253f823faae74383 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 17 Oct 2016 07:45:09 -0600 Subject: [PATCH 12/12] v0.3.3 --- VERSION | 2 +- zsh-autosuggestions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 7becae1..600e6fd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.3.2 +v0.3.3 diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index a40cbdc..3761efe 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -1,6 +1,6 @@ # Fish-like fast/unobtrusive autosuggestions for zsh. # https://github.com/zsh-users/zsh-autosuggestions -# v0.3.2 +# v0.3.3 # Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2016 Eric Freese #