Skip to content

Commit f8a0395

Browse files
committed
'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.
1 parent 2aca4e2 commit f8a0395

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

highlighters/main/main-highlighter.zsh

+6-4
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ _zsh_highlight_highlighter_main_paint()
422422

423423
# Try to expand $1, if it's possible to do so safely.
424424
#
425-
# Uses two parameters from the caller: $parameter_name_pattern and $res.
425+
# Uses one parameter from the caller: $parameter_name_pattern.
426426
#
427427
# If expansion was done, set $reply to the expansion and return true.
428428
# Otherwise, return false.
@@ -447,7 +447,7 @@ _zsh_highlight_main_highlighter__try_expand_parameter()
447447
else
448448
parameter_name=${arg:1}
449449
fi
450-
if [[ $res == none ]] && zmodload -e zsh/parameter &&
450+
if zmodload -e zsh/parameter &&
451451
[[ ${parameter_name} =~ ^${~parameter_name_pattern}$ ]] &&
452452
[[ ${parameters[(e)$MATCH]} != *special* ]]
453453
then
@@ -745,8 +745,10 @@ _zsh_highlight_main_highlighter_highlight_list()
745745
(( in_param = 1 + $#words ))
746746
args=( $words $args )
747747
arg=$args[1]
748-
_zsh_highlight_main__type "$arg" 0
749-
res=$REPLY
748+
if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then
749+
_zsh_highlight_main__type "$arg" 0
750+
res=$REPLY
751+
fi
750752
fi
751753
}
752754
fi

highlighters/main/test-data/brackets-mismatch7.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ expected_region_highlight=(
3939
'11 11 commandseparator' # ;
4040
'13 14 reserved-word' # do
4141
'16 19 builtin' # echo
42-
'21 22 default' # $n
42+
'21 22 comment' # $n - because it's unset when the line is parsed
4343
'23 23 commandseparator' # ;
4444
'25 27 unknown-token' # end
4545
)

highlighters/main/test-data/order-path-after-dollar.zsh

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# vim: ft=zsh sw=2 ts=2 et
2929
# -------------------------------------------------------------------------------------------------
3030

31+
local foo='is set'
3132
touch '$foo'
3233
BUFFER=': $foo \$foo'
3334

0 commit comments

Comments
 (0)