Compare commits

...

3 Commits

Author SHA1 Message Date
Daniel Shahaf
023c994cdf 'main': Update comments after last commit. No functional change. 2020-01-12 18:16:31 +00:00
Daniel Shahaf
e5acdf0ba5 'main': Simplify alias handling.
$last_alias isn't needed; there's no reason to treat loops of length 2
(alias a=b b=a) differently to loops of length 1 (alias a=a), length 3
(alias a=b b=c c=a), or length N.

The «(( $+seen_alias[$arg] ))» check is redundant as of the last commit:
the enclosing condition ensures that $res is "alias", which implies that
«(( $+seen_alias[$arg] ))» is false.
2019-12-27 09:24:01 +00:00
Daniel Shahaf
44aa6f1f4e 'main': Fix issue #652. 2019-12-27 09:20:18 +00:00
2 changed files with 8 additions and 11 deletions

View File

@ -393,9 +393,7 @@ _zsh_highlight_main_highlighter_highlight_list()
# alias_style is the style to apply to an alias once in_alias=0 # alias_style is the style to apply to an alias once in_alias=0
# Usually 'alias' but set to 'unknown-token' if any word expanded from # Usually 'alias' but set to 'unknown-token' if any word expanded from
# the alias would be highlighted as unknown-token # the alias would be highlighted as unknown-token
# last_alias is the last alias arg (lhs) expanded (if in an alias). local alias_style arg buf=$4 highlight_glob=true style
# This allows for expanding alias ls='ls -l' while avoiding loops.
local alias_style arg buf=$4 highlight_glob=true last_alias style
local in_array_assignment=false # true between 'a=(' and the matching ')' local in_array_assignment=false # true between 'a=(' and the matching ')'
# in_alias is equal to the number of shifts needed until arg=args[1] pops an # in_alias is equal to the number of shifts needed until arg=args[1] pops an
# arg from BUFFER and not added by an alias. # arg from BUFFER and not added by an alias.
@ -473,7 +471,7 @@ _zsh_highlight_main_highlighter_highlight_list()
if (( in_alias )); then if (( in_alias )); then
(( in_alias-- )) (( in_alias-- ))
if (( in_alias == 0 )); then if (( in_alias == 0 )); then
last_alias= seen_alias=() seen_alias=()
# start_pos and end_pos are of the alias (previous $arg) here # start_pos and end_pos are of the alias (previous $arg) here
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
fi fi
@ -547,18 +545,17 @@ _zsh_highlight_main_highlighter_highlight_list()
if [[ $this_word == *:start:* ]] && ! (( in_redirection )); then if [[ $this_word == *:start:* ]] && ! (( in_redirection )); then
# Expand aliases. # Expand aliases.
_zsh_highlight_main__type "$arg" # An alias is ineligible for expansion while it's being expanded (see #652/#653).
_zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))"
local res="$REPLY" local res="$REPLY"
if [[ $res == "alias" ]] && [[ $last_alias != $arg ]]; then if [[ $res == "alias" ]]; then
# Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' # Mark insane aliases as unknown-token (cf. #263).
# Also mark insane aliases as unknown-token (cf. #263). if [[ $arg == ?*=* ]]; then
if (( $+seen_alias[$arg] )) || [[ $arg == ?*=* ]]; then
(( in_alias == 0 )) && in_alias=1 (( in_alias == 0 )) && in_alias=1
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
continue continue
fi fi
seen_alias[$arg]=1 seen_alias[$arg]=1
last_alias=$arg
_zsh_highlight_main__resolve_alias $arg _zsh_highlight_main__resolve_alias $arg
local -a alias_args local -a alias_args
# Elision is desired in case alias x='' # Elision is desired in case alias x=''

View File

@ -32,5 +32,5 @@ alias ls=tmp tmp='command ls'
BUFFER='ls' BUFFER='ls'
expected_region_highlight=( expected_region_highlight=(
"1 2 alias 'issue #652'" # ls "1 2 alias" # ls
) )