zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: PATCH: replace string etc.
Date: Fri, 4 Nov 2011 14:19:48 +0000	[thread overview]
Message-ID: <11453.1320416388@csr.com> (raw)

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 <pws@csr.com>            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


             reply	other threads:[~2011-11-04 14:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-04 14:19 Peter Stephenson [this message]
2011-11-07 10:15 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11453.1320416388@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).