# HG changeset patch # User Juri Linkov # Date 1194731296 0 # Node ID 484f09d924cfa106351bdd8aa065d6b5849d6028 # Parent 77608327b2c8ecbb4d73faae66bbf410c2521f5d (match-substitute-replacement): New function. diff -r 77608327b2c8 -r 484f09d924cf lisp/subr.el --- a/lisp/subr.el Sat Nov 10 17:20:37 2007 +0000 +++ b/lisp/subr.el Sat Nov 10 21:48:16 2007 +0000 @@ -2709,6 +2709,24 @@ (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.