* optimize discrimination of bracket-type
* use a nicer variable name
This commit is contained in:
parent
f1eb5aeef7
commit
e7ab165310
@ -54,28 +54,23 @@ _zsh_highlight_brackets_highlighter()
|
||||
["([{"])
|
||||
levelpos[$pos]=$((++level))
|
||||
lastoflevel[$level]=$pos
|
||||
typepos[$pos]=$BUFFER[$pos]
|
||||
typepos[$pos]=`_zsh_highlight_brackets_highlighter_brackettype $BUFFER[$pos]`
|
||||
;;
|
||||
[")]}"])
|
||||
matching[$lastoflevel[$level]]=$pos
|
||||
matching[$pos]=$lastoflevel[$level]
|
||||
levelpos[$pos]=$((level--))
|
||||
typepos[$pos]=$BUFFER[$pos]
|
||||
typepos[$pos]=`_zsh_highlight_brackets_highlighter_brackettype $BUFFER[$pos]`
|
||||
;;
|
||||
['"'\'])
|
||||
local temp=$BUFFER[$pos]
|
||||
local quotetype=$BUFFER[$pos]
|
||||
while (( $pos < ${#BUFFER} )) ; do
|
||||
((++pos))
|
||||
[[ $BUFFER[$pos] == $temp ]] && break
|
||||
[[ $BUFFER[$pos] == $quotetype ]] && break
|
||||
done
|
||||
;;
|
||||
esac
|
||||
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
|
||||
if [[ -z $matching[$pos] ]] || [[ $typepos[$pos] != $typepos[$matching[$pos]] ]]; then
|
||||
region_highlight+=("$((pos - 1)) $pos "$ZSH_HIGHLIGHT_STYLES[bracket-error])
|
||||
@ -91,3 +86,13 @@ _zsh_highlight_brackets_highlighter()
|
||||
region_highlight+=("$((otherpos - 1)) $otherpos standout")
|
||||
fi
|
||||
}
|
||||
|
||||
_zsh_highlight_brackets_highlighter_brackettype()
|
||||
{
|
||||
case $1 in
|
||||
["()"]) print round;;
|
||||
["[]"]) print bracket;;
|
||||
["{}"]) print curly;;
|
||||
*) ;;
|
||||
esac
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user