'main': Apply the parameter expansion logic regardless of the type

The existing check was bogus: parameter expansion doesn't depend on
whether there happens to be a command literally called «$foo».

This enables the parameter elision logic to kick in for words not in
command position.

Fixes #239.
This commit is contained in:
Daniel Shahaf 2020-03-19 22:06:21 +00:00
commit b47387b55e
5 changed files with 47 additions and 7 deletions

View file

@ -422,7 +422,7 @@ _zsh_highlight_highlighter_main_paint()
# Try to expand $1, if it's possible to do so safely.
#
# Uses two parameters from the caller: $parameter_name_pattern and $res.
# Uses one parameter from the caller: $parameter_name_pattern.
#
# If expansion was done, set $reply to the expansion and return true.
# Otherwise, return false.
@ -447,7 +447,7 @@ _zsh_highlight_main_highlighter__try_expand_parameter()
else
parameter_name=${arg:1}
fi
if [[ $res == none ]] && zmodload -e zsh/parameter &&
if zmodload -e zsh/parameter &&
[[ ${parameter_name} =~ ^${~parameter_name_pattern}$ ]] &&
[[ ${parameters[(e)$MATCH]} != *special* ]]
then
@ -745,8 +745,10 @@ _zsh_highlight_main_highlighter_highlight_list()
(( in_param = 1 + $#words ))
args=( $words $args )
arg=$args[1]
_zsh_highlight_main__type "$arg" 0
res=$REPLY
if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then
_zsh_highlight_main__type "$arg" 0
res=$REPLY
fi
fi
}
fi