Highlight arithmetic expansions.

Fixes zsh-users/zsh-syntax-highlighting#188 in the case that both the
opening '((' and closing '))' have been typed,  The case that only the
opening '((' have been typed is also fixed, but requires a zsh development
build (zsh-5.1.1-52-g4bed2cf or newer); see comments within.
This commit is contained in:
Daniel Shahaf
2015-09-24 18:24:07 +00:00
parent 6488284814
commit 7b4598a764
2 changed files with 53 additions and 0 deletions

View File

@@ -183,6 +183,19 @@ _zsh_highlight_main_highlighter()
elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then
style=$ZSH_HIGHLIGHT_STYLES[redirection]
redirection=true
elif [[ $arg[1,2] == '((' ]]; then
# Arithmetic evaluation.
#
# Note: prior to zsh-5.1.1-52-g4bed2cf (workers/36669), the ${(z)...}
# splitter would only output the '((' token if the matching '))' had
# been typed. Therefore, under those versions of zsh, BUFFER="(( 42"
# would be highlighted as an error until the matching "))" are typed.
#
# We highlight just the opening parentheses, as a reserved word; this
# is how [[ ... ]] is highlighted, too.
style=$ZSH_HIGHLIGHT_STYLES[reserved-word]
_zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style
substr_color=1
else
if _zsh_highlight_main_highlighter_check_path; then
style=$ZSH_HIGHLIGHT_STYLES[path]