@@ -73,8 +73,10 @@ _zsh_highlight_main_add_region_highlight() {
73
73
integer start=$1 end=$2
74
74
shift 2
75
75
76
- (( highlighted_alias )) && return
77
- (( in_alias )) && highlighted_alias=1
76
+ if (( in_alias )) ; then
77
+ [[ $1 == unknown-token ]] && alias_style=unknown-token
78
+ return
79
+ fi
78
80
79
81
# The calculation was relative to $buf but region_highlight is relative to $BUFFER.
80
82
(( start += buf_offset ))
@@ -377,15 +379,14 @@ _zsh_highlight_highlighter_main_paint()
377
379
_zsh_highlight_main_highlighter_highlight_list ()
378
380
{
379
381
integer start_pos end_pos=0 buf_offset=$1 has_end=$3
382
+ # alias_style is the style to apply to an alias once in_alias=0
380
383
# last_alias is the last alias arg (lhs) expanded (if in an alias).
381
384
# This allows for expanding alias ls='ls -l' while avoiding loops.
382
- local arg buf=$4 highlight_glob=true last_alias style
385
+ local alias_style arg buf=$4 highlight_glob=true last_alias style
383
386
local in_array_assignment=false # true between 'a=(' and the matching ')'
384
- # highlighted_alias is 1 when the alias arg has been highlighted with a non-alias style.
385
- # E.g. alias x=ls; x has been highlighted as alias AND command.
386
387
# in_alias is equal to the number of shifts needed until arg=args[1] pops an
387
388
# arg from BUFFER and not added by an alias.
388
- integer highlighted_alias=0 in_alias=0 len=$# buf
389
+ integer in_alias=0 len=$# buf
389
390
local -a match mbegin mend list_highlights
390
391
# seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a
391
392
local -A seen_alias
@@ -458,7 +459,11 @@ _zsh_highlight_main_highlighter_highlight_list()
458
459
shift args
459
460
if (( in_alias )) ; then
460
461
(( in_alias-- ))
461
- (( in_alias == 0 )) && highlighted_alias=0 last_alias= seen_alias=()
462
+ if (( in_alias == 0 )) ; then
463
+ last_alias= seen_alias=()
464
+ # start_pos and end_pos are of the alias (previous $arg) here
465
+ _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
466
+ fi
462
467
fi
463
468
464
469
# Initialize this_word and next_word.
@@ -535,6 +540,7 @@ _zsh_highlight_main_highlighter_highlight_list()
535
540
# Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar'
536
541
# Also mark insane aliases as unknown-token (cf. #263).
537
542
if (( $+ seen_alias[$arg ] )) || [[ $arg == ?* = * ]]; then
543
+ (( in_alias == 0 )) && in_alias=1
538
544
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
539
545
continue
540
546
fi
@@ -550,7 +556,7 @@ _zsh_highlight_main_highlighter_highlight_list()
550
556
fi
551
557
args=( $alias_args $args )
552
558
if (( in_alias == 0 )) ; then
553
- _zsh_highlight_main_add_region_highlight $start_pos $end_pos alias
559
+ alias_style= alias
554
560
# Add one because we will in_alias-- on the next loop iteration so
555
561
# this iteration should be considered in in_alias as well
556
562
(( in_alias += $# alias_args + 1 ))
@@ -909,6 +915,7 @@ _zsh_highlight_main_highlighter_highlight_list()
909
915
fi
910
916
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
911
917
done
918
+ (( in_alias == 1 )) && in_alias= 0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
912
919
[[ " $proc_buf " = (# b)(#s)(([[:space:]]|\\$'\n')#) ]]
913
920
REPLY=$(( end_pos + ${# match[1]} - 1 ))
914
921
reply=($list_highlights )
0 commit comments