From 5694221939b79e9e6243d733c081a21d3cba8df4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 07:50:38 +0000 Subject: [PATCH] 'main': Highlight the 'command' precommand. Fixes #343. --- highlighters/main/main-highlighter.zsh | 9 +++++---- highlighters/main/test-data/precommand2.zsh | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 695d4fd..f8cd254 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -242,6 +242,7 @@ _zsh_highlight_highlighter_main_paint() # for that precommand. local -A precommand_options precommand_options=( + 'command' '' 'sudo' Cgprtu ) @@ -263,7 +264,7 @@ _zsh_highlight_highlighter_main_paint() # ';;' ';&' ';|' ) ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( - 'builtin' 'command' 'exec' 'nocorrect' 'noglob' + 'builtin' 'exec' 'nocorrect' 'noglob' 'pkexec' # immune to #121 because it's usually not passed --option flags ) @@ -572,14 +573,14 @@ _zsh_highlight_main_highlighter_highlight_list() style=reserved-word # de facto a reserved word, although not de jure next_word=':start:' elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word - if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then - style=precommand - elif (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then + if (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then style=precommand flags_with_argument=${precommand_options[$arg]} next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then + style=precommand else case $res in reserved) # reserved word diff --git a/highlighters/main/test-data/precommand2.zsh b/highlighters/main/test-data/precommand2.zsh index 3d8f332..75dceab 100644 --- a/highlighters/main/test-data/precommand2.zsh +++ b/highlighters/main/test-data/precommand2.zsh @@ -31,6 +31,6 @@ BUFFER='command -v ls' expected_region_highlight=( "1 7 precommand" # command - "9 10 single-hyphen-option 'issue #343'" # -v - "12 13 command 'issue #343'" # ls + "9 10 single-hyphen-option" # -v + "12 13 command" # ls )