summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@jurta.org>2007-11-10 21:48:16 +0000
committerJuri Linkov <juri@jurta.org>2007-11-10 21:48:16 +0000
commit8c2e721a69fd7d5a517393a83f4ffc189a699638 (patch)
tree5d7005823b3b050523d5b43cd0d33ed8f4da3923 /lisp/subr.el
parent18d8cb813a5d53244dde9c594aeb6d02d333e743 (diff)
downloademacs-8c2e721a69fd7d5a517393a83f4ffc189a699638.tar.gz
emacs-8c2e721a69fd7d5a517393a83f4ffc189a699638.tar.bz2
emacs-8c2e721a69fd7d5a517393a83f4ffc189a699638.zip
(match-substitute-replacement): New function.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el18
1 files changed, 18 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 17008e058ba..17abc70e073 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2709,6 +2709,24 @@ STRING should be given if the last search was by `string-match' on STRING."
(buffer-substring-no-properties (match-beginning num)
(match-end num)))))
+
+(defun match-substitute-replacement (replacement
+ &optional fixedcase literal string subexp)
+ "Return REPLACEMENT as it will be inserted by `replace-match'.
+In other words, all back-references in the form `\\&' and `\\N'
+are substituted with actual strings matched by the last search.
+Optional FIXEDCASE, LITERAL, STRING and SUBEXP have the same
+meaning as for `replace-match'."
+ (let ((match (match-string 0 string)))
+ (save-match-data
+ (set-match-data (mapcar (lambda (x)
+ (if (numberp x)
+ (- x (match-beginning 0))
+ x))
+ (match-data t)))
+ (replace-match replacement fixedcase literal match subexp))))
+
+
(defun looking-back (regexp &optional limit greedy)
"Return non-nil if text before point matches regular expression REGEXP.
Like `looking-at' except matches before point, and is slower.