Skip to content

Commit 3997739

Browse files
committed
'main': Highlight escaped reserved words properly. Fixes #701.
1 parent f284041 commit 3997739

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@ _zsh_highlight_main_calculate_fallback() {
153153
#
154154
# If $2 is 0, do not consider aliases.
155155
#
156+
# If $3 is 0, do not consider reserved words.
157+
#
156158
# The result will be stored in REPLY.
157159
_zsh_highlight_main__type() {
158160
integer -r aliases_allowed=${2-1}
161+
integer -r resword_allowed=${3-1}
159162
# We won't cache replies of anything that exists as an alias at all, to
160163
# ensure the cached value is correct regardless of $aliases_allowed.
161164
#
@@ -186,7 +189,7 @@ _zsh_highlight_main__type() {
186189
REPLY=alias
187190
elif [[ $1 == *.* && -n ${1%.*} ]] && (( $+saliases[(e)${1##*.}] )); then
188191
REPLY='suffix alias'
189-
elif (( $reswords[(Ie)$1] )); then
192+
elif (( resword_allowed )) && (( $reswords[(Ie)$1] )); then
190193
REPLY=reserved
191194
elif (( $+functions[(e)$1] )); then
192195
REPLY=function
@@ -616,7 +619,7 @@ _zsh_highlight_main_highlighter_highlight_list()
616619
if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then
617620
# Expand aliases.
618621
# An alias is ineligible for expansion while it's being expanded (see #652/#653).
619-
_zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))"
622+
_zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))" 1
620623
local res="$REPLY"
621624
if [[ $res == "alias" ]]; then
622625
# Mark insane aliases as unknown-token (cf. #263).
@@ -648,7 +651,7 @@ _zsh_highlight_main_highlighter_highlight_list()
648651
continue
649652
else
650653
_zsh_highlight_main_highlighter_expand_path $arg
651-
_zsh_highlight_main__type "$REPLY" 0
654+
_zsh_highlight_main__type "$REPLY" 0 0
652655
res="$REPLY"
653656
fi
654657
fi

highlighters/main/test-data/escaped-reserved-word-isnt.zsh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@
3131
BUFFER=$'\\local a=( * )'
3232

3333
expected_region_highlight=(
34-
'1 6 builtin "issue #701"' # \\local
34+
'1 6 builtin' # \\local
35+
'8 14 default' # a=( * )
36+
'12 12 globbing' # *
3537
)

0 commit comments

Comments
 (0)