Only match brackets of the same type
This commit is contained in:
parent
48c30a805a
commit
ef74d2b611
@ -49,24 +49,33 @@ _zsh_highlight_brackets_highlighter()
|
|||||||
local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]}
|
local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]}
|
||||||
if ((bracket_color_size > 0)); then
|
if ((bracket_color_size > 0)); then
|
||||||
local c level pos
|
local c level pos
|
||||||
typeset -A levelpos lastoflevel matching revmatching
|
typeset -A levelpos lastoflevel matching typepos revmatching
|
||||||
((level = 0))
|
((level = 0))
|
||||||
for pos in {1..${#BUFFER}}; do
|
for pos in {1..${#BUFFER}}; do
|
||||||
case $BUFFER[pos] in
|
case $BUFFER[pos] in
|
||||||
"("|"["|"{")
|
"("|"["|"{")
|
||||||
levelpos[$pos]=$((++level))
|
levelpos[$pos]=$((++level))
|
||||||
lastoflevel[$level]=$pos
|
lastoflevel[$level]=$pos
|
||||||
|
typepos[$pos]=$BUFFER[$pos]
|
||||||
;;
|
;;
|
||||||
")"|"]"|"}")
|
")"|"]"|"}")
|
||||||
matching[$lastoflevel[$level]]=$pos
|
matching[$lastoflevel[$level]]=$pos
|
||||||
revmatching[$pos]=$lastoflevel[$level]
|
revmatching[$pos]=$lastoflevel[$level]
|
||||||
levelpos[$pos]=$((level--))
|
levelpos[$pos]=$((level--))
|
||||||
|
typepos[$pos]=$BUFFER[$pos]
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
for pos in ${(k)typepos}; do
|
||||||
|
typepos[$pos]=${typepos[${pos}]/["()"]/round}
|
||||||
|
typepos[$pos]=${typepos[${pos}]/["[]"]/square}
|
||||||
|
typepos[$pos]=${typepos[${pos}]/["{}"]/curly}
|
||||||
|
done
|
||||||
for pos in ${(k)levelpos}; do
|
for pos in ${(k)levelpos}; do
|
||||||
if [[ -z $matching[$pos] ]] && [[ -z $revmatching[$pos] ]]; then
|
if [[ -z $matching[$pos] ]] && [[ -z $revmatching[$pos] ]]; then
|
||||||
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[bracket-error])
|
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[bracket-error])
|
||||||
|
elif [[ $typepos[$pos] != $typepos[$matching[$pos]] ]] && [[ $typepos[$pos] != $typepos[$revmatching[$pos]] ]]; then
|
||||||
|
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[bracket-error])
|
||||||
else
|
else
|
||||||
local style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
|
local style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
|
||||||
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[$style])
|
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[$style])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user