Highlight subshells and anonymous functions correctly.
Fixes zsh-users/zsh-syntax-highlighting#166. Fixes zsh-users/zsh-syntax-highlighting#194. Builds upon the issue #207 work.
This commit is contained in:
parent
c216242b46
commit
0d1bfbcbfa
@ -101,6 +101,9 @@ _zsh_highlight_main_highlighter()
|
|||||||
# Tokens that, at (naively-determined) "command position", are followed by
|
# Tokens that, at (naively-determined) "command position", are followed by
|
||||||
# a de jure command position. All of these are reserved words.
|
# a de jure command position. All of these are reserved words.
|
||||||
ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=(
|
ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=(
|
||||||
|
$'\x7b' # block
|
||||||
|
$'\x28' # subshell
|
||||||
|
'()' # anonymous function
|
||||||
'while'
|
'while'
|
||||||
'until'
|
'until'
|
||||||
'if'
|
'if'
|
||||||
@ -247,6 +250,9 @@ _zsh_highlight_main_highlighter()
|
|||||||
style=$ZSH_HIGHLIGHT_STYLES[reserved-word]
|
style=$ZSH_HIGHLIGHT_STYLES[reserved-word]
|
||||||
_zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style
|
_zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style
|
||||||
already_added=1
|
already_added=1
|
||||||
|
elif [[ $arg == '()' ]]; then
|
||||||
|
# anonymous function
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[reserved-word]
|
||||||
else
|
else
|
||||||
if _zsh_highlight_main_highlighter_check_path; then
|
if _zsh_highlight_main_highlighter_check_path; then
|
||||||
style=$ZSH_HIGHLIGHT_STYLES[path]
|
style=$ZSH_HIGHLIGHT_STYLES[path]
|
||||||
|
@ -30,11 +30,11 @@
|
|||||||
BUFFER='() echo hello; () { echo world }'
|
BUFFER='() echo hello; () { echo world }'
|
||||||
|
|
||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
"1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # ()
|
"1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ()
|
||||||
"4 7 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo
|
"4 7 $ZSH_HIGHLIGHT_STYLES[command]" # echo
|
||||||
"9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello
|
"9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello
|
||||||
"14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ;
|
"14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ;
|
||||||
"16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # ()
|
"16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ()
|
||||||
"19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # {
|
"19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # {
|
||||||
"21 24 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo
|
"21 24 $ZSH_HIGHLIGHT_STYLES[command]" # echo
|
||||||
)
|
)
|
||||||
|
@ -31,6 +31,6 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)'
|
|||||||
|
|
||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
"1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar
|
"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
|
"27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user