Skip to content

Commit 8a1bd7c

Browse files
committed
driver: Move the initialization of $zsh_highlight__memo_feature out of the entry point function.
This is needed for feature/redrawhook to be able to use it.
1 parent d9a7963 commit 8a1bd7c

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

zsh-syntax-highlighting.zsh

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,12 @@ else
6262
typeset -g zsh_highlight__pat_static_bug=true
6363
fi
6464

65-
# Array declaring active highlighters names.
66-
typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS
65+
# Probe the memo= feature, once. When this anonymous function returns,
66+
# $zsh_highlight__memo_feature will be set (either to 0 or to 1).
67+
() {
68+
# Provide a mock $region_highlight. (The test suite's mock might not have been set up yet.)
69+
(( ${+region_highlight} )) || typeset -a region_highlight
6770

68-
# Update ZLE buffer syntax highlighting.
69-
#
70-
# Invokes each highlighter that needs updating.
71-
# This function is supposed to be called whenever the ZLE state changes.
72-
_zsh_highlight()
73-
{
74-
# Store the previous command return code to restore it whatever happens.
75-
local ret=$?
76-
# Make it read-only. Can't combine this with the previous line when POSIX_BUILTINS may be set.
77-
typeset -r ret
78-
79-
# $region_highlight should be predefined, either by zle or by the test suite's mock (non-special) array.
80-
(( ${+region_highlight} )) || {
81-
echo >&2 'zsh-syntax-highlighting: error: $region_highlight is not defined'
82-
echo >&2 'zsh-syntax-highlighting: (Check whether zsh-syntax-highlighting was installed according to the instructions.)'
83-
return $ret
84-
}
85-
86-
# Probe the memo= feature, once.
8771
(( ${+zsh_highlight__memo_feature} )) || {
8872
region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" )
8973
case ${region_highlight[-1]} in
@@ -126,6 +110,28 @@ _zsh_highlight()
126110
esac
127111
region_highlight[-1]=()
128112
}
113+
}
114+
115+
# Array declaring active highlighters names.
116+
typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS
117+
118+
# Update ZLE buffer syntax highlighting.
119+
#
120+
# Invokes each highlighter that needs updating.
121+
# This function is supposed to be called whenever the ZLE state changes.
122+
_zsh_highlight()
123+
{
124+
# Store the previous command return code to restore it whatever happens.
125+
local ret=$?
126+
# Make it read-only. Can't combine this with the previous line when POSIX_BUILTINS may be set.
127+
typeset -r ret
128+
129+
# $region_highlight should be predefined, either by zle or by the test suite's mock (non-special) array.
130+
(( ${+region_highlight} )) || {
131+
echo >&2 'zsh-syntax-highlighting: error: $region_highlight is not defined'
132+
echo >&2 'zsh-syntax-highlighting: (Check whether zsh-syntax-highlighting was installed according to the instructions.)'
133+
return $ret
134+
}
129135

130136
# Reset region_highlight to build it from scratch
131137
if (( zsh_highlight__memo_feature )); then

0 commit comments

Comments
 (0)