Skip to content

Commit

Permalink
Highlight subshells and anonymous functions correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielshahaf committed Oct 29, 2015
1 parent c216242 commit 0d1bfbc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ _zsh_highlight_main_highlighter()
# Tokens that, at (naively-determined) "command position", are followed by
# a de jure command position. All of these are reserved words.
ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=(
$'\x7b' # block
$'\x28' # subshell
'()' # anonymous function
'while'
'until'
'if'
Expand Down Expand Up @@ -247,6 +250,9 @@ _zsh_highlight_main_highlighter()
style=$ZSH_HIGHLIGHT_STYLES[reserved-word]
_zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style
already_added=1
elif [[ $arg == '()' ]]; then
# anonymous function
style=$ZSH_HIGHLIGHT_STYLES[reserved-word]
else
if _zsh_highlight_main_highlighter_check_path; then
style=$ZSH_HIGHLIGHT_STYLES[path]
Expand Down
10 changes: 5 additions & 5 deletions highlighters/main/test-data/anonymous-function.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
BUFFER='() echo hello; () { echo world }'

expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # ()
"4 7 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo
"1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ()
"4 7 $ZSH_HIGHLIGHT_STYLES[command]" # echo
"9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello
"14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ;
"16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # ()
"19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # {
"21 24 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo
"16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ()
"19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # {
"21 24 $ZSH_HIGHLIGHT_STYLES[command]" # echo
)
2 changes: 1 addition & 1 deletion highlighters/main/test-data/subshell.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)'

expected_region_highlight=(
"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
)

0 comments on commit 0d1bfbc

Please sign in to comment.