Skip to content

Commit 0d1bfbc

Browse files
committed
Highlight subshells and anonymous functions correctly.
Fixes #166. Fixes #194. Builds upon the issue #207 work.
1 parent c216242 commit 0d1bfbc

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

highlighters/main/main-highlighter.zsh

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ _zsh_highlight_main_highlighter()
101101
# Tokens that, at (naively-determined) "command position", are followed by
102102
# a de jure command position. All of these are reserved words.
103103
ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=(
104+
$'\x7b' # block
105+
$'\x28' # subshell
106+
'()' # anonymous function
104107
'while'
105108
'until'
106109
'if'
@@ -247,6 +250,9 @@ _zsh_highlight_main_highlighter()
247250
style=$ZSH_HIGHLIGHT_STYLES[reserved-word]
248251
_zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style
249252
already_added=1
253+
elif [[ $arg == '()' ]]; then
254+
# anonymous function
255+
style=$ZSH_HIGHLIGHT_STYLES[reserved-word]
250256
else
251257
if _zsh_highlight_main_highlighter_check_path; then
252258
style=$ZSH_HIGHLIGHT_STYLES[path]

highlighters/main/test-data/anonymous-function.zsh

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
BUFFER='() echo hello; () { echo world }'
3131

3232
expected_region_highlight=(
33-
"1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # ()
34-
"4 7 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo
33+
"1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ()
34+
"4 7 $ZSH_HIGHLIGHT_STYLES[command]" # echo
3535
"9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello
3636
"14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ;
37-
"16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # ()
38-
"19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # {
39-
"21 24 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo
37+
"16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ()
38+
"19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # {
39+
"21 24 $ZSH_HIGHLIGHT_STYLES[command]" # echo
4040
)

highlighters/main/test-data/subshell.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)'
3131

3232
expected_region_highlight=(
3333
"1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar
34-
"15 16 $ZSH_HIGHLIGHT_STYLES[command] 'issue #166'" # cd
34+
"15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd
3535
"27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar
3636
)

0 commit comments

Comments
 (0)