@@ -299,7 +299,7 @@ _zsh_highlight_highlighter_main_paint()
299
299
_zsh_highlight_main_highlighter_highlight_list ()
300
300
{
301
301
integer start_pos=0 end_pos buf_offset=$1 has_end=$3
302
- local buf=$4 highlight_glob=true arg style
302
+ local buf=$4 highlight_glob=true arg arg_raw style
303
303
local in_array_assignment=false # true between 'a=(' and the matching ')'
304
304
integer len=$# buf
305
305
local -a match mbegin mend list_highlights
@@ -362,6 +362,9 @@ _zsh_highlight_main_highlighter_highlight_list()
362
362
args=(${(z)buf} )
363
363
fi
364
364
for arg in $args ; do
365
+ # Save an unmunged copy of the current word.
366
+ arg_raw=" $arg "
367
+
365
368
# Initialize $next_word.
366
369
if (( in_redirection )) ; then
367
370
(( -- in_redirection ))
@@ -472,6 +475,30 @@ _zsh_highlight_main_highlighter_highlight_list()
472
475
fi
473
476
fi
474
477
478
+ # Expand aliases.
479
+ # TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x'
480
+ # And then the entire 'alias' branch of the 'case' statement should
481
+ # be done here.
482
+ () {
483
+ # TODO: path expansion should happen _after_ alias expansion
484
+ _zsh_highlight_main_highlighter_expand_path $arg
485
+ local expanded_arg=" $REPLY "
486
+ _zsh_highlight_main__type ${expanded_arg}
487
+ }
488
+ local res=" $REPLY "
489
+ if [[ $res == " alias" ]]; then
490
+ _zsh_highlight_main__resolve_alias $arg
491
+ () {
492
+ # Use a temporary array to ensure the subscript is interpreted as
493
+ # an array subscript, not as a scalar subscript
494
+ local -a reply
495
+ # TODO: the ${interactive_comments+set} path needs to skip comments; see test-data/alias-comment1.zsh
496
+ reply=( ${interactive_comments-${(z)REPLY} }
497
+ ${interactive_comments+${(zZ+c+)REPLY} } )
498
+ arg=$reply [1]
499
+ }
500
+ fi
501
+
475
502
# Special-case the first word after 'sudo'.
476
503
if (( ! in_redirection )) ; then
477
504
if [[ $this_word == * ' :sudo_opt:' * ]] && [[ $arg != -* ]]; then
@@ -512,10 +539,6 @@ _zsh_highlight_main_highlighter_highlight_list()
512
539
next_word+=' :sudo_opt:'
513
540
next_word+=' :start:'
514
541
else
515
- _zsh_highlight_main_highlighter_expand_path $arg
516
- local expanded_arg=" $REPLY "
517
- _zsh_highlight_main__type ${expanded_arg}
518
- local res=" $REPLY "
519
542
() {
520
543
# Special-case: command word is '$foo', like that, without braces or anything.
521
544
#
@@ -588,8 +611,9 @@ _zsh_highlight_main_highlighter_highlight_list()
588
611
;;
589
612
' suffix alias' ) style=suffix-alias;;
590
613
alias) () {
614
+ # Make sure to use $arg_raw here, rather than $arg.
591
615
integer insane_alias
592
- case $arg in
616
+ case $arg_raw in
593
617
# Issue #263: aliases with '=' on their LHS.
594
618
#
595
619
# There are three cases:
@@ -603,12 +627,13 @@ _zsh_highlight_main_highlighter_highlight_list()
603
627
esac
604
628
if (( insane_alias )) ; then
605
629
style=unknown-token
630
+ # Calling 'type' again; since __type memoizes the answer, this call is just a hash lookup.
631
+ elif _zsh_highlight_main__type " $arg " ; [[ $REPLY == ' none' ]]; then
632
+ style=unknown-token
606
633
else
607
634
# The common case.
608
635
style=alias
609
- _zsh_highlight_main__resolve_alias $arg
610
- local alias_target=" $REPLY "
611
- [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:# " $alias_target " } && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:# " $arg " } ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg )
636
+ [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:# " $arg " } && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:# " $arg_raw " } ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg_raw )
612
637
fi
613
638
}
614
639
;;
0 commit comments