Function: map-query-replace-regexp
map-query-replace-regexp is an interactive and byte-compiled function
defined in replace.el.gz.
Signature
(map-query-replace-regexp REGEXP TO-STRINGS &optional N START END REGION-NONCONTIGUOUS-P)
Documentation
Replace some matches for REGEXP with various strings, in rotation.
The second argument TO-STRINGS contains the replacement strings, separated
by spaces. This command works like query-replace-regexp except that
each successive replacement uses the next successive replacement string,
wrapping around from the last such string to the first.
In Transient Mark mode, if the mark is active, operate on the contents of the region. Otherwise, operate from point to the end of the buffer's accessible portion.
Non-interactively, TO-STRINGS may be a list of replacement strings.
Interactively, reads the regexp using read-regexp.
Use M-n (next-history-element) to pull the last incremental search regexp to the minibuffer
that reads REGEXP.
As each match is found, the user must type a character saying
what to do with it. Type SPC or y to replace the match,
DEL or n to skip and go to the next match. For more directions,
type C-h (help-command) at that time.
A prefix argument N says to use each replacement string N times before rotating to the next. Fourth and fifth arg START and END specify the region to operate on.
Arguments REGEXP, START, END, and REGION-NONCONTIGUOUS-P are passed to
perform-replace (which see).
Probably introduced at or before Emacs version 21.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/replace.el.gz
(defun map-query-replace-regexp (regexp to-strings &optional n start end region-noncontiguous-p)
"Replace some matches for REGEXP with various strings, in rotation.
The second argument TO-STRINGS contains the replacement strings, separated
by spaces. This command works like `query-replace-regexp' except that
each successive replacement uses the next successive replacement string,
wrapping around from the last such string to the first.
In Transient Mark mode, if the mark is active, operate on the contents
of the region. Otherwise, operate from point to the end of the buffer's
accessible portion.
Non-interactively, TO-STRINGS may be a list of replacement strings.
Interactively, reads the regexp using `read-regexp'.
Use \\<minibuffer-local-map>\\[next-history-element] \
to pull the last incremental search regexp to the minibuffer
that reads REGEXP.
As each match is found, the user must type a character saying
what to do with it. Type SPC or `y' to replace the match,
DEL or `n' to skip and go to the next match. For more directions,
type \\[help-command] at that time.
A prefix argument N says to use each replacement string N times
before rotating to the next.
Fourth and fifth arg START and END specify the region to operate on.
Arguments REGEXP, START, END, and REGION-NONCONTIGUOUS-P are passed to
`perform-replace' (which see)."
(declare (interactive-args
(start (use-region-beginning))
(end (use-region-end))
(region-noncontiguous-p (use-region-noncontiguous-p))))
(interactive
(let* ((from (read-regexp "Map query replace (regexp): " nil
query-replace-from-history-variable))
(to (read-from-minibuffer
(format "Query replace %s with (space-separated strings): "
(query-replace-descr from))
nil nil nil
query-replace-to-history-variable from t)))
(list from to
(and current-prefix-arg
(prefix-numeric-value current-prefix-arg))
(use-region-beginning) (use-region-end)
(use-region-noncontiguous-p))))
(let (replacements)
(if (listp to-strings)
(setq replacements to-strings)
(while (/= (length to-strings) 0)
(if (string-search " " to-strings)
(setq replacements
(append replacements
(list (substring to-strings 0
(string-search " " to-strings))))
to-strings (substring to-strings
(1+ (string-search " " to-strings))))
(setq replacements (append replacements (list to-strings))
to-strings ""))))
(perform-replace regexp replacements t t nil n nil start end nil region-noncontiguous-p)))