'main': Highlight escaped reserved words properly. Fixes #701.

This commit is contained in:
Daniel Shahaf 2020-03-17 02:12:00 +00:00 committed by Daniel Shahaf
parent f284041305
commit 39977391de
2 changed files with 9 additions and 4 deletions

View File

@ -153,9 +153,12 @@ _zsh_highlight_main_calculate_fallback() {
# #
# If $2 is 0, do not consider aliases. # If $2 is 0, do not consider aliases.
# #
# If $3 is 0, do not consider reserved words.
#
# The result will be stored in REPLY. # The result will be stored in REPLY.
_zsh_highlight_main__type() { _zsh_highlight_main__type() {
integer -r aliases_allowed=${2-1} integer -r aliases_allowed=${2-1}
integer -r resword_allowed=${3-1}
# We won't cache replies of anything that exists as an alias at all, to # We won't cache replies of anything that exists as an alias at all, to
# ensure the cached value is correct regardless of $aliases_allowed. # ensure the cached value is correct regardless of $aliases_allowed.
# #
@ -186,7 +189,7 @@ _zsh_highlight_main__type() {
REPLY=alias REPLY=alias
elif [[ $1 == *.* && -n ${1%.*} ]] && (( $+saliases[(e)${1##*.}] )); then elif [[ $1 == *.* && -n ${1%.*} ]] && (( $+saliases[(e)${1##*.}] )); then
REPLY='suffix alias' REPLY='suffix alias'
elif (( $reswords[(Ie)$1] )); then elif (( resword_allowed )) && (( $reswords[(Ie)$1] )); then
REPLY=reserved REPLY=reserved
elif (( $+functions[(e)$1] )); then elif (( $+functions[(e)$1] )); then
REPLY=function REPLY=function
@ -616,7 +619,7 @@ _zsh_highlight_main_highlighter_highlight_list()
if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then
# Expand aliases. # Expand aliases.
# An alias is ineligible for expansion while it's being expanded (see #652/#653). # An alias is ineligible for expansion while it's being expanded (see #652/#653).
_zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))" _zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))" 1
local res="$REPLY" local res="$REPLY"
if [[ $res == "alias" ]]; then if [[ $res == "alias" ]]; then
# Mark insane aliases as unknown-token (cf. #263). # Mark insane aliases as unknown-token (cf. #263).
@ -648,7 +651,7 @@ _zsh_highlight_main_highlighter_highlight_list()
continue continue
else else
_zsh_highlight_main_highlighter_expand_path $arg _zsh_highlight_main_highlighter_expand_path $arg
_zsh_highlight_main__type "$REPLY" 0 _zsh_highlight_main__type "$REPLY" 0 0
res="$REPLY" res="$REPLY"
fi fi
fi fi

View File

@ -31,5 +31,7 @@
BUFFER=$'\\local a=( * )' BUFFER=$'\\local a=( * )'
expected_region_highlight=( expected_region_highlight=(
'1 6 builtin "issue #701"' # \\local '1 6 builtin' # \\local
'8 14 default' # a=( * )
'12 12 globbing' # *
) )