From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22580 invoked by alias); 7 Nov 2011 11:11:20 -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: 29894 Received: (qmail 11076 invoked from network); 7 Nov 2011 11:11:11 -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) Date: Mon, 7 Nov 2011 10:15:22 +0000 From: Peter Stephenson To: Zsh hackers list Subject: Re: PATCH: replace string etc. Message-ID: <20111107101522.146d7c90@pwslap01u.europe.root.pri> In-Reply-To: <11453.1320416388@csr.com> References: <11453.1320416388@csr.com> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.101.11.233] X-Scanned-By: MailControl 7.6.3 (www.mailcontrol.com) on 10.71.0.135 On Fri, 4 Nov 2011 14:19:48 +0000 Peter Stephenson wrote: > I had a go at trying to make replace-string use a local history, > but ... I've given up. However, here's a simple addition that offers the previous replacement as a default. Index: Doc/Zsh/contrib.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v retrieving revision 1.137 diff -p -u -r1.137 contrib.yo --- Doc/Zsh/contrib.yo 3 Jul 2011 11:54:12 -0000 1.137 +++ Doc/Zsh/contrib.yo 7 Nov 2011 10:13:49 -0000 @@ -2335,6 +2335,11 @@ regular expression matching is performed replacement. Note that the previous source and replacement text are the same whether pattern, regular expression or string matching is used. +In addition, tt(replace-string) shows the previous replacement above +the prompt, so long as there was one during the current session; if the +source string is empty, that replacement will be repeated without +the widget prompting for a replacement string. + For example, starting from the line: example(print This line contains fan and fond) Index: Functions/Zle/replace-string =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Zle/replace-string,v retrieving revision 1.5 diff -p -u -r1.5 replace-string --- Functions/Zle/replace-string 28 Jul 2010 14:01:12 -0000 1.5 +++ Functions/Zle/replace-string 7 Nov 2011 10:13:49 -0000 @@ -3,7 +3,15 @@ setopt extendedglob autoload -Uz read-from-minibuffer replace-string-again -local p1="Replace: " p2=" with: " +local p1 p2 + +if [[ -n $_replace_string_src ]]; then + p1="[$_replace_string_src -> $_replace_string_rep]"$'\n' +fi + +p1+="Replace: " +p2=" with: " + # Saving curwidget is necessary to avoid the widget name being overwritten. local REPLY previous curwidget=$WIDGET @@ -14,10 +22,12 @@ else fi read-from-minibuffer $p1 ${previous:+$_replace_string_src} || return 1 -typeset -g _replace_string_src=$REPLY +if [[ -n $REPLY ]]; then + typeset -g _replace_string_src=$REPLY -read-from-minibuffer "$p1$_replace_string_src$p2" \ - ${previous:+$_replace_string_rep} || return 1 -typeset -g _replace_string_rep=$REPLY + read-from-minibuffer "$p1$_replace_string_src$p2" \ + ${previous:+$_replace_string_rep} || return 1 + typeset -g _replace_string_rep=$REPLY +fi replace-string-again $curwidget -- 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