From b554feb7ba7cd8b47d9a72c502f0e945211259ae Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 31 Aug 2016 16:34:28 +0000 Subject: [PATCH 1/6] Declare global variables This was causing warnings with `setopt warn_create_global`. --- zsh-history-substring-search.zsh | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index e29c9b1..fa1a8d7 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -42,10 +42,10 @@ # configuration variables #----------------------------------------------------------------------------- -HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold' -HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold' -HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' -HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE='' +typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold' +typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold' +typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' +typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE='' #----------------------------------------------------------------------------- # the main ZLE widgets @@ -178,8 +178,11 @@ fi _history-substring-search-begin() { setopt localoptions extendedglob - _history_substring_search_refresh_display= - _history_substring_search_query_highlight= + typeset -g _history_substring_search_refresh_display= + typeset -g _history_substring_search_query_highlight= + + # Declare global variables that will be referenced in this function + typeset -g BUFFER MATCH # # If the buffer is the same as the previously displayed history substring @@ -193,7 +196,7 @@ _history-substring-search-begin() { # # Clear the previous result. # - _history_substring_search_result='' + typeset -g _history_substring_search_result='' if [[ -z $BUFFER ]]; then # @@ -202,14 +205,14 @@ _history-substring-search-begin() { # speed things up a little. # _history_substring_search_query= - _history_substring_search_raw_matches=() + typeset -g _history_substring_search_raw_matches=() else # # For the purpose of highlighting we keep a copy of the original # query string. # - _history_substring_search_query=$BUFFER + typeset -g _history_substring_search_query=$BUFFER # # $BUFFER contains the text that is in the command-line currently. @@ -225,7 +228,7 @@ _history-substring-search-begin() { # (R) returns values in reverse older, so the index of the youngest # matching history entry is at the head of the list. # - _history_substring_search_raw_matches=(${(k)history[(R)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)*${escaped_query}*]}) + typeset -g _history_substring_search_raw_matches=(${(k)history[(R)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)*${escaped_query}*]}) fi # @@ -242,8 +245,8 @@ _history-substring-search-begin() { # If an entry (key) is in the set (non-empty value), then we have already # added that entry to _history_substring_search_matches. # - _history_substring_search_raw_match_index=0 - _history_substring_search_matches=() + typeset -g _history_substring_search_raw_match_index=0 + typeset -g _history_substring_search_matches=() unset _history_substring_search_unique_filter typeset -A -g _history_substring_search_unique_filter @@ -266,9 +269,9 @@ _history-substring-search-begin() { # decremented to 0. # if [[ $WIDGET == history-substring-search-down ]]; then - _history_substring_search_match_index=1 + typeset -g _history_substring_search_match_index=1 else - _history_substring_search_match_index=0 + typeset -g _history_substring_search_match_index=0 fi } @@ -281,7 +284,7 @@ _history-substring-search-end() { # existing highlights and moving the cursor to the end of the result buffer if [[ $_history_substring_search_refresh_display -eq 1 ]]; then region_highlight=() - CURSOR=${#BUFFER} + typeset -g CURSOR=${#BUFFER} fi # highlight command line using zsh-syntax-highlighting @@ -294,6 +297,7 @@ _history-substring-search-end() { # indicates the begin position + 1 of the first occurrence # of _history_substring_search_query in $BUFFER. # + typeset -g MBEGIN MEND : ${(S)BUFFER##(#m$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)($_history_substring_search_query##)} local begin=$(( MBEGIN - 1 )) local end=$(( begin + $#_history_substring_search_query )) From ec88096611a5a1896d09d1d29431a048b7c4ca2c Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Tue, 13 Sep 2016 22:00:53 +0100 Subject: [PATCH 2/6] Declare more global variables --- zsh-history-substring-search.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index fa1a8d7..cf02057 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -204,7 +204,7 @@ _history-substring-search-begin() { # in ZSH, so we do not need to actually search the history. This should # speed things up a little. # - _history_substring_search_query= + typeset -g _history_substring_search_query= typeset -g _history_substring_search_raw_matches=() else @@ -219,6 +219,7 @@ _history-substring-search-begin() { # we put an extra "\\" before meta characters such as "\(" and "\)", # so that they become "\\\(" and "\\\)". # + typeset -g MBEGIN MEND local escaped_query=${BUFFER//(#m)[\][()|\\*?#<>~^]/\\$MATCH} # From d26aaa659470019343751acb50384b0f950469b6 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 2 Nov 2016 01:23:42 +0000 Subject: [PATCH 3/6] Revert "Declare more global variables" This reverts commit ec88096611a5a1896d09d1d29431a048b7c4ca2c. --- zsh-history-substring-search.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index cf02057..fa1a8d7 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -204,7 +204,7 @@ _history-substring-search-begin() { # in ZSH, so we do not need to actually search the history. This should # speed things up a little. # - typeset -g _history_substring_search_query= + _history_substring_search_query= typeset -g _history_substring_search_raw_matches=() else @@ -219,7 +219,6 @@ _history-substring-search-begin() { # we put an extra "\\" before meta characters such as "\(" and "\)", # so that they become "\\\(" and "\\\)". # - typeset -g MBEGIN MEND local escaped_query=${BUFFER//(#m)[\][()|\\*?#<>~^]/\\$MATCH} # From 3fa98998c5ca1f810a7a7f1667bf32b43a97ce15 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 2 Nov 2016 01:23:44 +0000 Subject: [PATCH 4/6] Revert "Declare global variables" This reverts commit b554feb7ba7cd8b47d9a72c502f0e945211259ae. --- zsh-history-substring-search.zsh | 34 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index fa1a8d7..e29c9b1 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -42,10 +42,10 @@ # configuration variables #----------------------------------------------------------------------------- -typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold' -typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold' -typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' -typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE='' +HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold' +HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold' +HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' +HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE='' #----------------------------------------------------------------------------- # the main ZLE widgets @@ -178,11 +178,8 @@ fi _history-substring-search-begin() { setopt localoptions extendedglob - typeset -g _history_substring_search_refresh_display= - typeset -g _history_substring_search_query_highlight= - - # Declare global variables that will be referenced in this function - typeset -g BUFFER MATCH + _history_substring_search_refresh_display= + _history_substring_search_query_highlight= # # If the buffer is the same as the previously displayed history substring @@ -196,7 +193,7 @@ _history-substring-search-begin() { # # Clear the previous result. # - typeset -g _history_substring_search_result='' + _history_substring_search_result='' if [[ -z $BUFFER ]]; then # @@ -205,14 +202,14 @@ _history-substring-search-begin() { # speed things up a little. # _history_substring_search_query= - typeset -g _history_substring_search_raw_matches=() + _history_substring_search_raw_matches=() else # # For the purpose of highlighting we keep a copy of the original # query string. # - typeset -g _history_substring_search_query=$BUFFER + _history_substring_search_query=$BUFFER # # $BUFFER contains the text that is in the command-line currently. @@ -228,7 +225,7 @@ _history-substring-search-begin() { # (R) returns values in reverse older, so the index of the youngest # matching history entry is at the head of the list. # - typeset -g _history_substring_search_raw_matches=(${(k)history[(R)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)*${escaped_query}*]}) + _history_substring_search_raw_matches=(${(k)history[(R)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)*${escaped_query}*]}) fi # @@ -245,8 +242,8 @@ _history-substring-search-begin() { # If an entry (key) is in the set (non-empty value), then we have already # added that entry to _history_substring_search_matches. # - typeset -g _history_substring_search_raw_match_index=0 - typeset -g _history_substring_search_matches=() + _history_substring_search_raw_match_index=0 + _history_substring_search_matches=() unset _history_substring_search_unique_filter typeset -A -g _history_substring_search_unique_filter @@ -269,9 +266,9 @@ _history-substring-search-begin() { # decremented to 0. # if [[ $WIDGET == history-substring-search-down ]]; then - typeset -g _history_substring_search_match_index=1 + _history_substring_search_match_index=1 else - typeset -g _history_substring_search_match_index=0 + _history_substring_search_match_index=0 fi } @@ -284,7 +281,7 @@ _history-substring-search-end() { # existing highlights and moving the cursor to the end of the result buffer if [[ $_history_substring_search_refresh_display -eq 1 ]]; then region_highlight=() - typeset -g CURSOR=${#BUFFER} + CURSOR=${#BUFFER} fi # highlight command line using zsh-syntax-highlighting @@ -297,7 +294,6 @@ _history-substring-search-end() { # indicates the begin position + 1 of the first occurrence # of _history_substring_search_query in $BUFFER. # - typeset -g MBEGIN MEND : ${(S)BUFFER##(#m$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)($_history_substring_search_query##)} local begin=$(( MBEGIN - 1 )) local end=$(( begin + $#_history_substring_search_query )) From f7c8d3157b77c8ae5c4a8236692cf5c4a39e1c87 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 2 Nov 2016 01:23:09 +0000 Subject: [PATCH 5/6] global variables: declare up-front --- zsh-history-substring-search.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index e29c9b1..d7ce6c2 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -38,6 +38,25 @@ # ############################################################################## +#----------------------------------------------------------------------------- +# declare global variables +#----------------------------------------------------------------------------- + +typeset -g BUFFER MATCH MBEGIN MEND CURSOR +typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND +typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND +typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS +typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE +typeset -g _history_substring_search_refresh_display +typeset -g _history_substring_search_query_highlight +typeset -g _history_substring_search_result +typeset -g _history_substring_search_query +typeset -g _history_substring_search_raw_matches +typeset -g _history_substring_search_raw_match_index +typeset -g _history_substring_search_matches +typeset -g -A _history_substring_search_unique_filter +typeset -g _history_substring_search_match_index + #----------------------------------------------------------------------------- # configuration variables #----------------------------------------------------------------------------- From fd331b8345ad0f409d14a5d15b87c32feb721bc2 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 2 Nov 2016 01:33:00 +0000 Subject: [PATCH 6/6] global variables: fix array declarations --- zsh-history-substring-search.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index d7ce6c2..a3c2abb 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -51,9 +51,9 @@ typeset -g _history_substring_search_refresh_display typeset -g _history_substring_search_query_highlight typeset -g _history_substring_search_result typeset -g _history_substring_search_query -typeset -g _history_substring_search_raw_matches +typeset -g -A _history_substring_search_raw_matches typeset -g _history_substring_search_raw_match_index -typeset -g _history_substring_search_matches +typeset -g -A _history_substring_search_matches typeset -g -A _history_substring_search_unique_filter typeset -g _history_substring_search_match_index