mirror of
https://github.com/zsh-users/zsh-syntax-highlighting.git
synced 2025-01-30 09:47:13 +08:00
command word: Start fixing issue #207, "Word following certain reserved words should be a command word".
This commit is contained in:
parent
87deac3062
commit
b397b12ac1
@ -87,6 +87,7 @@ _zsh_highlight_main_highlighter()
|
|||||||
local start_pos=0 end_pos highlight_glob=true arg style
|
local start_pos=0 end_pos highlight_glob=true arg style
|
||||||
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
|
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
|
||||||
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
|
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
|
||||||
|
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
|
||||||
local buf="$PREBUFFER$BUFFER"
|
local buf="$PREBUFFER$BUFFER"
|
||||||
region_highlight=()
|
region_highlight=()
|
||||||
|
|
||||||
@ -97,6 +98,15 @@ _zsh_highlight_main_highlighter()
|
|||||||
'builtin' 'command' 'exec' 'nocorrect' 'noglob'
|
'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
|
# State machine
|
||||||
#
|
#
|
||||||
# The states are:
|
# The states are:
|
||||||
@ -284,6 +294,7 @@ _zsh_highlight_main_highlighter()
|
|||||||
# TODO maybe check *':regular:'* here?
|
# TODO maybe check *':regular:'* here?
|
||||||
next_word=':start:'
|
next_word=':start:'
|
||||||
elif
|
elif
|
||||||
|
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:' ]] ||
|
||||||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then
|
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then
|
||||||
next_word=':start:'
|
next_word=':start:'
|
||||||
fi
|
fi
|
||||||
|
@ -32,15 +32,15 @@ BUFFER='while if echo Hello; then ls /; fi; do stat "x"; done'
|
|||||||
|
|
||||||
expected_region_highlight+=(
|
expected_region_highlight+=(
|
||||||
"1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while
|
"1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while
|
||||||
"7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #207'" # if
|
"7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # if
|
||||||
"10 13 $ZSH_HIGHLIGHT_STYLES[builtin] 'issue #207'" # echo
|
"10 13 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo
|
||||||
"15 19 $ZSH_HIGHLIGHT_STYLES[default]" # Hello
|
"15 19 $ZSH_HIGHLIGHT_STYLES[default]" # Hello
|
||||||
"22 25 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # then
|
"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]" # /
|
"30 30 $ZSH_HIGHLIGHT_STYLES[path]" # /
|
||||||
"33 34 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi
|
"33 34 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi
|
||||||
"37 38 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do
|
"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"
|
"45 47 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x"
|
||||||
"50 53 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done
|
"50 53 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user