diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f222877..61596d0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -101,6 +101,9 @@ _zsh_highlight_main_highlighter() # Tokens that, at (naively-determined) "command position", are followed by # a de jure command position. All of these are reserved words. ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=( + $'\x7b' # block + $'\x28' # subshell + '()' # anonymous function 'while' 'until' 'if' @@ -247,6 +250,9 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[reserved-word] _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style already_added=1 + elif [[ $arg == '()' ]]; then + # anonymous function + style=$ZSH_HIGHLIGHT_STYLES[reserved-word] else if _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] diff --git a/highlighters/main/test-data/anonymous-function.zsh b/highlighters/main/test-data/anonymous-function.zsh index 9e3e279..62714ed 100644 --- a/highlighters/main/test-data/anonymous-function.zsh +++ b/highlighters/main/test-data/anonymous-function.zsh @@ -30,11 +30,11 @@ BUFFER='() echo hello; () { echo world }' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # () - "4 7 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo + "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () + "4 7 $ZSH_HIGHLIGHT_STYLES[command]" # echo "9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello "14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # () - "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # { - "21 24 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo + "16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () + "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # { + "21 24 $ZSH_HIGHLIGHT_STYLES[command]" # echo ) diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index 31f8507..f8d61a0 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -31,6 +31,6 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar - "15 16 $ZSH_HIGHLIGHT_STYLES[command] 'issue #166'" # cd + "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar )