@@ -89,6 +89,12 @@ _zsh_highlight_main_add_region_highlight() {
89
89
#
90
90
# The result will be stored in REPLY.
91
91
_zsh_highlight_main__type () {
92
+ if (( $+ _zsh_highlight_main__command_type_cache )) ; then
93
+ REPLY=$_zsh_highlight_main__command_type_cache [(e)$1 ]
94
+ if [[ -n " $REPLY " ]]; then
95
+ return
96
+ fi
97
+ fi
92
98
if (( $# options_to_set )) ; then
93
99
setopt localoptions $options_to_set ;
94
100
fi
@@ -113,6 +119,9 @@ _zsh_highlight_main__type() {
113
119
if ! (( $+ REPLY )) ; then
114
120
REPLY=" ${$(LC_ALL=C builtin type -w -- $1 2>/ dev/ null)#*: } "
115
121
fi
122
+ if (( $+ _zsh_highlight_main__command_type_cache )) ; then
123
+ _zsh_highlight_main__command_type_cache[(e)$1 ]=$REPLY
124
+ fi
116
125
}
117
126
118
127
# Check whether the first argument is a redirection operator token.
@@ -662,3 +671,21 @@ _zsh_highlight_main_highlighter_expand_path()
662
671
unset REPLY
663
672
: ${REPLY:= ${(Q)~1} }
664
673
}
674
+
675
+ # -------------------------------------------------------------------------------------------------
676
+ # Main highlighter initialization
677
+ # -------------------------------------------------------------------------------------------------
678
+
679
+ _zsh_highlight_main__precmd_hook () {
680
+ _zsh_highlight_main__command_type_cache=()
681
+ }
682
+
683
+ autoload -U add-zsh-hook
684
+ if add-zsh-hook precmd _zsh_highlight_main__precmd_hook 2> /dev/null; then
685
+ # Initialize command type cache
686
+ typeset -gA _zsh_highlight_main__command_type_cache
687
+ else
688
+ echo ' zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used.' >&2
689
+ # Make sure the cache is unset
690
+ unset _zsh_highlight_main__command_type_cache
691
+ fi
0 commit comments