From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14918 invoked by alias); 4 Nov 2011 14:20:03 -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: 29892 Received: (qmail 16140 invoked from network); 4 Nov 2011 14:19:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) X-Authentication-Warning: pwslap01u.europe.root.pri: pws owned process doing -bs To: Zsh hackers list Subject: PATCH: replace string etc. X-Mailer: MH-E 8.2; nmh 1.3; GNU Emacs 23.2.1 Date: Fri, 4 Nov 2011 14:19:48 +0000 Message-ID: <11453.1320416388@csr.com> From: Peter Stephenson MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.101.11.233] X-Scanned-By: MailControl 7.6.3 (www.mailcontrol.com) on 10.68.0.155 This fixes a couple of minor things. replace-string when doing regular expression matches didn't replace anything right of the cursor if it didn't find anything left of the cursor. It still doesn't handle cases straddling the cursor. There's a rather grotesque save and restore in read-from-minibuffer that could be better done using local variables in an anonymous function now we have them. I had a go at trying to make replace-string use a local history, but it was very hairy; changing the history in the middle of zle has interesting effects (not fatal ones, hence probably entirely logical if thought through). Until some brainwave occurs I've given up. Index: Functions/Zle/read-from-minibuffer =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Zle/read-from-minibuffer,v retrieving revision 1.7 diff -p -u -r1.7 read-from-minibuffer --- Functions/Zle/read-from-minibuffer 7 Apr 2008 09:44:34 -0000 1.7 +++ Functions/Zle/read-from-minibuffer 4 Nov 2011 14:14:31 -0000 @@ -19,26 +19,19 @@ while getopts "k:" opt; do done (( OPTIND > 1 )) && shift $(( OPTIND - 1 )) +local readprompt="$1" lbuf_init="$2" rbuf_init="$3" + +# Use anonymous function to make sure special values get restored, +# even if this function is called as a widget. +# local +h ensures special parameters stay special. +() { local pretext="$PREDISPLAY$LBUFFER$RBUFFER$POSTDISPLAY " -# 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[@]}") - -{ - LBUFFER="$2" - RBUFFER="$3" - PREDISPLAY="$pretext${1:-? }" - POSTDISPLAY= + local +h LBUFFER="$lbuf_init" + local +h RBUFFER="$rbuf_init" + local +h PREDISPLAY="$pretext${readprompt:-? }" + local +h POSTDISPLAY= + local +h -a region_highlight region_highlight=("P${#pretext} ${#PREDISPLAY} bold") if [[ -n $keys ]]; then @@ -50,12 +43,6 @@ done 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 Index: Functions/Zle/replace-string-again =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Zle/replace-string-again,v retrieving revision 1.5 diff -p -u -r1.5 replace-string-again --- Functions/Zle/replace-string-again 8 Sep 2010 16:32:45 -0000 1.5 +++ Functions/Zle/replace-string-again 4 Nov 2011 14:14:31 -0000 @@ -40,8 +40,10 @@ if [[ $curwidget = *(pattern|regex)* ]]; rep2+=$rep if [[ $curwidget = *regex* ]]; then autoload -Uz regexp-replace - regexp-replace LBUFFER $_replace_string_src $rep2 || return 1 - regexp-replace RBUFFER $_replace_string_src $rep2 || return 1 + integer ret=1 + regexp-replace LBUFFER $_replace_string_src $rep2 && ret=0 + regexp-replace RBUFFER $_replace_string_src $rep2 && ret=0 + return ret else LBUFFER=${LBUFFER//(#bm)$~_replace_string_src/${(e)rep2}} RBUFFER=${RBUFFER//(#bm)$~_replace_string_src/${(e)rep2}} -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog