From 4c23a2fd1b90db08551d909ab7323bb82ea5de49 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 13 Mar 2016 02:47:25 +0000 Subject: [PATCH] 'main': Highlight lone '!' correctly: it's not a history expansion. While here, also add a test for the '!' reserved word (which is highlighted since c216242b). --- highlighters/main/main-highlighter.zsh | 6 ++++-- highlighters/main/test-data/history-expansion.zsh | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 981d3bd..a6465a6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -342,7 +342,9 @@ _zsh_highlight_main_highlighter() # (For array assignments, the command doesn't start until the ")" token.) next_word+=':start:' fi - elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then + elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then + style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + elif [[ $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ $this_word == *':regular:'* ]]; then @@ -414,7 +416,7 @@ _zsh_highlight_main_highlighter() [*?]*|*[^\\][*?]*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if false; then - elif [[ $arg[0,1] = $histchars[0,1] ]]; then + elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ $this_word == *':regular:'* ]]; then diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index 0e1c4a6..0e818b8 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -28,10 +28,12 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[default]=$unused_highlight -BUFFER='!foo bar !baz' +BUFFER='!foo bar !baz ! ; !' expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !foo "6 8 $ZSH_HIGHLIGHT_STYLES[default]" # bar "10 13 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !baz + "15 15 $ZSH_HIGHLIGHT_STYLES[default]" # ! (before the semicolon) + "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ! (after the semicolon) )