From 116fdcd436be2bc1cd87ea7f335b3d3f2e1184ae Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 10 Aug 2020 18:05:26 -0500 Subject: [PATCH] driver: Probe for the memo feature in the startup code --- driver.zsh | 42 +++++++++++++++++++++++++++++++++++ zsh-syntax-highlighting.zsh | 44 ------------------------------------- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/driver.zsh b/driver.zsh index d93b9103a..7be37d2d9 100644 --- a/driver.zsh +++ b/driver.zsh @@ -204,6 +204,48 @@ _zsh_highlight_load_highlighters() autoload -Uz _zsh_highlight_internal +# Probe the memo= feature. +region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" ) +case ${region_highlight[-1]} in + ("0 0 fg=red") + # zsh 5.8 or earlier + integer -gr zsh_highlight__memo_feature=0 + ;; + ("0 0 fg=red memo=zsh-syntax-highlighting") + # zsh 5.9 or later + integer -gr zsh_highlight__memo_feature=1 + ;; + (" 0 0 fg=red, memo=zsh-syntax-highlighting") ;& + (*) + # We can get here in two ways: + # + # 1. When not running as a widget. In that case, $region_highlight is + # not a special variable (= one with custom getter/setter functions + # written in C) but an ordinary one, so the third case pattern matches + # and we fall through to this block. (The test suite uses this codepath.) + # + # 2. When running under a future version of zsh that will have changed + # the serialization of $region_highlight elements from their underlying + # C structs, so that none of the previous case patterns will match. + # + # In either case, fall back to a version check. + # + # The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee. + # The version number at the time was 5.8.0.2-dev (see Config/version.mk). + # Therefore, on 5.8.0.3 and newer the memo= feature is available. + # + # On zsh version 5.8.0.2 between the aforementioned commit and the + # first Config/version.mk bump after it (which, at the time of writing, + # is yet to come), this condition will false negative. + if is-at-least 5.8.0.3 $ZSH_VERSION.0.0; then + integer -gr zsh_highlight__memo_feature=1 + else + integer -gr zsh_highlight__memo_feature=0 + fi + ;; +esac +region_highlight[-1]=() + # Resolve highlighters directory location. _zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || { print -r -- >&2 'zsh-syntax-highlighting: failed loading highlighters, exiting.' diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4b0c81fb8..82b55d1fd 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -50,50 +50,6 @@ _zsh_highlight() return $ret } - # Probe the memo= feature, once. - (( ${+zsh_highlight__memo_feature} )) || { - region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" ) - case ${region_highlight[-1]} in - ("0 0 fg=red") - # zsh 5.8 or earlier - integer -gr zsh_highlight__memo_feature=0 - ;; - ("0 0 fg=red memo=zsh-syntax-highlighting") - # zsh 5.9 or later - integer -gr zsh_highlight__memo_feature=1 - ;; - (" 0 0 fg=red, memo=zsh-syntax-highlighting") ;& - (*) - # We can get here in two ways: - # - # 1. When not running as a widget. In that case, $region_highlight is - # not a special variable (= one with custom getter/setter functions - # written in C) but an ordinary one, so the third case pattern matches - # and we fall through to this block. (The test suite uses this codepath.) - # - # 2. When running under a future version of zsh that will have changed - # the serialization of $region_highlight elements from their underlying - # C structs, so that none of the previous case patterns will match. - # - # In either case, fall back to a version check. - # - # The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee. - # The version number at the time was 5.8.0.2-dev (see Config/version.mk). - # Therefore, on 5.8.0.3 and newer the memo= feature is available. - # - # On zsh version 5.8.0.2 between the aforementioned commit and the - # first Config/version.mk bump after it (which, at the time of writing, - # is yet to come), this condition will false negative. - if is-at-least 5.8.0.3 $ZSH_VERSION.0.0; then - integer -gr zsh_highlight__memo_feature=1 - else - integer -gr zsh_highlight__memo_feature=0 - fi - ;; - esac - region_highlight[-1]=() - } - # Reset region_highlight to build it from scratch if (( zsh_highlight__memo_feature )); then region_highlight=( "${(@)region_highlight:#*memo=zsh-syntax-highlighting*}" )