Update main-highlighter.zsh

Added highlighting of dollar variable in double quoted strings
This commit is contained in:
Shura 2013-07-26 15:39:20 +04:00
parent e5d8a50d36
commit 13acbbbe29

View File

@ -167,18 +167,24 @@ _zsh_highlight_main_highlighter_check_path()
_zsh_highlight_main_highlighter_highlight_string() _zsh_highlight_main_highlighter_highlight_string()
{ {
setopt localoptions noksharrays setopt localoptions noksharrays
local i j k style local i j k style varflag
# Starting quote is at 1, so start parsing at offset 2 in the string. # Starting quote is at 1, so start parsing at offset 2 in the string.
for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do
(( j = i + start_pos - 1 )) (( j = i + start_pos - 1 ))
(( k = j + 1 )) (( k = j + 1 ))
case "$arg[$i]" in case "$arg[$i]" in
'$') style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument];; '$') style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]
(( varflag = 1 )) #variable start
;;
"\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] "\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]
(( k += 1 )) # Color following char too. (( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char. (( i += 1 )) # Skip parsing the escaped char.
;; ;;
*) continue;; ([^a-zA-Z0-9_]))
(( varflag = 0 )) #variable end
continue
;;
*) [[ $varflag -eq 0 ]] && continue;;
esac esac
region_highlight+=("$j $k $style") region_highlight+=("$j $k $style")
done done