* remove a safety belt - no need to check if array has elements, as defaults are provided
* reuse $pos instead of using another variable * remove declaration forgotten in last commit
This commit is contained in:
parent
d4acac9837
commit
05e4a031c7
@ -46,45 +46,43 @@ _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 typepos revmatching
|
for pos in {1..${#BUFFER}}; 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]=$BUFFER[$pos]
|
||||||
lastoflevel[$level]=$pos
|
;;
|
||||||
typepos[$pos]=$BUFFER[$pos]
|
")"|"]"|"}")
|
||||||
;;
|
matching[$lastoflevel[$level]]=$pos
|
||||||
")"|"]"|"}")
|
matching[$pos]=$lastoflevel[$level]
|
||||||
matching[$lastoflevel[$level]]=$pos
|
levelpos[$pos]=$((level--))
|
||||||
matching[$pos]=$lastoflevel[$level]
|
typepos[$pos]=$BUFFER[$pos]
|
||||||
levelpos[$pos]=$((level--))
|
;;
|
||||||
typepos[$pos]=$BUFFER[$pos]
|
esac
|
||||||
;;
|
done
|
||||||
esac
|
for pos in ${(k)typepos}; do
|
||||||
done
|
typepos[$pos]=${typepos[${pos}]/["()"]/round}
|
||||||
for pos in ${(k)typepos}; do
|
typepos[$pos]=${typepos[${pos}]/["[]"]/square}
|
||||||
typepos[$pos]=${typepos[${pos}]/["()"]/round}
|
typepos[$pos]=${typepos[${pos}]/["{}"]/curly}
|
||||||
typepos[$pos]=${typepos[${pos}]/["[]"]/square}
|
done
|
||||||
typepos[$pos]=${typepos[${pos}]/["{}"]/curly}
|
for pos in ${(k)levelpos}; do
|
||||||
done
|
if [[ -z $matching[$pos] ]] || [[ $typepos[$pos] != $typepos[$matching[$pos]] ]]; then
|
||||||
for pos in ${(k)levelpos}; do
|
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[bracket-error])
|
||||||
if [[ -z $matching[$pos] ]] || [[ $typepos[$pos] != $typepos[$matching[$pos]] ]]; then
|
else
|
||||||
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[bracket-error])
|
local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]}
|
||||||
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])
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
((c = CURSOR + 1))
|
|
||||||
if [[ -n $levelpos[$c] ]]; then
|
|
||||||
local otherpos
|
|
||||||
((otherpos = -1))
|
|
||||||
[[ -n $matching[$c] ]] && otherpos=$matching[$c]
|
|
||||||
region_highlight+=("$((otherpos - 1)) $otherpos standout")
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
((pos = CURSOR + 1))
|
||||||
|
if [[ -n $levelpos[$pos] ]]; then
|
||||||
|
local otherpos
|
||||||
|
((otherpos = -1))
|
||||||
|
[[ -n $matching[$pos] ]] && otherpos=$matching[$pos]
|
||||||
|
region_highlight+=("$((otherpos - 1)) $otherpos standout")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user