about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--Functions/Zle/read-from-minibuffer35
-rw-r--r--Functions/Zle/replace-string-again6
3 files changed, 21 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index d2a18fd80..8eda2f415 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-11-04  Peter Stephenson  <pws@csr.com>
 
+	* 29892: Functions/Zle/read-from-minibuffer,
+	Functions/Zle/replace-string: fix regular expression
+	replacements right of the cursor; make save and restore
+	in read-from-minibuffer more automated.
+
 	* 29891: Doc/Zsh/zle.yo, Src/Zle/zle_thingy.c: allow "zle -lL"
 	with arguments to list in -L format.
 
@@ -15538,5 +15543,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5492 $
+* $Revision: 1.5493 $
 *****************************************************
diff --git a/Functions/Zle/read-from-minibuffer b/Functions/Zle/read-from-minibuffer
index fce6b5319..57e926884 100644
--- a/Functions/Zle/read-from-minibuffer
+++ b/Functions/Zle/read-from-minibuffer
@@ -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
diff --git a/Functions/Zle/replace-string-again b/Functions/Zle/replace-string-again
index f24c14f88..dac3db755 100644
--- a/Functions/Zle/replace-string-again
+++ b/Functions/Zle/replace-string-again
@@ -40,8 +40,10 @@ if [[ $curwidget = *(pattern|regex)* ]]; then
     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}}