Skip to content

Commit 3848e8f

Browse files
committed
driver: Probe for the memo feature in the startup code
1 parent f94548e commit 3848e8f

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

driver.zsh

+42
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,48 @@ _zsh_highlight_load_highlighters()
322322

323323
autoload -Uz _zsh_highlight_internal
324324

325+
# Probe the memo= feature.
326+
region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" )
327+
case ${region_highlight[-1]} in
328+
("0 0 fg=red")
329+
# zsh 5.8 or earlier
330+
integer -gr zsh_highlight__memo_feature=0
331+
;;
332+
("0 0 fg=red memo=zsh-syntax-highlighting")
333+
# zsh 5.9 or later
334+
integer -gr zsh_highlight__memo_feature=1
335+
;;
336+
(" 0 0 fg=red, memo=zsh-syntax-highlighting") ;&
337+
(*)
338+
# We can get here in two ways:
339+
#
340+
# 1. When not running as a widget. In that case, $region_highlight is
341+
# not a special variable (= one with custom getter/setter functions
342+
# written in C) but an ordinary one, so the third case pattern matches
343+
# and we fall through to this block. (The test suite uses this codepath.)
344+
#
345+
# 2. When running under a future version of zsh that will have changed
346+
# the serialization of $region_highlight elements from their underlying
347+
# C structs, so that none of the previous case patterns will match.
348+
#
349+
# In either case, fall back to a version check.
350+
#
351+
# The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee.
352+
# The version number at the time was 5.8.0.2-dev (see Config/version.mk).
353+
# Therefore, on 5.8.0.3 and newer the memo= feature is available.
354+
#
355+
# On zsh version 5.8.0.2 between the aforementioned commit and the
356+
# first Config/version.mk bump after it (which, at the time of writing,
357+
# is yet to come), this condition will false negative.
358+
if is-at-least 5.8.0.3 $ZSH_VERSION.0.0; then
359+
integer -gr zsh_highlight__memo_feature=1
360+
else
361+
integer -gr zsh_highlight__memo_feature=0
362+
fi
363+
;;
364+
esac
365+
region_highlight[-1]=()
366+
325367
# Try binding widgets.
326368
_zsh_highlight_bind_widgets || {
327369
print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.'

zsh-syntax-highlighting.zsh

-44
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)