Merge pull request #63 from garinger/master
Fix for Issue #36 "Brackets of different types matched"
This commit is contained in:
commit
8ebce17a11
@ -46,39 +46,53 @@ _zsh_highlight_brackets_highlighter_predicate()
|
|||||||
# Brackets highlighting function.
|
# Brackets highlighting function.
|
||||||
_zsh_highlight_brackets_highlighter()
|
_zsh_highlight_brackets_highlighter()
|
||||||
{
|
{
|
||||||
local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]}
|
local level pos
|
||||||
if ((bracket_color_size > 0)); then
|
local -A levelpos lastoflevel matching typepos
|
||||||
local c level pos
|
((level = 0))
|
||||||
typeset -A levelpos lastoflevel matching revmatching
|
for ((pos = 1; $pos <= ${#BUFFER}; pos++ )) ; do
|
||||||
((level = 0))
|
case $BUFFER[pos] in
|
||||||
for pos in {1..${#BUFFER}}; do
|
["([{"])
|
||||||
case $BUFFER[pos] in
|
levelpos[$pos]=$((++level))
|
||||||
"("|"["|"{")
|
lastoflevel[$level]=$pos
|
||||||
levelpos[$pos]=$((++level))
|
typepos[$pos]=`_zsh_highlight_brackets_highlighter_brackettype $BUFFER[$pos]`
|
||||||
lastoflevel[$level]=$pos
|
;;
|
||||||
;;
|
[")]}"])
|
||||||
")"|"]"|"}")
|
matching[$lastoflevel[$level]]=$pos
|
||||||
matching[$lastoflevel[$level]]=$pos
|
matching[$pos]=$lastoflevel[$level]
|
||||||
revmatching[$pos]=$lastoflevel[$level]
|
levelpos[$pos]=$((level--))
|
||||||
levelpos[$pos]=$((level--))
|
typepos[$pos]=`_zsh_highlight_brackets_highlighter_brackettype $BUFFER[$pos]`
|
||||||
;;
|
;;
|
||||||
esac
|
['"'\'])
|
||||||
done
|
local quotetype=$BUFFER[$pos]
|
||||||
for pos in ${(k)levelpos}; do
|
while (( $pos < ${#BUFFER} )) ; do
|
||||||
if [[ -z $matching[$pos] ]] && [[ -z $revmatching[$pos] ]]; then
|
((++pos))
|
||||||
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[bracket-error])
|
[[ $BUFFER[$pos] == $quotetype ]] && break
|
||||||
else
|
done
|
||||||
local style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
|
;;
|
||||||
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[$style])
|
esac
|
||||||
fi
|
done
|
||||||
done
|
for pos in ${(k)levelpos}; do
|
||||||
((c = CURSOR + 1))
|
if [[ -z $matching[$pos] ]] || [[ $typepos[$pos] != $typepos[$matching[$pos]] ]]; then
|
||||||
if [[ -n $levelpos[$c] ]]; then
|
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[bracket-error])
|
||||||
local otherpos
|
else
|
||||||
((otherpos = -1))
|
local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]}
|
||||||
[[ -n $matching[$c] ]] && otherpos=$matching[$c]
|
local style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
|
||||||
[[ -n $revmatching[$c] ]] && otherpos=$revmatching[$c]
|
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[$style])
|
||||||
region_highlight+=("$((otherpos - 1)) $otherpos standout")
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
((pos = CURSOR + 1))
|
||||||
|
if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then
|
||||||
|
local otherpos=$matching[$pos]
|
||||||
|
region_highlight+=("$((otherpos - 1)) $otherpos standout")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_zsh_highlight_brackets_highlighter_brackettype()
|
||||||
|
{
|
||||||
|
case $1 in
|
||||||
|
["()"]) print round;;
|
||||||
|
["[]"]) print bracket;;
|
||||||
|
["{}"]) print curly;;
|
||||||
|
*) ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user