@@ -76,7 +76,7 @@ _zsh_highlight_main_add_region_highlight() {
76
76
integer start=$1 end=$2
77
77
shift 2
78
78
79
- if (( in_alias )) ; then
79
+ if (( $# in_alias )) ; then
80
80
[[ $1 == unknown-token ]] && alias_style=unknown-token
81
81
return
82
82
fi
@@ -498,17 +498,18 @@ _zsh_highlight_main_highlighter__try_expand_parameter()
498
498
_zsh_highlight_main_highlighter_highlight_list ()
499
499
{
500
500
integer start_pos end_pos=0 buf_offset=$1 has_end=$3
501
- # alias_style is the style to apply to an alias once in_alias=0
501
+ # alias_style is the style to apply to an alias once $# in_alias=0
502
502
# Usually 'alias' but set to 'unknown-token' if any word expanded from
503
503
# the alias would be highlighted as unknown-token
504
504
# param_style is analogous for parameter expansions
505
505
local alias_style param_style last_arg arg buf=$4 highlight_glob=true saw_assignment=false style
506
506
local in_array_assignment=false # true between 'a=(' and the matching ')'
507
- # in_alias is equal to the number of shifts needed until arg=args[1] pops an
508
- # arg from BUFFER and not added by an alias.
507
+ # in_alias is an array of integers with each element equal to the number
508
+ # of shifts needed until arg=args[1] pops an arg from the next level up
509
+ # alias or from BUFFER.
509
510
# in_param is analogous for parameter expansions
510
- integer in_alias=0 in_param=0 len=$# buf
511
- local -a match mbegin mend list_highlights
511
+ integer in_param=0 len=$# buf
512
+ local -a in_alias match mbegin mend list_highlights
512
513
# seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a
513
514
local -A seen_alias
514
515
# Pattern for parameter names
@@ -596,9 +597,12 @@ _zsh_highlight_main_highlighter_highlight_list()
596
597
last_arg=$arg
597
598
arg=$args [1]
598
599
shift args
599
- if (( in_alias )) ; then
600
- (( in_alias-- ))
601
- if (( in_alias == 0 )) ; then
600
+ if (( $# in_alias )) ; then
601
+ (( in_alias[- 1 ]-- ))
602
+ while (( $# in_alias && in_alias[- 1 ] == 0 )) ; do
603
+ in_alias=($in_alias [1,-2])
604
+ done
605
+ if (( $# in_alias == 0 )) ; then
602
606
seen_alias=()
603
607
# start_pos and end_pos are of the alias (previous $arg) here
604
608
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
@@ -637,7 +641,7 @@ _zsh_highlight_main_highlighter_highlight_list()
637
641
fi
638
642
fi
639
643
640
- if (( in_alias == 0 && in_param == 0 )) ; then
644
+ if (( $# in_alias == 0 && in_param == 0 )) ; then
641
645
# Compute the new $start_pos and $end_pos, skipping over whitespace in $buf.
642
646
[[ " $proc_buf " = (# b)(#s)(([ $'\t']|[\\]$'\n')#)(?|)* ]]
643
647
# The first, outer parenthesis
@@ -693,7 +697,6 @@ _zsh_highlight_main_highlighter_highlight_list()
693
697
if [[ $res == " alias" ]]; then
694
698
# Mark insane aliases as unknown-token (cf. #263).
695
699
if [[ $arg == ?* = * ]]; then
696
- (( in_alias == 0 )) && in_alias=1
697
700
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
698
701
continue
699
702
fi
@@ -707,15 +710,15 @@ _zsh_highlight_main_highlighter_highlight_list()
707
710
alias_args=(${(z)REPLY} )
708
711
fi
709
712
args=( $alias_args $args )
710
- if (( in_alias == 0 )) ; then
713
+ if (( $# in_alias == 0 )) ; then
711
714
alias_style=alias
712
- # Add one because we will in_alias-- on the next loop iteration so
713
- # this iteration should be considered in in_alias as well
714
- (( in_alias += $# alias_args + 1 ))
715
715
else
716
- # This arg is already included in the count, so no need to + 1 .
717
- (( in_alias += $# alias_args ))
716
+ # Transfer the count of this arg to the new element about to be appended .
717
+ (( in_alias[ - 1 ] -- ))
718
718
fi
719
+ # Add one because we will in_alias[-1]-- on the next loop iteration so
720
+ # this iteration should be considered in in_alias as well
721
+ in_alias+=( $(( $# alias_args + 1 )) )
719
722
(( in_redirection++ )) # Stall this arg
720
723
continue
721
724
else
@@ -854,7 +857,7 @@ _zsh_highlight_main_highlighter_highlight_list()
854
857
style=commandseparator
855
858
elif [[ $this_word == * ' :start:' * ]] && [[ $arg == $' \n ' ]]; then
856
859
style=commandseparator
857
- elif [[ $this_word == * ' :start:' * ]] && [[ $arg == ' ;' ]] && (( in_alias )) ; then
860
+ elif [[ $this_word == * ' :start:' * ]] && [[ $arg == ' ;' ]] && (( $# in_alias )) ; then
858
861
style=commandseparator
859
862
else
860
863
# Empty commands (semicolon follows nothing) are valid syntax.
@@ -1147,7 +1150,7 @@ _zsh_highlight_main_highlighter_highlight_list()
1147
1150
fi
1148
1151
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
1149
1152
done
1150
- (( in_alias == 1 )) && in_alias= 0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
1153
+ (( $# in_alias )) && in_alias= () _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
1151
1154
(( in_param == 1 )) && in_param= 0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style
1152
1155
[[ " $proc_buf " = (# b)(#s)(([[:space:]]|\\$'\n')#) ]]
1153
1156
REPLY=$(( end_pos + ${# match[1]} - 1 ))
@@ -1258,7 +1261,7 @@ _zsh_highlight_main_highlighter_check_path()
1258
1261
1259
1262
# If this word ends the buffer, check if it's the prefix of a valid path.
1260
1263
if (( has_end && (len == end_pos) )) &&
1261
- (( ! in_alias )) &&
1264
+ (( ! $# in_alias )) &&
1262
1265
[[ $WIDGET != zle-line-finish ]]; then
1263
1266
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
1264
1267
local -a tmp
0 commit comments