command word: Start fixing issue #207, "Word following certain reserved words should be a command word".

This commit is contained in:
Daniel Shahaf 2015-10-28 08:04:43 +02:00
parent 87deac3062
commit b397b12ac1
2 changed files with 15 additions and 4 deletions

View File

@ -87,6 +87,7 @@ _zsh_highlight_main_highlighter()
local start_pos=0 end_pos highlight_glob=true arg style
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
local buf="$PREBUFFER$BUFFER"
region_highlight=()
@ -97,6 +98,15 @@ _zsh_highlight_main_highlighter()
'builtin' 'command' 'exec' 'nocorrect' 'noglob'
)
# Tokens that, at (naively-determined) "command position", are followed by
# a de jure command position.
ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=(
'while'
'if'
'then'
'do'
)
# State machine
#
# The states are:
@ -284,6 +294,7 @@ _zsh_highlight_main_highlighter()
# TODO maybe check *':regular:'* here?
next_word=':start:'
elif
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:' ]] ||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then
next_word=':start:'
fi

View File

@ -32,15 +32,15 @@ BUFFER='while if echo Hello; then ls /; fi; do stat "x"; done'
expected_region_highlight+=(
"1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while
"7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #207'" # if
"10 13 $ZSH_HIGHLIGHT_STYLES[builtin] 'issue #207'" # echo
"7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # if
"10 13 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo
"15 19 $ZSH_HIGHLIGHT_STYLES[default]" # Hello
"22 25 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # then
"27 28 $ZSH_HIGHLIGHT_STYLES[command] 'issue #207'" # ls
"27 28 $ZSH_HIGHLIGHT_STYLES[command]" # ls
"30 30 $ZSH_HIGHLIGHT_STYLES[path]" # /
"33 34 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi
"37 38 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do
"40 43 $ZSH_HIGHLIGHT_STYLES[command] 'issue #207'" # stat
"40 43 $ZSH_HIGHLIGHT_STYLES[command]" # stat
"45 47 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x"
"50 53 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done
)