From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29094 invoked by alias); 29 Nov 2009 11:36:04 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27439 Received: (qmail 7550 invoked from network); 29 Nov 2009 11:35:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.219.222 as permitted sender) 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= MIME-Version: 1.0 Date: Sun, 29 Nov 2009 12:35:47 +0100 Message-ID: <237967ef0911290335o46d37f85rf64c617f67ddcf5e@mail.gmail.com> Subject: crazy brace match highlighting From: Mikael Magnusson To: zsh workers Content-Type: text/plain; charset=UTF-8 2009/11/29 Mikael Magnusson : > 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