diff --git a/history-search-multi-word b/history-search-multi-word index d1d22ad..9dc07d8 100644 --- a/history-search-multi-word +++ b/history-search-multi-word @@ -15,6 +15,11 @@ # zstyle ":history-search-multi-word" highlight-color "fg=yellow,bold" # zstyle ":plugin:history-search-multi-word" synhl "yes" +[[ "$__HSMW_MH_SOURCED" != "1" ]] && source "$HSMW_REPO_DIR/hsmw-highlight" +local right_brace_is_recognised_everywhere +integer path_dirs_was_set multi_func_def ointeractive_comments +-hsmw-highlight-fill-option-variables + emulate -LR zsh setopt typesetsilent extendedglob noshortloops localtraps @@ -154,8 +159,6 @@ _hsmw_main() { region_highlight+=( "$(( offset + ${#txt_before} )) $(( offset + ${#txt_before} + ${#entry} + 1 )) $__hsmw_active" ) } -[[ "$__HSMW_MH_SOURCED" != "1" ]] && source "$HSMW_REPO_DIR/hsmw-highlight" - _hsmw_main _hsmw_simulate_widget() { diff --git a/hsmw-highlight b/hsmw-highlight index c6ef5ef..24d798d 100644 --- a/hsmw-highlight +++ b/hsmw-highlight @@ -188,28 +188,44 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=( fi } +# Below are variables that must be defined in outer +# scope so that they are reachable in *-process() +# +# local right_brace_is_recognised_everywhere +# integer path_dirs_was_set +# integer multi_func_def +# integer ointeractive_comments +-hsmw-highlight-fill-option-variables() { + if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then + right_brace_is_recognised_everywhere=0 + else + right_brace_is_recognised_everywhere=1 + fi + + if [[ -o path_dirs ]]; then + path_dirs_was_set=1 + else + path_dirs_was_set=0 + fi + + if [[ -o multi_func_def ]]; then + multi_func_def=1 + else + multi_func_def=0 + fi + + if [[ -o interactive_comments ]]; then + ointeractive_comments=1 + else + ointeractive_comments=0 + fi +} + # Main syntax highlighting function. -hsmw-highlight-process() { - ## Before we even 'emulate -L', we must test a few options that would reset. - if [[ -o interactive_comments ]]; then - local interactive_comments= # set to empty - fi - if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then - local right_brace_is_recognised_everywhere=0 - else - local right_brace_is_recognised_everywhere=1 - fi - if [[ -o path_dirs ]]; then - integer path_dirs_was_set=1 - else - integer path_dirs_was_set=0 - fi - if [[ -o multi_func_def ]]; then - integer multi_func_def=1 - else - integer multi_func_def=0 - fi + (( ointeractive_comments )) && local interactive_comments= # _set_ to empty + emulate -L zsh setopt localoptions extendedglob bareglobqual nonomatch noksharrays diff --git a/test/parse.zsh b/test/parse.zsh index 8020d69..5ced2c2 100755 --- a/test/parse.zsh +++ b/test/parse.zsh @@ -61,6 +61,11 @@ if [[ "$1" = "-o" || "$1" = "-oo" ]]; then SECONDS=0 -hsmw-highlight-init + + local right_brace_is_recognised_everywhere + integer path_dirs_was_set multi_func_def ointeractive_comments + -hsmw-highlight-fill-option-variables + local line for line in "${long_input[@]}"; do reply=( ) @@ -79,6 +84,11 @@ elif [[ -r "$1" ]]; then reply=( ) -hsmw-highlight-init + + local right_brace_is_recognised_everywhere + integer path_dirs_was_set multi_func_def ointeractive_comments + -hsmw-highlight-fill-option-variables + -hsmw-highlight-process "$buf" print "Running time: $SECONDS"