diff -u replace-2018-04-18.el replace-2018-04-18-PATCHED.el
--- replace-2018-04-18.el	2018-04-18 07:58:34.745852300 -0700
+++ replace-2018-04-18-PATCHED.el	2018-04-18 13:58:44.825710000 -0700
@@ -345,6 +345,9 @@
 
 Fourth and fifth arg START and END specify the region to operate on.
 
+Arguments FROM-STRING, TO-STRING, DELIMITED, START, END, BACKWARD, and
+REGION-NONCONTIGUOUS-P are passed to `perform-replace' (which see).
+
 To customize possible responses, change the bindings in `query-replace-map'."
   (interactive
    (let ((common
@@ -427,7 +430,10 @@
 
 When using those Lisp features interactively in the replacement
 text, TO-STRING is actually made a list instead of a string.
-Use \\[repeat-complex-command] after this command for details."
+Use \\[repeat-complex-command] after this command for details.
+
+Arguments REGEXP, TO-STRING, DELIMITED, START, END, BACKWARD, and
+REGION-NONCONTIGUOUS-P are passed to `perform-replace' (which see)."
   (interactive
    (let ((common
 	  (query-replace-read-args
@@ -450,7 +456,7 @@
 
 (define-key esc-map [?\C-%] 'query-replace-regexp)
 
-(defun query-replace-regexp-eval (regexp to-expr &optional delimited start end)
+(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
@@ -496,7 +502,10 @@
 
 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."
+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"))
@@ -518,11 +527,12 @@
        (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-end))
+             (and (use-region-p) (region-noncontiguous-p))))))
   (perform-replace regexp (cons 'replace-eval-replacement to-expr)
-		   t 'literal delimited nil nil start end))
+		   t 'literal delimited nil nil start end nil region-noncontiguous-p))
 
-(defun map-query-replace-regexp (regexp to-strings &optional n start end)
+(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
@@ -542,7 +552,10 @@
 
 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."
+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)."
   (interactive
    (let* ((from (read-regexp "Map query replace (regexp): " nil
 			     query-replace-from-history-variable))
@@ -555,7 +568,8 @@
 	   (and current-prefix-arg
 		(prefix-numeric-value current-prefix-arg))
 	   (if (use-region-p) (region-beginning))
-	   (if (use-region-p) (region-end)))))
+	   (if (use-region-p) (region-end))
+           (and (use-region-p) (region-noncontiguous-p)))))
   (let (replacements)
     (if (listp to-strings)
 	(setq replacements to-strings)
@@ -569,9 +583,9 @@
 				       (1+ (string-match " " to-strings))))
 	  (setq replacements (append replacements (list to-strings))
 		to-strings ""))))
-    (perform-replace regexp replacements t t nil n nil start end)))
+    (perform-replace regexp replacements t t nil n nil start end nil region-noncontiguous-p)))
 
-(defun replace-string (from-string to-string &optional delimited start end backward)
+(defun replace-string (from-string to-string &optional delimited start end backward region-noncontiguous-p)
   "Replace occurrences of FROM-STRING with TO-STRING.
 Preserve case in each match if `case-replace' and `case-fold-search'
 are non-nil and FROM-STRING has no uppercase letters.
@@ -625,10 +639,11 @@
      (list (nth 0 common) (nth 1 common) (nth 2 common)
 	   (if (use-region-p) (region-beginning))
 	   (if (use-region-p) (region-end))
-	   (nth 3 common))))
-  (perform-replace from-string to-string nil nil delimited nil nil start end backward))
+	   (nth 3 common)
+           (and (use-region-p) (region-noncontiguous-p)))))
+  (perform-replace from-string to-string nil nil delimited nil nil start end backward region-noncontiguous-p))
 
-(defun replace-regexp (regexp to-string &optional delimited start end backward)
+(defun replace-regexp (regexp to-string &optional delimited start end backward region-noncontiguous-p)
   "Replace things after point matching REGEXP with TO-STRING.
 Preserve case in each match if `case-replace' and `case-fold-search'
 are non-nil and REGEXP has no uppercase letters.
@@ -701,8 +716,9 @@
      (list (nth 0 common) (nth 1 common) (nth 2 common)
 	   (if (use-region-p) (region-beginning))
 	   (if (use-region-p) (region-end))
-	   (nth 3 common))))
-  (perform-replace regexp to-string nil t delimited nil nil start end backward))
+	   (nth 3 common)
+           (and (use-region-p) (region-noncontiguous-p)))))
+  (perform-replace regexp to-string nil t delimited nil nil start end backward region-noncontiguous-p))
 
 
 (defvar regexp-history nil
@@ -2313,7 +2329,12 @@
 containing a function and its first argument.  The function is
 called to generate each replacement like this:
   (funcall (car replacements) (cdr replacements) replace-count)
-It must return a string."
+It must return a string.
+
+Non-nil REGION-NONCONTIGUOUS-P means that the region is composed of
+noncontiguous pieces.  The most common example of this is a
+rectangular region, where the pieces are separated by newline
+characters."
   (or map (setq map query-replace-map))
   (and query-flag minibuffer-auto-raise
        (raise-frame (window-frame (minibuffer-window))))
