about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorPaul Ackersviller <packersv@users.sourceforge.net>2007-03-18 23:13:22 +0000
committerPaul Ackersviller <packersv@users.sourceforge.net>2007-03-18 23:13:22 +0000
commit298de9ddb1ec77a23c7fb64e68f5ad404fbe74d3 (patch)
tree8d1f76f4e0a3815ca6d6545ea625983f6ef58bc5 /Functions
parent462c07e520d4d7022b694e0ec768bc559c88cacb (diff)
downloadzsh-298de9ddb1ec77a23c7fb64e68f5ad404fbe74d3.tar.gz
zsh-298de9ddb1ec77a23c7fb64e68f5ad404fbe74d3.tar.xz
zsh-298de9ddb1ec77a23c7fb64e68f5ad404fbe74d3.zip
New with 4.3, workers/22854.
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Zle/replace-string-again45
1 files changed, 45 insertions, 0 deletions
diff --git a/Functions/Zle/replace-string-again b/Functions/Zle/replace-string-again
new file mode 100644
index 000000000..122f0a8ee
--- /dev/null
+++ b/Functions/Zle/replace-string-again
@@ -0,0 +1,45 @@
+# Back end for replace-string; can be called as a widget to repeat
+# the previous replacement.  _replace_string_src and _replace_string_rep
+# are global.
+
+# When called from replace-string, we need to use the widget
+# name passed to decide whether to do pattern matching: the widget
+# may since have been overwritten.
+local MATCH MBEGIN MEND curwidget=${1:-$WIDGET}
+local -a match mbegin mend
+
+if [[ -z $_replace_string_src ]]; then
+  zle -M No string to replace.
+fi
+
+if [[ $curwidget = *pattern* ]]; then
+    local rep2
+    # The following horror is so that an & preceded by an even
+    # number of backslashes is active, without stripping backslashes,
+    # 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
+	    rep2="${match[1]}${match[2]}${match[4]}"
+	else
+	    rep2+="${match[1]}${match[2]}"
+	    if [[ $match[4] = \& ]]; then
+		rep2+='${MATCH}'
+	    elif [[ $match[4] = \\\{* ]]; then
+		rep2+='${match['${match[4][3,-2]}']}'
+	    else
+		rep2+='${match['${match[4][2,-1]}']}'
+	    fi
+	fi
+	rep=${match[5]}
+    done
+    rep2+=$rep
+    LBUFFER=${LBUFFER//(#bm)$~_replace_string_src/${(e)rep2}}
+    RBUFFER=${RBUFFER//(#bm)$~_replace_string_src/${(e)rep2}}
+else
+    LBUFFER=${LBUFFER//$_replace_string_src/$_replace_string_rep}
+    RBUFFER=${RBUFFER//$_replace_string_src/$_replace_string_rep}
+fi