Skip to content

Commit 116fdcd

Browse files
committed
driver: Probe for the memo feature in the startup code
1 parent e440834 commit 116fdcd

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

driver.zsh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,48 @@ _zsh_highlight_load_highlighters()
204204

205205
autoload -Uz _zsh_highlight_internal
206206

207+
# Probe the memo= feature.
208+
region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" )
209+
case ${region_highlight[-1]} in
210+
("0 0 fg=red")
211+
# zsh 5.8 or earlier
212+
integer -gr zsh_highlight__memo_feature=0
213+
;;
214+
("0 0 fg=red memo=zsh-syntax-highlighting")
215+
# zsh 5.9 or later
216+
integer -gr zsh_highlight__memo_feature=1
217+
;;
218+
(" 0 0 fg=red, memo=zsh-syntax-highlighting") ;&
219+
(*)
220+
# We can get here in two ways:
221+
#
222+
# 1. When not running as a widget. In that case, $region_highlight is
223+
# not a special variable (= one with custom getter/setter functions
224+
# written in C) but an ordinary one, so the third case pattern matches
225+
# and we fall through to this block. (The test suite uses this codepath.)
226+
#
227+
# 2. When running under a future version of zsh that will have changed
228+
# the serialization of $region_highlight elements from their underlying
229+
# C structs, so that none of the previous case patterns will match.
230+
#
231+
# In either case, fall back to a version check.
232+
#
233+
# The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee.
234+
# The version number at the time was 5.8.0.2-dev (see Config/version.mk).
235+
# Therefore, on 5.8.0.3 and newer the memo= feature is available.
236+
#
237+
# On zsh version 5.8.0.2 between the aforementioned commit and the
238+
# first Config/version.mk bump after it (which, at the time of writing,
239+
# is yet to come), this condition will false negative.
240+
if is-at-least 5.8.0.3 $ZSH_VERSION.0.0; then
241+
integer -gr zsh_highlight__memo_feature=1
242+
else
243+
integer -gr zsh_highlight__memo_feature=0
244+
fi
245+
;;
246+
esac
247+
region_highlight[-1]=()
248+
207249
# Resolve highlighters directory location.
208250
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
209251
print -r -- >&2 'zsh-syntax-highlighting: failed loading highlighters, exiting.'

zsh-syntax-highlighting.zsh

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -50,50 +50,6 @@ _zsh_highlight()
5050
return $ret
5151
}
5252

53-
# Probe the memo= feature, once.
54-
(( ${+zsh_highlight__memo_feature} )) || {
55-
region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" )
56-
case ${region_highlight[-1]} in
57-
("0 0 fg=red")
58-
# zsh 5.8 or earlier
59-
integer -gr zsh_highlight__memo_feature=0
60-
;;
61-
("0 0 fg=red memo=zsh-syntax-highlighting")
62-
# zsh 5.9 or later
63-
integer -gr zsh_highlight__memo_feature=1
64-
;;
65-
(" 0 0 fg=red, memo=zsh-syntax-highlighting") ;&
66-
(*)
67-
# We can get here in two ways:
68-
#
69-
# 1. When not running as a widget. In that case, $region_highlight is
70-
# not a special variable (= one with custom getter/setter functions
71-
# written in C) but an ordinary one, so the third case pattern matches
72-
# and we fall through to this block. (The test suite uses this codepath.)
73-
#
74-
# 2. When running under a future version of zsh that will have changed
75-
# the serialization of $region_highlight elements from their underlying
76-
# C structs, so that none of the previous case patterns will match.
77-
#
78-
# In either case, fall back to a version check.
79-
#
80-
# The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee.
81-
# The version number at the time was 5.8.0.2-dev (see Config/version.mk).
82-
# Therefore, on 5.8.0.3 and newer the memo= feature is available.
83-
#
84-
# On zsh version 5.8.0.2 between the aforementioned commit and the
85-
# first Config/version.mk bump after it (which, at the time of writing,
86-
# is yet to come), this condition will false negative.
87-
if is-at-least 5.8.0.3 $ZSH_VERSION.0.0; then
88-
integer -gr zsh_highlight__memo_feature=1
89-
else
90-
integer -gr zsh_highlight__memo_feature=0
91-
fi
92-
;;
93-
esac
94-
region_highlight[-1]=()
95-
}
96-
9753
# Reset region_highlight to build it from scratch
9854
if (( zsh_highlight__memo_feature )); then
9955
region_highlight=( "${(@)region_highlight:#*memo=zsh-syntax-highlighting*}" )

0 commit comments

Comments
 (0)