summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Doc/Zsh/contrib.yo7
-rw-r--r--Functions/Zle/replace-string26
3 files changed, 27 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 554d4d36c..3d88749f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2005-01-13 Peter Stephenson <pws@csr.com>
+ * 20708: Doc/Zsh/contrib.yo, Functions/Zle/replace-string:
+ replace-string can offer previous values for editing.
+
* unposted: README, Config/version.mk, Etc/FAQ.yo:
release 4.2.3.
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 14a402785..9f74af154 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -814,6 +814,13 @@ replaced by the var(N)th parenthesised expression matched. The form
`tt(\{)var(N)tt(})' may be used to protect the digit from following
digits.
+By default the previous source or replacement string will not be offered
+for editing. However, this feature can be activated by setting the style
+tt(edit-previous) in the context tt(:zle:)var(widget) (for example,
+tt(:zle:replace-string)) to tt(true). In addition, a positive
+numeric argument forces the previous values to be offered, a negative or
+zero argument forces them not to be.
+
For example, starting from the line:
example(print This line contains fan and fond)
diff --git a/Functions/Zle/replace-string b/Functions/Zle/replace-string
index 2fe0da901..577e9174d 100644
--- a/Functions/Zle/replace-string
+++ b/Functions/Zle/replace-string
@@ -4,14 +4,21 @@ setopt extendedglob
autoload read-from-minibuffer
local p1="Replace: " p2=" with: "
-local src rep REPLY MATCH MBEGIN MEND curwidget=$WIDGET
+local REPLY MATCH MBEGIN MEND curwidget=$WIDGET previous
local -a match mbegin mend
-read-from-minibuffer $p1 || return 1
-src=$REPLY
+if (( ${+NUMERIC} )); then
+ (( $NUMERIC > 0 )) && previous=1
+else
+ zstyle -t ":zle:$WIDGET" edit-previous && previous=1
+fi
+
+read-from-minibuffer $p1 ${previous:+$_replace_string_src} || return 1
+_replace_string_src=$REPLY
-read-from-minibuffer "$p1$src$p2" || return 1
-rep=$REPLY
+read-from-minibuffer "$p1$_replace_string_src$p2" \
+ ${previous:+$_replace_string_rep} || return 1
+_replace_string_rep=$REPLY
if [[ $curwidget = *pattern* ]]; then
local rep2
@@ -20,6 +27,7 @@ if [[ $curwidget = *pattern* ]]; then
# while preceded by an odd number of backslashes is inactive,
# with one backslash being stripped. A similar logic applies
# to \digit.
+ local rep=$_replace_string_rep
while [[ $rep = (#b)([^\\]#)(\\\\)#(\\|)(\&|\\<->|\\\{<->\})(*) ]]; do
if [[ -n $match[3] ]]; then
# Expression is quoted, strip quotes
@@ -37,9 +45,9 @@ if [[ $curwidget = *pattern* ]]; then
rep=${match[5]}
done
rep2+=$rep
- LBUFFER=${LBUFFER//(#bm)$~src/${(e)rep2}}
- RBUFFER=${RBUFFER//(#bm)$~src/${(e)rep2}}
+ LBUFFER=${LBUFFER//(#bm)$~_replace_string_src/${(e)rep2}}
+ RBUFFER=${RBUFFER//(#bm)$~_replace_string_src/${(e)rep2}}
else
- LBUFFER=${LBUFFER//$src/$rep}
- RBUFFER=${RBUFFER//$src/$rep}
+ LBUFFER=${LBUFFER//$_replace_string_src/$_replace_string_rep}
+ RBUFFER=${RBUFFER//$_replace_string_src/$_replace_string_rep}
fi