Function: replace-match-maybe-edit
replace-match-maybe-edit is a byte-compiled function defined in
replace.el.gz.
Signature
(replace-match-maybe-edit NEWTEXT FIXEDCASE LITERAL NOEDIT MATCH-DATA &optional BACKWARD)
Documentation
Make a replacement with replace-match, editing \?.
FIXEDCASE, LITERAL are passed to replace-match (which see).
After possibly editing it (if \? is present), NEWTEXT is also
passed to replace-match. If NOEDIT is true, no check for \?
is made (to save time).
MATCH-DATA is used for the replacement, and is a data structure
as returned from the match-data function.
In case editing is done, it is changed to use markers. BACKWARD is
used to reverse the replacement direction.
The return value is non-nil if there has been no \? or NOEDIT was
passed in. If LITERAL is set, no checking is done, anyway.
Source Code
;; Defined in /usr/src/emacs/lisp/replace.el.gz
(defun replace-match-maybe-edit (newtext fixedcase literal noedit match-data
&optional backward)
"Make a replacement with `replace-match', editing `\\?'.
FIXEDCASE, LITERAL are passed to `replace-match' (which see).
After possibly editing it (if `\\?' is present), NEWTEXT is also
passed to `replace-match'. If NOEDIT is true, no check for `\\?'
is made (to save time).
MATCH-DATA is used for the replacement, and is a data structure
as returned from the `match-data' function.
In case editing is done, it is changed to use markers. BACKWARD is
used to reverse the replacement direction.
The return value is non-nil if there has been no `\\?' or NOEDIT was
passed in. If LITERAL is set, no checking is done, anyway."
(unless (or literal noedit)
(setq noedit t)
(while (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\?\\)"
newtext)
(setq newtext
(read-string "Edit replacement string: "
(prog1
(cons
(replace-match "" t t newtext 3)
(1+ (match-beginning 3)))
(setq match-data
(replace-match-data
nil match-data match-data))))
noedit nil)))
(set-match-data match-data)
(replace-match newtext fixedcase literal)
;; `query-replace' undo feature needs the beginning of the match position,
;; but `replace-match' may change it, for instance, with a regexp like "^".
;; Ensure that this function preserves the match data (Bug#31492).
(set-match-data match-data)
;; `replace-match' leaves point at the end of the replacement text,
;; so move point to the beginning when replacing backward.
(when backward (goto-char (nth 0 match-data)))
noedit)