@@ -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,16 @@ _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
383
+ # Usually 'alias' but set to 'unknown-token' if any word expanded from
384
+ # the alias would be highlighted as unknown-token
380
385
# last_alias is the last alias arg (lhs) expanded (if in an alias).
381
386
# This allows for expanding alias ls='ls -l' while avoiding loops.
382
- local arg buf=$4 highlight_glob=true last_alias style
387
+ local alias_style arg buf=$4 highlight_glob=true last_alias style
383
388
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
389
# in_alias is equal to the number of shifts needed until arg=args[1] pops an
387
390
# arg from BUFFER and not added by an alias.
388
- integer highlighted_alias=0 in_alias=0 len=$# buf
391
+ integer in_alias=0 len=$# buf
389
392
local -a match mbegin mend list_highlights
390
393
# seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a
391
394
local -A seen_alias
@@ -458,7 +461,11 @@ _zsh_highlight_main_highlighter_highlight_list()
458
461
shift args
459
462
if (( in_alias )) ; then
460
463
(( in_alias-- ))
461
- (( in_alias == 0 )) && highlighted_alias=0 last_alias= seen_alias=()
464
+ if (( in_alias == 0 )) ; then
465
+ last_alias= seen_alias=()
466
+ # start_pos and end_pos are of the alias (previous $arg) here
467
+ _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
468
+ fi
462
469
fi
463
470
464
471
# Initialize this_word and next_word.
@@ -535,6 +542,7 @@ _zsh_highlight_main_highlighter_highlight_list()
535
542
# Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar'
536
543
# Also mark insane aliases as unknown-token (cf. #263).
537
544
if (( $+ seen_alias[$arg ] )) || [[ $arg == ?* = * ]]; then
545
+ (( in_alias == 0 )) && in_alias=1
538
546
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
539
547
continue
540
548
fi
@@ -550,7 +558,7 @@ _zsh_highlight_main_highlighter_highlight_list()
550
558
fi
551
559
args=( $alias_args $args )
552
560
if (( in_alias == 0 )) ; then
553
- _zsh_highlight_main_add_region_highlight $start_pos $end_pos alias
561
+ alias_style= alias
554
562
# Add one because we will in_alias-- on the next loop iteration so
555
563
# this iteration should be considered in in_alias as well
556
564
(( in_alias += $# alias_args + 1 ))
@@ -909,6 +917,7 @@ _zsh_highlight_main_highlighter_highlight_list()
909
917
fi
910
918
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
911
919
done
920
+ (( in_alias == 1 )) && in_alias= 0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
912
921
[[ " $proc_buf " = (# b)(#s)(([[:space:]]|\\$'\n')#) ]]
913
922
REPLY=$(( end_pos + ${# match[1]} - 1 ))
914
923
reply=($list_highlights )
0 commit comments