Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
crazy brace match highlighting
- X-seq: zsh-workers 27439
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: crazy brace match highlighting
- Date: Sun, 29 Nov 2009 12:35:47 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=IFak4GGKYxaQuWQoip86ofE23vwPRQewLjeQme2rq/c=; b=w5WNaaMXy/nZa/BxdAN8T48n6Zwlbub7qcRWg+irhBnj1ya/kYRRkdBE+4YfTTqOBq oeMDlgp0bdp2qQx4Ut6YE49iGW2Zjny2IFKlQMjG7gu2B9eHrvxb3upxfntd0Ug+Enr/ dWJUhzI2T6dxy4hTdt2JSV6HDh/dYyOtOd7bE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=ty/AiKZbyPsVRBCqxxHH9dwq4gf/QsicJvgR1FjB5vz1UruaKoKMHPbmqmKItBOxgH 2ROPEZ8L5iuyB67CFsBA91jMzTbJJ5TZXiTVctbvFc1InbXglmxNBz3/AVpjK75W4vOj dilzHONfs19XKxvlgkqhGF+uCI9VPg3+EFybA=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
2009/11/29 Mikael Magnusson <mikachu@xxxxxxxxx>:
> Oops, this was due to an experiment I was doing with brace
> highlighting, sorry for the noise. I added a shell hook in zrefresh
> which is probably quite crazy, which ended up overwriting the static
> variables used in the isearch pattern matching.
I changed it to use =~ instead and it seems to work ;). So this is
sort of a crazy experiment just to see if it would be useful.
Patch to c code:
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -1039,6 +1039,14 @@ zrefresh(void)
tmpalloced = 0;
}
+ if ((initthingy = rthingy_nocreate("zle-line-pre-redraw"))) {
+ char *args[2];
+ args[0] = initthingy->nam;
+ args[1] = NULL;
+ execzlefunc(initthingy, args, 1);
+ unrefthingy(initthingy);
+ }
+
/* this will create region_highlights if it's still NULL */
zle_set_highlight();
.zshrc stuff:
function _line_redraw_dummy() {
}
function _line_redraw_brace_detect() {
local char=$BUFFER[pos]
if [[ $char =~ '\(' ]]; then
dir=1
that=')'
elif [[ $char =~ '\)' ]]; then
dir=-1
that='('
elif [[ $char =~ '\]' ]]; then
dir=-1
that='['
elif [[ $char =~ '\[' ]]; then
dir=-1
that=']'
elif [[ $char =~ '\}' ]]; then
dir=-1
that='{'
elif [[ $char =~ '\{' ]]; then
dir=-1
that='}'
fi
}
function _line_redraw() {
unset region_highlight
#set this var to 2 in your accept-line hook to remove the hilight
#when accepting a line
[[ $__zle_line_accepted -gt 0 ]] && {
(( __zle_line_accepted-- ))
return
}
#this stuff is so slow
[[ $#BUFFER -gt 250 ]] && { zle -N zle-line-pre-redraw
_line_redraw_dummy; return }
#hilight matching parens,braces,brackets
local ct=1 pos=$((CURSOR+1)) cpos dir this that
_line_redraw_brace_detect
(( ! dir )) && {
(( pos-- ))
_line_redraw_brace_detect
}
(( ! dir )) && return
this=$BUFFER[pos]
cpos=$pos
while (( ((dir > 0) ? (pos < $#BUFFER) : pos > 0) && ct )) {
(( pos+=dir ))
[[ $BUFFER[pos] == $that ]] && (( ct-- ))
[[ $BUFFER[pos] == $this ]] && (( ct++ ))
}
(( ct )) ||
region_highlight=("$((cpos-1)) $cpos bold,bg=cyan,fg=black"
"$((pos-1)) $pos bold,bg=cyan,fg=black")
#this just colors each word, assumes terminal supports 88 colors, change the 88s
#to 16 if it doesn't. crazy slow.
# local index=1 pos oldpos=0 region_highlight_tmp
# while [[ ${pos::="$BUFFER[(in:index++:)[[:space:]]]"} -lt $#BUFFER ]]; do
# region_highlight_tmp+=("$oldpos $((pos-1)) bg=$((index%88))")
# oldpos=$pos
# done
# region_highlight_tmp+=("$oldpos $#BUFFER bg=$((index%88))")
# region_highlight=($region_highlight_tmp)
}
function _zle_line_init() {
zle -N zle-line-pre-redraw _line_redraw
}
zle -N zle-line-init _zle_line_init
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author