@@ -1234,6 +1234,19 @@ _zsh_highlight_main_highlighter_check_path()
1234
1234
# This function currently assumes it's never called for the command word.
1235
1235
_zsh_highlight_main_highlighter_highlight_argument ()
1236
1236
{
1237
+ if (( $+ _zsh_highlight_main__arg_cache )) ; then
1238
+ local cache_key=$1 $' \0' $2 $' \0' $arg $' \0' $last_arg $' \0' $has_end $' \0' $highlight_glob $' \0' $in_redirection $' \0' $zsyh_user_options [multios]
1239
+ local -a cache_val=(${(@ 0)_zsh_highlight_main__arg_cache[$cache_key]} )
1240
+ if (( $# cache_val )) ; then
1241
+ integer offset=$(( start_pos - $cache_val [- 1 ] ))
1242
+ local start end_ style
1243
+ for start end_ style in $cache_val [1,-2]; do
1244
+ _zsh_highlight_main_add_region_highlight $(( start + offset )) $(( end_ + offset )) $style
1245
+ done
1246
+ return
1247
+ fi
1248
+ fi
1249
+
1237
1250
local base_style=default i=$1 option_eligible=${2:- 1} path_eligible=1 ret start style
1238
1251
local -a highlights
1239
1252
@@ -1381,6 +1394,11 @@ _zsh_highlight_main_highlighter_highlight_argument()
1381
1394
1382
1395
highlights= ($(( start_pos + $1 - 1 )) $end_pos $base_style $highlights )
1383
1396
_zsh_highlight_main_add_many_region_highlights $highlights
1397
+
1398
+ if (( $+ _zsh_highlight_main__arg_cache )) ; then
1399
+ highlights+=($start_pos )
1400
+ _zsh_highlight_main__arg_cache[$cache_key ]=${(pj: \0 : )highlights}
1401
+ fi
1384
1402
}
1385
1403
1386
1404
# Quote Helper Functions
@@ -1761,6 +1779,7 @@ _zsh_highlight_main__precmd_hook() {
1761
1779
1762
1780
_zsh_highlight_main__command_type_cache=()
1763
1781
_zsh_highlight_main__path_cache=()
1782
+ _zsh_highlight_main__arg_cache=()
1764
1783
1765
1784
if [[ $ZSH_VERSION != (5.< 9-> * | < 6-> .* ) ]]; then
1766
1785
_zsh_highlight_main_calculate_styles
@@ -1770,11 +1789,11 @@ _zsh_highlight_main__precmd_hook() {
1770
1789
autoload -Uz add-zsh-hook
1771
1790
if add-zsh-hook precmd _zsh_highlight_main__precmd_hook 2> /dev/null; then
1772
1791
# Initialize caches
1773
- typeset -gA _zsh_highlight_main__command_type_cache _zsh_highlight_main__path_cache
1792
+ typeset -gA _zsh_highlight_main__command_type_cache _zsh_highlight_main__path_cache _zsh_highlight_main__arg_cache
1774
1793
else
1775
1794
print -r -- >&2 ' zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used.'
1776
1795
# Make sure the caches are unset
1777
- unset _zsh_highlight_main__command_type_cache _zsh_highlight_main__path_cache
1796
+ unset _zsh_highlight_main__command_type_cache _zsh_highlight_main__path_cache _zsh_highlight_main__arg_cache
1778
1797
fi
1779
1798
typeset -g a ZSH_HIGHLIGHT_DIRS_BLACKLIST
1780
1799
0 commit comments