Skip to content

Commit bdbe214

Browse files
committed
main: Add *-quoted-argument-unclosed styles
Closes zsh-users#277.
1 parent ff61a49 commit bdbe214

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

docs/highlighters/main.md

+3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ This highlighter defines the following styles:
3636
* `double-hyphen-option` - double hyphen options (`--option`)
3737
* `back-quoted-argument` - backquoted expressions (`` `foo` ``)
3838
* `single-quoted-argument` - single quoted arguments (`` 'foo' ``)
39+
* `single-quoted-argument-unclosed` - unclosed single quoted arguments (`` 'foo ``)
3940
* `double-quoted-argument` - double quoted arguments (`` "foo" ``)
41+
* `double-quoted-argument-unclosed` - unclosed double quoted arguments (`` "foo ``)
4042
* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``)
43+
* `dollar-quoted-argument-unclosed` - unclosed dollar quoted arguments (`` $'foo ``)
4144
* `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
4245
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
4346
* `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`)

highlighters/main/main-highlighter.zsh

+23-4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ _zsh_highlight_main_add_region_highlight() {
8585
# in _zsh_highlight_main_highlighter_highlight_path_separators().
8686
path_pathseparator path
8787
path_prefix_pathseparator path_prefix
88+
89+
single-quoted-argument{-unclosed,}
90+
double-quoted-argument{-unclosed,}
91+
dollar-single-quoted-argument{-unclosed,}
8892
)
8993
local needle=$1 value
9094
while [[ -n ${value::=$fallback_of[$needle]} ]]; do
@@ -840,7 +844,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
840844
# Highlight single-quoted strings
841845
_zsh_highlight_main_highlighter_highlight_single_quote()
842846
{
843-
local arg1=$1 i q=\'
847+
local arg1=$1 i q=\' style
844848
local -a highlights
845849
i=$arg[(ib:arg1+1:)$q]
846850

@@ -852,7 +856,12 @@ _zsh_highlight_main_highlighter_highlight_single_quote()
852856
done
853857
fi
854858

855-
highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights)
859+
if [[ $arg[i] == "'" ]]; then
860+
style=single-quoted-argument
861+
else
862+
style=single-quoted-argument-unclosed
863+
fi
864+
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights)
856865
_zsh_highlight_main_add_many_region_highlights $highlights
857866
REPLY=$i
858867
}
@@ -912,7 +921,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
912921
highlights+=($j $k $style)
913922
done
914923

915-
highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) double-quoted-argument $highlights)
924+
if [[ $arg[i] == '"' ]]; then
925+
style=double-quoted-argument
926+
else
927+
style=double-quoted-argument-unclosed
928+
fi
929+
highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $highlights)
916930
_zsh_highlight_main_add_many_region_highlights $highlights
917931
REPLY=$i
918932
}
@@ -959,7 +973,12 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
959973
highlights+=($j $k $style)
960974
done
961975

962-
highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) dollar-quoted-argument $highlights)
976+
if [[ $arg[i] == "'" ]]; then
977+
style=dollar-quoted-argument
978+
else
979+
style=dollar-quoted-argument-unclosed
980+
fi
981+
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights)
963982
_zsh_highlight_main_add_many_region_highlights $highlights
964983
REPLY=$i
965984
}

highlighters/main/test-data/dollar-quoted3.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
BUFFER=": \$'\xa1"
3333

3434
expected_region_highlight=(
35-
"3 4 dollar-quoted-argument" # $'
35+
"3 4 dollar-quoted-argument-unclosed" # $'
3636
"5 8 back-dollar-quoted-argument" # \xa1
3737
)

highlighters/main/test-data/double-quoted2.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
BUFFER=': "foo$bar'
3333

3434
expected_region_highlight=(
35-
"3 6 double-quoted-argument" # "foo
35+
"3 6 double-quoted-argument-unclosed" # "foo
3636
"7 10 dollar-double-quoted-argument" # $bar
3737
)

highlighters/main/test-data/multiline-string2.zsh

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
# vim: ft=zsh sw=2 ts=2 et
2828
# -------------------------------------------------------------------------------------------------
2929

30-
BUFFER=$'echo "foo1\n'
30+
BUFFER=$'echo \'foo1\n'
3131

3232
expected_region_highlight=(
33-
"6 10 double-quoted-argument" # 'foo2"'
33+
"6 10 single-quoted-argument-unclosed" # 'foo1
3434
)

0 commit comments

Comments
 (0)