main: Add *-quoted-argument-unclosed styles

Closes #277.
This commit is contained in:
Matthew Martin 2017-11-15 22:38:19 -06:00
parent ff61a496b5
commit bdbe214453
5 changed files with 30 additions and 8 deletions

View file

@ -36,8 +36,11 @@ This highlighter defines the following styles:
* `double-hyphen-option` - double hyphen options (`--option`)
* `back-quoted-argument` - backquoted expressions (`` `foo` ``)
* `single-quoted-argument` - single quoted arguments (`` 'foo' ``)
* `single-quoted-argument-unclosed` - unclosed single quoted arguments (`` 'foo ``)
* `double-quoted-argument` - double quoted arguments (`` "foo" ``)
* `double-quoted-argument-unclosed` - unclosed double quoted arguments (`` "foo ``)
* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``)
* `dollar-quoted-argument-unclosed` - unclosed dollar quoted arguments (`` $'foo ``)
* `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
* `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`)

View file

@ -85,6 +85,10 @@ _zsh_highlight_main_add_region_highlight() {
# in _zsh_highlight_main_highlighter_highlight_path_separators().
path_pathseparator path
path_prefix_pathseparator path_prefix
single-quoted-argument{-unclosed,}
double-quoted-argument{-unclosed,}
dollar-single-quoted-argument{-unclosed,}
)
local needle=$1 value
while [[ -n ${value::=$fallback_of[$needle]} ]]; do
@ -840,7 +844,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
# Highlight single-quoted strings
_zsh_highlight_main_highlighter_highlight_single_quote()
{
local arg1=$1 i q=\'
local arg1=$1 i q=\' style
local -a highlights
i=$arg[(ib:arg1+1:)$q]
@ -852,7 +856,12 @@ _zsh_highlight_main_highlighter_highlight_single_quote()
done
fi
highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights)
if [[ $arg[i] == "'" ]]; then
style=single-quoted-argument
else
style=single-quoted-argument-unclosed
fi
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights)
_zsh_highlight_main_add_many_region_highlights $highlights
REPLY=$i
}
@ -912,7 +921,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
highlights+=($j $k $style)
done
highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) double-quoted-argument $highlights)
if [[ $arg[i] == '"' ]]; then
style=double-quoted-argument
else
style=double-quoted-argument-unclosed
fi
highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $highlights)
_zsh_highlight_main_add_many_region_highlights $highlights
REPLY=$i
}
@ -959,7 +973,12 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
highlights+=($j $k $style)
done
highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) dollar-quoted-argument $highlights)
if [[ $arg[i] == "'" ]]; then
style=dollar-quoted-argument
else
style=dollar-quoted-argument-unclosed
fi
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights)
_zsh_highlight_main_add_many_region_highlights $highlights
REPLY=$i
}

View file

@ -32,6 +32,6 @@
BUFFER=": \$'\xa1"
expected_region_highlight=(
"3 4 dollar-quoted-argument" # $'
"3 4 dollar-quoted-argument-unclosed" # $'
"5 8 back-dollar-quoted-argument" # \xa1
)

View file

@ -32,6 +32,6 @@
BUFFER=': "foo$bar'
expected_region_highlight=(
"3 6 double-quoted-argument" # "foo
"3 6 double-quoted-argument-unclosed" # "foo
"7 10 dollar-double-quoted-argument" # $bar
)

View file

@ -27,8 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=$'echo "foo1\n'
BUFFER=$'echo \'foo1\n'
expected_region_highlight=(
"6 10 double-quoted-argument" # 'foo2"'
"6 10 single-quoted-argument-unclosed" # 'foo1
)