Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: replace string etc.
On Fri, 4 Nov 2011 14:19:48 +0000
Peter Stephenson <pws@xxxxxxx> 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 <pws@xxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author