From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22840 invoked from network); 7 Apr 2008 09:38:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 7 Apr 2008 09:38:37 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 93319 invoked from network); 7 Apr 2008 09:38:23 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 7 Apr 2008 09:38:23 -0000 Received: (qmail 8444 invoked by alias); 7 Apr 2008 09:38:19 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24797 Received: (qmail 8429 invoked from network); 7 Apr 2008 09:38:18 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 7 Apr 2008 09:38:18 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [85.115.41.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id 0F79480561C1 for ; Mon, 7 Apr 2008 11:38:14 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly06g.srv.mailcontrol.com (MailControl) with ESMTP id m379aQne028987 for ; Mon, 7 Apr 2008 10:38:06 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Mon, 7 Apr 2008 10:36:28 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.14.2/8.13.4) with ESMTP id m379aSMJ027694 for ; Mon, 7 Apr 2008 10:36:28 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.14.2/8.14.2/Submit) with ESMTP id m379aS9e027691 for ; Mon, 7 Apr 2008 10:36:28 +0100 Message-Id: <200804070936.m379aS9e027691@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: PATCH: command line highlighting In-reply-to: <080406133141.ZM31581@torch.brasslantern.com> References: <8360.1207165155@pws-pc> <080406133141.ZM31581@torch.brasslantern.com> Comments: In-reply-to Bart Schaefer message dated "Sun, 06 Apr 2008 13:31:41 -0700." Date: Mon, 07 Apr 2008 10:36:28 +0100 From: Peter Stephenson X-OriginalArrivalTime: 07 Apr 2008 09:36:28.0185 (UTC) FILETIME=[DAB2B090:01C89892] X-Scanned-By: MailControl A-08-00-05 (www.mailcontrol.com) on 10.71.0.116 X-Virus-Scanned: ClamAV 0.91.2/6647/Mon Apr 7 10:41:45 2008 on bifrost X-Virus-Status: Clean Bart Schaefer wrote: > On Apr 2, 8:39pm, Peter Stephenson wrote: > } > } Now 4.3.6 is out of the way, here's something I've been working on. It > } highlights the normal command line (not a completion list) > > Now all we need to make all the would-be highlighters happy is > highlighting in PREDISPLAY and POSTDISPLAY, I think. This should work already. A "P" in the region_highlight indicates the index includes PRESDISPLAY, and counting is supposed to continue over POSTDISPLAY. See, for example, the highlighting added to read-from-minibuffer. I should make it more explicit that POSTDISPLAY is included, however. Completely separate matter that's just occurred to me... actually,I think I've inadvertently made read-from-minibuffer behave slightly differently. The documentation says it "will work correctly as a widget in its own right". However, I've rewritten so that saving and restoring of special parameters is done by making them local. This doesn't actually work when it's called directly as a widget: the parameters are already local at the level in question and won't be restored when they go out of scope, because of the way special zle widgets work. It would probably be safer to put it back. It's actually not very useful as a widget in its own right so it's hardly worth worrying about, but I might as well get out of the corner I've documented myself into. pws Index: Doc/Zsh/zle.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v retrieving revision 1.60 diff -u -r1.60 zle.yo --- Doc/Zsh/zle.yo 4 Apr 2008 09:29:32 -0000 1.60 +++ Doc/Zsh/zle.yo 7 Apr 2008 09:34:53 -0000 @@ -778,8 +778,12 @@ item(tt(region_highlight) (array))( Each element of this array may be set to a string that describes highlighting for an arbitrary region of the command line that will -take effect the next time the command line is redisplayed. Each -string consists of the following parts: +take effect the next time the command line is redisplayed. Highlighting +of the non-editable parts of the command line in tt(PREDISPLAY) +and tt(POSTDISPLAY) are possible, but note that the tt(P) flag +is needed for character indexing to include tt(PREDISPLAY). + +Each string consists of the following parts: startlist() list(Optionally, a `tt(P)' to signify that the start and end offset that Index: Functions/Zle/read-from-minibuffer =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Zle/read-from-minibuffer,v retrieving revision 1.6 diff -u -r1.6 read-from-minibuffer --- Functions/Zle/read-from-minibuffer 3 Apr 2008 11:39:11 -0000 1.6 +++ Functions/Zle/read-from-minibuffer 7 Apr 2008 09:34:54 -0000 @@ -21,21 +21,41 @@ local pretext="$PREDISPLAY$LBUFFER$RBUFFER$POSTDISPLAY " -local LBUFFER="$2" -local RBUFFER="$3" -local PREDISPLAY="$pretext${1:-? }" -local POSTDISPLAY= -local -a region_highlight -region_highlight=("P${#pretext} ${#PREDISPLAY} bold") +# We could use the local variables mechanism to save these +# values, but if read-from-minibuffer is called as a widget +# (which isn't actually all that useful) the values won't be +# restored because the variables are already local at the current +# level and don't get restored when they go out of scope. +# We could do it with an additional function level. + local save_lbuffer=$LBUFFER + local save_rbuffer=$RBUFFER + local save_predisplay=$PREDISPLAY + local save_postdisplay=$POSTDISPLAY + local -a save_region_highlight + save_region_highlight=("${region_highlight[@]}") -if [[ -n $keys ]]; then - zle -R - read -k $keys - stat=$? -else - zle recursive-edit -K main - stat=$? - (( stat )) || REPLY=$BUFFER -fi +{ + LBUFFER="$2" + RBUFFER="$3" + PREDISPLAY="$pretext${1:-? }" + POSTDISPLAY= + region_highlight=("P${#pretext} ${#PREDISPLAY} bold") + + if [[ -n $keys ]]; then + zle -R + read -k $keys + stat=$? + else + zle recursive-edit -K main + stat=$? + (( stat )) || REPLY=$BUFFER + fi +} always { + LBUFFER=$save_lbuffer + RBUFFER=$save_rbuffer + PREDISPLAY=$save_predisplay + POSTDISPLAY=$save_postdisplay + region_highlight=("${save_region_highlight[@]}") +} return $stat -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070