Fix some _hl_string issues:
- Avoid unset variable warning at $arg[0]. - Fix highlighting of "\$" and "\\". - Tweak the code style a bit.
This commit is contained in:
parent
030cabee59
commit
6a3bbe72da
@ -74,19 +74,21 @@ _zsh_check-path() {
|
|||||||
|
|
||||||
# Highlight special chars inside double-quoted strings
|
# Highlight special chars inside double-quoted strings
|
||||||
_zsh_highlight-string() {
|
_zsh_highlight-string() {
|
||||||
local i
|
setopt localoptions noksharrays
|
||||||
local j
|
local i j k style
|
||||||
local k
|
# Starting quote is at 1, so start parsing at offset 2 in the string.
|
||||||
local c
|
for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do
|
||||||
for (( i = 0 ; i < end_pos - start_pos ; i += 1 )) ; do
|
|
||||||
(( j = i + start_pos - 1 ))
|
(( j = i + start_pos - 1 ))
|
||||||
(( k = j + 1 ))
|
(( k = j + 1 ))
|
||||||
c="$arg[$i]"
|
case "$arg[$i]" in
|
||||||
[[ "$c" = '$' ]] && region_highlight+=("$j $k $ZSH_SYNTAX_HIGHLIGHTING_STYLES[dollar-double-quoted-argument]")
|
'$') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[dollar-double-quoted-argument];;
|
||||||
if [[ "$c" = "\\" ]] ; then
|
"\\") style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[back-double-quoted-argument]
|
||||||
(( k = k + 1 ))
|
(( k += 1 )) # Color following char too.
|
||||||
region_highlight+=("$j $k $ZSH_SYNTAX_HIGHLIGHTING_STYLES[back-double-quoted-argument]")
|
(( i += 1 )) # Skip parsing the escaped char.
|
||||||
fi
|
;;
|
||||||
|
*) continue;;
|
||||||
|
esac
|
||||||
|
region_highlight+=("$j $k $style")
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user