From b9b67b9f78baade6faa43d1675986d0640566698 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Aug 2015 09:44:14 +0000 Subject: [PATCH] Don't parse first word of array assignment as command Fixes zsh-users/zsh-syntax-highlighting#178 --- highlighters/main/main-highlighter.zsh | 6 +++++- highlighters/main/test-data/assign.zsh | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5b038b4..1bd1809 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -125,7 +125,11 @@ _zsh_highlight_main_highlighter() *': hashed') style=$ZSH_HIGHLIGHT_STYLES[hashed-command];; *) if _zsh_highlight_main_highlighter_check_assign; then style=$ZSH_HIGHLIGHT_STYLES[assign] - new_expression=true + if [[ $arg[-1] != '(' ]]; then + # assignment to a scalar parameter. + # (For array assignments, the command doesn't start until the ")" token.) + new_expression=true + fi elif _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 0401bf4..61edd6d 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -28,8 +28,9 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='A=1' +BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 + "8 12 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo" )