Autoload highlighters

This commit is contained in:
Matthew Martin 2020-08-09 19:33:44 -05:00
commit b62aeb6168
22 changed files with 2287 additions and 1907 deletions

View file

@ -30,33 +30,3 @@
# List of keyword and color pairs.
typeset -gA ZSH_HIGHLIGHT_REGEXP
# Whether the pattern highlighter should be called or not.
_zsh_highlight_highlighter_regexp_predicate()
{
_zsh_highlight_buffer_modified
}
# Pattern syntax highlighting function.
_zsh_highlight_highlighter_regexp_paint()
{
setopt localoptions extendedglob
local pattern
for pattern in ${(k)ZSH_HIGHLIGHT_REGEXP}; do
_zsh_highlight_regexp_highlighter_loop "$BUFFER" "$pattern"
done
}
_zsh_highlight_regexp_highlighter_loop()
{
local buf="$1" pat="$2"
integer OFFSET=0
local MATCH; integer MBEGIN MEND
local -a match mbegin mend
while true; do
[[ "$buf" =~ "$pat" ]] || return;
region_highlight+=("$((MBEGIN - 1 + OFFSET)) $((MEND + OFFSET)) $ZSH_HIGHLIGHT_REGEXP[$pat], memo=zsh-syntax-highlighting")
buf="$buf[$(($MEND+1)),-1]"
OFFSET=$((MEND+OFFSET));
done
}