From 40b5688633bbb81d4d6d15029c78c422c5f212d7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 02:12:00 +0000 Subject: [PATCH] 'main': Highlight escaped reserved words properly. Fixes #701. --- highlighters/main/main-highlighter.zsh | 9 ++++++--- .../main/test-data/escaped-reserved-word-isnt.zsh | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 34a206fcd..a2e9d2fa9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -146,9 +146,12 @@ _zsh_highlight_main_calculate_fallback() { # # If $2 is 0, do not consider aliases. # +# If $3 is 0, do not consider reserved words. +# # The result will be stored in REPLY. _zsh_highlight_main__type() { 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 # ensure the cached value is correct regardless of $aliases_allowed. # @@ -177,7 +180,7 @@ _zsh_highlight_main__type() { REPLY=alias elif [[ $1 == *.* && -n ${1%.*} ]] && (( $+saliases[(e)${1##*.}] )); then REPLY='suffix alias' - elif (( $reswords[(Ie)$1] )); then + elif (( resword_allowed )) && (( $reswords[(Ie)$1] )); then REPLY=reserved elif (( $+functions[(e)$1] )); then REPLY=function @@ -592,7 +595,7 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then # Expand aliases. # 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" if [[ $res == "alias" ]]; then # Mark insane aliases as unknown-token (cf. #263). @@ -624,7 +627,7 @@ _zsh_highlight_main_highlighter_highlight_list() continue else _zsh_highlight_main_highlighter_expand_path $arg - _zsh_highlight_main__type "$REPLY" 0 + _zsh_highlight_main__type "$REPLY" 0 0 res="$REPLY" fi fi diff --git a/highlighters/main/test-data/escaped-reserved-word-isnt.zsh b/highlighters/main/test-data/escaped-reserved-word-isnt.zsh index 97c26aad5..14e335b3e 100644 --- a/highlighters/main/test-data/escaped-reserved-word-isnt.zsh +++ b/highlighters/main/test-data/escaped-reserved-word-isnt.zsh @@ -31,5 +31,7 @@ BUFFER=$'\\local a=( * )' expected_region_highlight=( - '1 6 builtin "issue #701"' # \\local + '1 6 builtin' # \\local + '8 14 default' # a=( * ) + '12 12 globbing' # * )