@@ -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,11 @@ _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
+ # Remove leading 0 entries
603
+ in_alias=($in_alias [$in_alias [(i)< 1-> ],-1])
604
+ if (( $# in_alias == 0 )) ; then
602
605
seen_alias=()
603
606
# start_pos and end_pos are of the alias (previous $arg) here
604
607
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
@@ -637,7 +640,7 @@ _zsh_highlight_main_highlighter_highlight_list()
637
640
fi
638
641
fi
639
642
640
- if (( in_alias == 0 && in_param == 0 )) ; then
643
+ if (( $# in_alias == 0 && in_param == 0 )) ; then
641
644
# Compute the new $start_pos and $end_pos, skipping over whitespace in $buf.
642
645
[[ " $proc_buf " = (# b)(#s)(([ $'\t']|[\\]$'\n')#)(?|)* ]]
643
646
# The first, outer parenthesis
@@ -693,7 +696,6 @@ _zsh_highlight_main_highlighter_highlight_list()
693
696
if [[ $res == " alias" ]]; then
694
697
# Mark insane aliases as unknown-token (cf. #263).
695
698
if [[ $arg == ?* = * ]]; then
696
- (( in_alias == 0 )) && in_alias=1
697
699
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
698
700
continue
699
701
fi
@@ -707,15 +709,15 @@ _zsh_highlight_main_highlighter_highlight_list()
707
709
alias_args=(${(z)REPLY} )
708
710
fi
709
711
args=( $alias_args $args )
710
- if (( in_alias == 0 )) ; then
712
+ if (( $# in_alias == 0 )) ; then
711
713
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
714
else
716
- # This arg is already included in the count, so no need to + 1 .
717
- (( in_alias += $# alias_args ))
715
+ # Transfer the count of this arg to the new element about to be appended .
716
+ (( in_alias[ 1 ] -- ))
718
717
fi
718
+ # Add one because we will in_alias[1]-- on the next loop iteration so
719
+ # this iteration should be considered in in_alias as well
720
+ in_alias=( $(( $# alias_args + 1 )) $in_alias )
719
721
(( in_redirection++ )) # Stall this arg
720
722
continue
721
723
else
@@ -854,7 +856,7 @@ _zsh_highlight_main_highlighter_highlight_list()
854
856
style=commandseparator
855
857
elif [[ $this_word == * ' :start:' * ]] && [[ $arg == $' \n ' ]]; then
856
858
style=commandseparator
857
- elif [[ $this_word == * ' :start:' * ]] && [[ $arg == ' ;' ]] && (( in_alias )) ; then
859
+ elif [[ $this_word == * ' :start:' * ]] && [[ $arg == ' ;' ]] && (( $# in_alias )) ; then
858
860
style=commandseparator
859
861
else
860
862
# Empty commands (semicolon follows nothing) are valid syntax.
@@ -1147,7 +1149,7 @@ _zsh_highlight_main_highlighter_highlight_list()
1147
1149
fi
1148
1150
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
1149
1151
done
1150
- (( in_alias == 1 )) && in_alias= 0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
1152
+ (( $# in_alias )) && in_alias= () _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
1151
1153
(( in_param == 1 )) && in_param= 0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style
1152
1154
[[ " $proc_buf " = (# b)(#s)(([[:space:]]|\\$'\n')#) ]]
1153
1155
REPLY=$(( end_pos + ${# match[1]} - 1 ))
@@ -1258,7 +1260,7 @@ _zsh_highlight_main_highlighter_check_path()
1258
1260
1259
1261
# If this word ends the buffer, check if it's the prefix of a valid path.
1260
1262
if (( has_end && (len == end_pos) )) &&
1261
- (( ! in_alias )) &&
1263
+ (( ! $# in_alias )) &&
1262
1264
[[ $WIDGET != zle-line-finish ]]; then
1263
1265
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
1264
1266
local -a tmp
0 commit comments