Skip to content

Commit ad8358c

Browse files
committed
'main': Highlight backslash escape sequences outside quotes.
Fixes zsh-users#631. WIP: test expectations should be updated (12 failures including cthulhu)
1 parent dfc4112 commit ad8358c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

docs/highlighters/main.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This highlighter defines the following styles:
5353
* `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``)
5454
* `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
5555
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
56+
* `back-un-quoted-argument` - backslash escape sequences outside quotes (`\"` in `print -r \"bar\"`)
5657
* `back-double-quoted-argument` - backslash escape sequences inside double-quoted arguments (`\"` in `"foo\"bar"`)
5758
* `back-dollar-quoted-argument` - backslash escape sequences inside dollar-quoted arguments (`\x` in `$'\x48'`)
5859
* `assign` - parameter assignments (`x=foo` and `x=( )`)

highlighters/main/main-highlighter.zsh

+9-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow}
5454
: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan}
5555
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
56-
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
56+
: ${ZSH_HIGHLIGHT_STYLES[back-un-quoted-argument]:=fg=cyan}
57+
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan,underline}
5758
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
5859
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
5960
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=fg=yellow}
@@ -1202,7 +1203,13 @@ _zsh_highlight_main_highlighter_highlight_argument()
12021203

12031204
for (( ; i <= $#arg ; i += 1 )); do
12041205
case "$arg[$i]" in
1205-
"\\") (( i += 1 )); continue;;
1206+
"\\")
1207+
highlights+=(
1208+
$(( start_pos + i - 1 )) $((start_pos + i + 1)) back-double-quoted-argument
1209+
)
1210+
(( i += 1 ))
1211+
continue
1212+
;;
12061213
"'")
12071214
_zsh_highlight_main_highlighter_highlight_single_quote $i
12081215
(( i = REPLY ))

highlighters/main/test-data/backslash-continuation2.zsh

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ expected_region_highlight=(
3434
'1 4 builtin' # echo
3535
'6 18 default "issue #705"' # foo\\\nbar"baz"
3636
'14 18 double-quoted-argument "issue #705"' # "baz"
37+
# TODO: when fixing this, see if we can highlight the backslash-newline sequence as a comment.
3738
)

0 commit comments

Comments
 (0)