Skip to content

Commit 0f11d80

Browse files
committed
'main': Highlight the parentheses of array assignments as reserved words.
Fixes #585.
1 parent 00c0c76 commit 0f11d80

13 files changed

+28
-1
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
- Highlight arithmetic expansions (e.g., `$(( 42 ))`)
8686
[#607 #649 #704]
8787

88+
- Highlight the parentheses of array assignments as reserved words (`foo=( bar )`).
89+
The `assign` style remains supported and has precedence.
90+
[#585]
91+
8892
# Changes in version 0.7.1
8993

9094
- Remove out-of-date information from the 0.7.0 changelog.

highlighters/main/main-highlighter.zsh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ _zsh_highlight_main_highlighter_highlight_list()
10071007
saw_assignment=true
10081008
if [[ $arg[i] == '(' ]]; then
10091009
in_array_assignment=true
1010+
_zsh_highlight_main_add_region_highlight start_pos+i-1 start_pos+i reserved-word
10101011
else
10111012
# assignment to a scalar parameter.
10121013
# (For array assignments, the command doesn't start until the ")" token.)
@@ -1088,9 +1089,11 @@ _zsh_highlight_main_highlighter_highlight_list()
10881089
($'\x29')
10891090
# subshell or end of array assignment
10901091
if $in_array_assignment; then
1091-
style=assign
1092+
_zsh_highlight_main_add_region_highlight $start_pos $end_pos assign
1093+
_zsh_highlight_main_add_region_highlight $start_pos $end_pos reserved-word
10921094
in_array_assignment=false
10931095
next_word+=':start:'
1096+
continue
10941097
elif (( in_redirection )); then
10951098
style=unknown-token
10961099
else

highlighters/main/test-data/array-cmdsep1.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bar(){}
3333

3434
expected_region_highlight=(
3535
'1 3 assign' # a=(
36+
'3 3 reserved-word' # (
3637
'5 7 default' # foo
3738
'9 9 unknown-token' # |
3839
# zsh reports a parse error at this point. Nevertheless, we test how we

highlighters/main/test-data/array-cmdsep2.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ BUFFER=$'a=( foo ; bar )'
3232

3333
expected_region_highlight=(
3434
'1 3 assign' # a=(
35+
'3 3 reserved-word' # (
3536
'5 7 default' # foo
3637
'9 9 unknown-token' # ; (not commandseparator; see highlighter source code)
3738
'11 13 default' # bar
3839
'15 15 assign' # )
40+
'15 15 reserved-word' # )
3941
)

highlighters/main/test-data/array-cmdsep3.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ BUFFER=$'a=( foo \n bar )'
3232

3333
expected_region_highlight=(
3434
'1 3 assign' # a=(
35+
'3 3 reserved-word' # (
3536
'5 7 default' # foo
3637
'9 9 commandseparator' # \n
3738
'11 13 default' # bar
3839
'15 15 assign' # )
40+
'15 15 reserved-word' # )
3941
)

highlighters/main/test-data/assign-append.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ BUFFER='a+=(lorem ipsum)'
3131

3232
expected_region_highlight=(
3333
"1 4 assign" # a+=(
34+
"4 4 reserved-word" # (
3435
"5 9 default" # lorem
3536
"11 15 default" # ipsum
3637
"16 16 assign" # )
38+
"16 16 reserved-word" # )
3739
)

highlighters/main/test-data/assign-array.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ BUFFER='(A=(hello world))'
3232
expected_region_highlight=(
3333
"1 1 reserved-word" # (
3434
"2 4 assign" # A=(
35+
"4 4 reserved-word" # (
3536
"5 9 default" # hello
3637
"11 15 default" # world
3738
"16 16 assign" # )
39+
"16 16 reserved-word" # )
3840
"17 17 reserved-word" # )
3941
)

highlighters/main/test-data/assign-array2.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ BUFFER='A=(hello world) ls'
3131

3232
expected_region_highlight=(
3333
"1 3 assign" # A=(
34+
"3 3 reserved-word" # (
3435
"4 8 default" # hello
3536
"10 14 default" # world
3637
"15 15 assign" # )
38+
"15 15 reserved-word" # )
3739
"17 18 command" # ls
3840
)

highlighters/main/test-data/assign-array3.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ BUFFER='A=(hello world) b=42'
3131

3232
expected_region_highlight=(
3333
"1 3 assign" # A=(
34+
"3 3 reserved-word" # (
3435
"4 8 default" # hello
3536
"10 14 default" # world
3637
"15 15 assign" # )
38+
"15 15 reserved-word" # )
3739
"17 20 assign" # b=42
3840
"19 20 default" # 42
3941
)

highlighters/main/test-data/assign.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ expected_region_highlight=(
3333
"1 3 assign" # A=1
3434
"3 3 default" # 1
3535
"5 7 assign" # b=(
36+
"7 7 reserved-word" # (
3637
"8 12 default" # "foo"
3738
"8 12 double-quoted-argument" # "foo"
3839
"14 16 default" # bar
3940
"17 17 assign" # )
41+
"17 17 reserved-word" # )
4042
)

0 commit comments

Comments
 (0)