Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: replace string etc.
- X-seq: zsh-workers 29892
- From: Peter Stephenson <pws@xxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: PATCH: replace string etc.
- Date: Fri, 4 Nov 2011 14:19:48 +0000
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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@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