Function: query-replace-regexp-eval

query-replace-regexp-eval is an interactive and byte-compiled function defined in replace.el.gz.

This command is obsolete since 22.1; use the \, feature of query-replace-regexp for interactive calls, and search-forward-regexp/replace-match for Lisp calls.

Signature

(query-replace-regexp-eval REGEXP TO-EXPR &optional DELIMITED START END REGION-NONCONTIGUOUS-P)

Documentation

Replace some things after point matching REGEXP with the result of TO-EXPR.

Interactive use of this function is deprecated in favor of the
\, feature of query-replace-regexp. For non-interactive use, a loop
using search-forward-regexp and replace-match is preferred.

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.

TO-EXPR is a Lisp expression evaluated to compute each replacement. It may reference replace-count to get the number of replacements already made. If the result of TO-EXPR is not a string, it is converted to one using prin1-to-string with the NOESCAPE argument (which see).

For convenience, when entering TO-EXPR interactively, you can use \& to stand for whatever matched the whole of REGEXP, and \N (where N is a digit) to stand for whatever matched the Nth \(...\) (1-based) in REGEXP.

Use \#& or \#N if you want a number instead of a string. In interactive use, \# in itself stands for replace-count.

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.

Use M-n (next-history-element) to pull the last incremental search regexp to the minibuffer that reads REGEXP.

Preserves case in each replacement if case-replace and case-fold-search are non-nil and REGEXP has no uppercase letters.

Ignore read-only matches if query-replace-skip-read-only is non-nil, ignore hidden matches if search-invisible is nil, and ignore more matches using isearch-filter-predicate.

If replace-regexp-lax-whitespace is non-nil, a space or spaces in the regexp to be replaced will match a sequence of whitespace chars defined by the regexp in search-whitespace-regexp.

This function is not affected by replace-char-fold.

Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace only matches that are surrounded by word boundaries. Fourth and fifth arg START and END specify the region to operate on.

Arguments REGEXP, DELIMITED, 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 query-replace-regexp-eval (regexp to-expr &optional delimited start end region-noncontiguous-p)
  "Replace some things after point matching REGEXP with the result of TO-EXPR.

Interactive use of this function is deprecated in favor of the
`\\,' feature of `query-replace-regexp'.  For non-interactive use, a loop
using `search-forward-regexp' and `replace-match' is preferred.

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.

TO-EXPR is a Lisp expression evaluated to compute each replacement.  It may
reference `replace-count' to get the number of replacements already made.
If the result of TO-EXPR is not a string, it is converted to one using
`prin1-to-string' with the NOESCAPE argument (which see).

For convenience, when entering TO-EXPR interactively, you can use `\\&'
to stand for whatever matched the whole of REGEXP, and `\\N' (where
N is a digit) to stand for whatever matched the Nth `\\(...\\)' (1-based)
in REGEXP.

Use `\\#&' or `\\#N' if you want a number instead of a string.
In interactive use, `\\#' in itself stands for `replace-count'.

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.

Use \\<minibuffer-local-map>\\[next-history-element] \
to pull the last incremental search regexp to the minibuffer
that reads REGEXP.

Preserves case in each replacement if `case-replace' and `case-fold-search'
are non-nil and REGEXP has no uppercase letters.

Ignore read-only matches if `query-replace-skip-read-only' is non-nil,
ignore hidden matches if `search-invisible' is nil, and ignore more
matches using `isearch-filter-predicate'.

If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
to be replaced will match a sequence of whitespace chars defined by the
regexp in `search-whitespace-regexp'.

This function is not affected by `replace-char-fold'.

Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
only matches that are surrounded by word boundaries.
Fourth and fifth arg START and END specify the region to operate on.

Arguments REGEXP, DELIMITED, START, END, and REGION-NONCONTIGUOUS-P
are passed to `perform-replace' (which see)."
  (declare (obsolete "use the `\\,' feature of `query-replace-regexp'
for interactive calls, and `search-forward-regexp'/`replace-match'
for Lisp calls." "22.1"))
  (interactive
   (progn
     (barf-if-buffer-read-only)
     (let* ((from
	     ;; Let-bind the history var to disable the "foo -> bar"
	     ;; default.  Maybe we shouldn't disable this default, but
	     ;; for now I'll leave it off.  --Stef
	     (let ((query-replace-defaults nil))
	       (query-replace-read-from "Query replace regexp" t)))
	    (to (list (read-from-minibuffer
		       (format "Query replace regexp %s with eval: "
			       (query-replace-descr from))
		       nil nil t query-replace-to-history-variable from t))))
       ;; We make TO a list because replace-match-string-symbols requires one,
       ;; and the user might enter a single token.
       (replace-match-string-symbols to)
       (list from (car to) current-prefix-arg
	     (if (use-region-p) (region-beginning))
	     (if (use-region-p) (region-end))
	     (if (use-region-p) (region-noncontiguous-p))))))
  (perform-replace regexp (cons #'replace-eval-replacement to-expr)
		   t 'literal delimited nil nil start end nil region-noncontiguous-p))