Skip to content

Commit d9e326b

Browse files
committed
main: consume trailing whitespace in _highlight_list
Fixes highlighting when an unclosed $( ends in whitespace.
1 parent 48a20d0 commit d9e326b

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

highlighters/main/main-highlighter.zsh

+2-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ _zsh_highlight_main_highlighter_highlight_list()
881881
fi
882882
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
883883
done
884-
REPLY=$(( end_pos - 1 ))
884+
[[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]]
885+
REPLY=$(( end_pos + ${#match[1]} - 1 ))
885886
reply=($list_highlights)
886887
return $(( $#braces_stack > 0 ))
887888
}

highlighters/main/test-data/command-substitution-unclosed.zsh

+1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ expected_region_highlight=(
4141

4242
if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug
4343
expected_region_highlight[2]='3 16 default' # foo$(echo bar
44+
expected_region_highlight[3]='6 16 command-substitution-unquoted' # $(echo bar
4445
fi

highlighters/main/test-data/process-substitution2.zsh

+1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ expected_region_highlight=(
4747

4848
if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug
4949
expected_region_highlight[8]='17 27 default' # =(echo foo
50+
expected_region_highlight[9]='17 27 process-substitution' # =(echo foo
5051
fi

highlighters/main/test-data/quoted-command-substitution-empty.zsh

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@
2828
# vim: ft=zsh sw=2 ts=2 et
2929
# -------------------------------------------------------------------------------------------------
3030

31-
BUFFER='echo "foo$('
31+
BUFFER='echo "foo$( '
3232

3333
expected_region_highlight=(
3434
'1 4 builtin' # echo
35-
'6 11 default' # "foo$(
35+
'6 12 default' # "foo$(
3636
'6 9 double-quoted-argument-unclosed' # "foo
37-
'10 11 command-substitution-quoted' # $(
37+
'10 12 command-substitution-quoted' # $(
3838
'10 11 command-substitution-delimiter-quoted' # $(
3939
)
4040

4141
if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug
42-
expected_region_highlight[2]='6 12 default' # "foo$(
42+
expected_region_highlight[2]='6 13 default' # "foo$(
43+
expected_region_highlight[4]='10 13 command-substitution-quoted' # $(
4344
fi

0 commit comments

Comments
 (0)