From f76472272e9a40a27a5b589f7ed3cf605c2993c4 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 1 Apr 2019 14:36:31 -0600 Subject: [PATCH 1/2] cleanup: Remove unnecessary braces --- src/bind.zsh | 6 +++--- zsh-autosuggestions.zsh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bind.zsh b/src/bind.zsh index bb41ef8..ec762ef 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -39,20 +39,20 @@ _zsh_autosuggest_bind_widget() { # User-defined widget user:*) _zsh_autosuggest_incr_bind_count $widget - zle -N $prefix${bind_count}-$widget ${widgets[$widget]#*:} + zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:} ;; # Built-in widget builtin) _zsh_autosuggest_incr_bind_count $widget eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }" - zle -N $prefix${bind_count}-$widget _zsh_autosuggest_orig_$widget + zle -N $prefix$bind_count-$widget _zsh_autosuggest_orig_$widget ;; # Completion widget completion:*) _zsh_autosuggest_incr_bind_count $widget - eval "zle -C $prefix${bind_count}-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}" + eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}" ;; esac diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 5bb5cd7..67cb5c9 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -200,20 +200,20 @@ _zsh_autosuggest_bind_widget() { # User-defined widget user:*) _zsh_autosuggest_incr_bind_count $widget - zle -N $prefix${bind_count}-$widget ${widgets[$widget]#*:} + zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:} ;; # Built-in widget builtin) _zsh_autosuggest_incr_bind_count $widget eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }" - zle -N $prefix${bind_count}-$widget _zsh_autosuggest_orig_$widget + zle -N $prefix$bind_count-$widget _zsh_autosuggest_orig_$widget ;; # Completion widget completion:*) _zsh_autosuggest_incr_bind_count $widget - eval "zle -C $prefix${bind_count}-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}" + eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}" ;; esac From 4a82ff1ead68db25645b2e920f17774a66e44e31 Mon Sep 17 00:00:00 2001 From: romkatv Date: Mon, 25 Feb 2019 12:59:31 +0100 Subject: [PATCH 2/2] speed up widget rebinding by removing redundant array subscripts --- src/bind.zsh | 23 +++++------------------ zsh-autosuggestions.zsh | 23 +++++------------------ 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/bind.zsh b/src/bind.zsh index ec762ef..a2e86e1 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -4,21 +4,8 @@ #--------------------------------------------------------------------# _zsh_autosuggest_incr_bind_count() { - if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then - ((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]++)) - else - _ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1 - fi - - typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1] -} - -_zsh_autosuggest_get_bind_count() { - if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then - typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1] - else - typeset -gi bind_count=0 - fi + typeset -gi bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]+1)) + _ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count } # Bind a single widget to an autosuggest widget, saving a reference to the original widget @@ -34,7 +21,9 @@ _zsh_autosuggest_bind_widget() { # Save a reference to the original widget case $widgets[$widget] in # Already bound - user:_zsh_autosuggest_(bound|orig)_*);; + user:_zsh_autosuggest_(bound|orig)_*) + bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$widget])) + ;; # User-defined widget user:*) @@ -56,8 +45,6 @@ _zsh_autosuggest_bind_widget() { ;; esac - _zsh_autosuggest_get_bind_count $widget - # Pass the original widget's name explicitly into the autosuggest # function. Use this passed in widget name to call the original # widget instead of relying on the $WIDGET variable being set diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 67cb5c9..a2edce6 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -165,21 +165,8 @@ _zsh_autosuggest_feature_detect_zpty_returns_fd() { #--------------------------------------------------------------------# _zsh_autosuggest_incr_bind_count() { - if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then - ((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]++)) - else - _ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1 - fi - - typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1] -} - -_zsh_autosuggest_get_bind_count() { - if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then - typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1] - else - typeset -gi bind_count=0 - fi + typeset -gi bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]+1)) + _ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count } # Bind a single widget to an autosuggest widget, saving a reference to the original widget @@ -195,7 +182,9 @@ _zsh_autosuggest_bind_widget() { # Save a reference to the original widget case $widgets[$widget] in # Already bound - user:_zsh_autosuggest_(bound|orig)_*);; + user:_zsh_autosuggest_(bound|orig)_*) + bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$widget])) + ;; # User-defined widget user:*) @@ -217,8 +206,6 @@ _zsh_autosuggest_bind_widget() { ;; esac - _zsh_autosuggest_get_bind_count $widget - # Pass the original widget's name explicitly into the autosuggest # function. Use this passed in widget name to call the original # widget instead of relying on the $WIDGET variable being set