Skip to content

Commit

Permalink
'main': Apply the parameter expansion logic regardless of the type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danielshahaf committed Mar 28, 2020
1 parent 2aca4e2 commit f8a0395
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion highlighters/main/test-data/brackets-mismatch7.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ expected_region_highlight=(
'11 11 commandseparator' # ;
'13 14 reserved-word' # do
'16 19 builtin' # echo
'21 22 default' # $n
'21 22 comment' # $n - because it's unset when the line is parsed
'23 23 commandseparator' # ;
'25 27 unknown-token' # end
)
1 change: 1 addition & 0 deletions highlighters/main/test-data/order-path-after-dollar.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------

local foo='is set'
touch '$foo'
BUFFER=': $foo \$foo'

Expand Down

0 comments on commit f8a0395

Please sign in to comment.