abra zsh config 2.0
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
|
||||
# Copyright (c) 2010-2017 zsh-syntax-highlighting contributors
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
@@ -38,73 +38,69 @@
|
||||
: ${ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]:=standout}
|
||||
|
||||
# Whether the brackets highlighter should be called or not.
|
||||
_zsh_highlight_brackets_highlighter_predicate()
|
||||
_zsh_highlight_highlighter_brackets_predicate()
|
||||
{
|
||||
_zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified
|
||||
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified
|
||||
}
|
||||
|
||||
# Brackets highlighting function.
|
||||
_zsh_highlight_brackets_highlighter()
|
||||
_zsh_highlight_highlighter_brackets_paint()
|
||||
{
|
||||
local level=0 pos
|
||||
local -A levelpos lastoflevel matching typepos
|
||||
region_highlight=()
|
||||
local char style
|
||||
local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 matchingpos pos
|
||||
local -A levelpos lastoflevel matching
|
||||
|
||||
# Find all brackets and remember which one is matching
|
||||
for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do
|
||||
local char="$BUFFER[pos+1]"
|
||||
for (( pos = 1; pos <= buflen; pos++ )) ; do
|
||||
char=$BUFFER[pos]
|
||||
case $char in
|
||||
["([{"])
|
||||
levelpos[$pos]=$((++level))
|
||||
lastoflevel[$level]=$pos
|
||||
_zsh_highlight_brackets_highlighter_brackettype "$char"
|
||||
;;
|
||||
[")]}"])
|
||||
matching[$lastoflevel[$level]]=$pos
|
||||
matching[$pos]=$lastoflevel[$level]
|
||||
levelpos[$pos]=$((level--))
|
||||
_zsh_highlight_brackets_highlighter_brackettype "$char"
|
||||
;;
|
||||
['"'\'])
|
||||
# Skip everything inside quotes
|
||||
local quotetype=$char
|
||||
while (( $pos < ${#BUFFER} )) ; do
|
||||
(( pos++ ))
|
||||
[[ $BUFFER[$pos+1] == $quotetype ]] && break
|
||||
done
|
||||
if (( level > 0 )); then
|
||||
matchingpos=$lastoflevel[$level]
|
||||
levelpos[$pos]=$((level--))
|
||||
if _zsh_highlight_brackets_match $matchingpos $pos; then
|
||||
matching[$matchingpos]=$pos
|
||||
matching[$pos]=$matchingpos
|
||||
fi
|
||||
else
|
||||
levelpos[$pos]=-1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Now highlight all found brackets
|
||||
for pos in ${(k)levelpos}; do
|
||||
if [[ -n $matching[$pos] ]] && [[ $typepos[$pos] == $typepos[$matching[$pos]] ]]; then
|
||||
local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]}
|
||||
local bracket_color_level=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
|
||||
local style=$ZSH_HIGHLIGHT_STYLES[$bracket_color_level]
|
||||
region_highlight+=("$pos $((pos + 1)) $style")
|
||||
if (( $+matching[$pos] )); then
|
||||
if (( bracket_color_size )); then
|
||||
_zsh_highlight_add_highlight $((pos - 1)) $pos bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
|
||||
fi
|
||||
else
|
||||
local style=$ZSH_HIGHLIGHT_STYLES[bracket-error]
|
||||
region_highlight+=("$pos $((pos + 1)) $style")
|
||||
_zsh_highlight_add_highlight $((pos - 1)) $pos bracket-error
|
||||
fi
|
||||
done
|
||||
|
||||
# If cursor is on a bracket, then highlight corresponding bracket, if any
|
||||
pos=$CURSOR
|
||||
if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then
|
||||
local otherpos=$matching[$pos]
|
||||
local style=$ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]
|
||||
region_highlight+=("$otherpos $((otherpos + 1)) $style")
|
||||
# If cursor is on a bracket, then highlight corresponding bracket, if any.
|
||||
if [[ $WIDGET != zle-line-finish ]]; then
|
||||
pos=$((CURSOR + 1))
|
||||
if (( $+levelpos[$pos] )) && (( $+matching[$pos] )); then
|
||||
local -i otherpos=$matching[$pos]
|
||||
_zsh_highlight_add_highlight $((otherpos - 1)) $otherpos cursor-matchingbracket
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Helper function to differentiate type
|
||||
_zsh_highlight_brackets_highlighter_brackettype()
|
||||
_zsh_highlight_brackets_match()
|
||||
{
|
||||
case $1 in
|
||||
["()"]) typepos[$pos]=round;;
|
||||
["[]"]) typepos[$pos]=bracket;;
|
||||
["{}"]) typepos[$pos]=curly;;
|
||||
*) ;;
|
||||
case $BUFFER[$1] in
|
||||
\() [[ $BUFFER[$2] == \) ]];;
|
||||
\[) [[ $BUFFER[$2] == \] ]];;
|
||||
\{) [[ $BUFFER[$2] == \} ]];;
|
||||
*) false;;
|
||||
esac
|
||||
}
|
||||
|
Reference in New Issue
Block a user