'main': Fix the last commit's issue concerning parameter expansion at command word.
This commit is contained in:
parent
d21d3b31da
commit
40dcbfbcf6
@ -459,6 +459,26 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Expand parameters.
|
||||||
|
#
|
||||||
|
# ### For now, expand just '$foo', like that, without braces or anything.
|
||||||
|
() {
|
||||||
|
# That's not entirely correct --- if the parameter's value happens to be a reserved
|
||||||
|
# word, the parameter expansion will be highlighted as a reserved word --- but that
|
||||||
|
# incorrectness is outweighed by the usability improvement of permitting the use of
|
||||||
|
# parameters that refer to commands, functions, and builtins.
|
||||||
|
local -a match mbegin mend
|
||||||
|
local MATCH; integer MBEGIN MEND
|
||||||
|
if [[ $res == none ]] && (( ${+parameters} )) &&
|
||||||
|
[[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] &&
|
||||||
|
(( ${+parameters[${MATCH}]} ))
|
||||||
|
then
|
||||||
|
arg=${(P)MATCH}
|
||||||
|
_zsh_highlight_main__type "$arg"
|
||||||
|
res=$REPLY
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Special-case the first word after 'sudo'.
|
# Special-case the first word after 'sudo'.
|
||||||
if (( ! in_redirection )); then
|
if (( ! in_redirection )); then
|
||||||
if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then
|
if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then
|
||||||
@ -499,23 +519,6 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
next_word+=':sudo_opt:'
|
next_word+=':sudo_opt:'
|
||||||
next_word+=':start:'
|
next_word+=':start:'
|
||||||
else
|
else
|
||||||
() {
|
|
||||||
# Special-case: command word is '$foo', like that, without braces or anything.
|
|
||||||
#
|
|
||||||
# That's not entirely correct --- if the parameter's value happens to be a reserved
|
|
||||||
# word, the parameter expansion will be highlighted as a reserved word --- but that
|
|
||||||
# incorrectness is outweighed by the usability improvement of permitting the use of
|
|
||||||
# parameters that refer to commands, functions, and builtins.
|
|
||||||
local -a match mbegin mend
|
|
||||||
local MATCH; integer MBEGIN MEND
|
|
||||||
if [[ $res == none ]] && (( ${+parameters} )) &&
|
|
||||||
[[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] &&
|
|
||||||
(( ${+parameters[${MATCH}]} ))
|
|
||||||
then
|
|
||||||
_zsh_highlight_main__type ${(P)MATCH}
|
|
||||||
res=$REPLY
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
case $res in
|
case $res in
|
||||||
reserved) # reserved word
|
reserved) # reserved word
|
||||||
style=reserved-word
|
style=reserved-word
|
||||||
|
@ -34,5 +34,5 @@ BUFFER='$x "argument"; $y'
|
|||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
"1 2 command" # $x
|
"1 2 command" # $x
|
||||||
"4 13 double-quoted-argument" # "argument"
|
"4 13 double-quoted-argument" # "argument"
|
||||||
"16 17 precommand 'parameter expansion precedes precommand recognition'" # $y (sudo)
|
"16 17 precommand" # $y (sudo)
|
||||||
)
|
)
|
||||||
|
@ -29,9 +29,11 @@
|
|||||||
|
|
||||||
# «/usr» at this point would be highlighted as path_prefix; so should
|
# «/usr» at this point would be highlighted as path_prefix; so should
|
||||||
# a parameter that expands to an equivalent string be highlighted.
|
# a parameter that expands to an equivalent string be highlighted.
|
||||||
|
#
|
||||||
|
# More complicated parameter substitutions aren't eval'd; issue #328.
|
||||||
BUFFER='$PWD; ${PWD}'
|
BUFFER='$PWD; ${PWD}'
|
||||||
|
|
||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
"1 4 unknown-token" # $PWD - not eval'd; issue #328
|
"1 4 path" # $PWD
|
||||||
"7 12 unknown-token" # ${PWD}
|
"7 12 unknown-token" # ${PWD}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user