all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 27897@debbugs.gnu.org
Subject: bug#27897: [PATCH] 25.1; Add REGION-NONCONTIGUOUS-P arg to other replace.el commands
Date: Wed, 18 Apr 2018 14:05:28 -0700 (PDT)	[thread overview]
Message-ID: <1a732915-3277-45a0-b5fd-9e4e19efe2e9@default> (raw)
In-Reply-To: <6168a7c3-dfa3-4894-8fb7-b2e6e9550dab@default>

[-- Attachment #1: Type: text/plain, Size: 711 bytes --]

Attached is a patch for this.

(I updated doc strings for arg REGION-NONCONTIGUOUS-P.
See also bug #31207, for other doc-string changes that
should be made.)

> ping.
> 
> Do you need an explicit patch for this?  Would that make a
> difference in getting this done?
> 
> > The patch is trivial - just do the same thing to commands such as
> > `replace-string', `replace-regexp', `query-replace-regexp-eval', and
> > `map-query-replace-regexp' as you did to `query-replace' and
> > `query-replace-regexp': add REGION-NONCONTIGUOUS-P arg to the
> > interactive spec the same way, and pass it to `perform-replace' the
> same
> > way.
> >
> > (Shouldn't this have been done in the first place?)

[-- Attachment #2: replace-2018-04-18.patch --]
[-- Type: application/octet-stream, Size: 6369 bytes --]

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))
 
 \f
 (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))))

  parent reply	other threads:[~2018-04-18 21:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-01  4:37 bug#27897: 25.1; Add REGION-NONCONTIGUOUS-P arg to other replace.el commands Drew Adams
2018-04-17 21:53 ` Drew Adams
2018-04-18 21:05 ` Drew Adams [this message]
2018-04-18 21:41   ` bug#27897: [PATCH] " Juri Linkov
2018-04-18 23:25     ` Drew Adams
2018-04-19 19:36       ` Juri Linkov
2018-04-19 19:48         ` Drew Adams
2018-04-19 20:12         ` Drew Adams
2018-04-19 20:27           ` Juri Linkov
2018-04-20  7:31         ` Eli Zaretskii
2018-04-21 19:59           ` Juri Linkov
2018-04-22  2:36             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a732915-3277-45a0-b5fd-9e4e19efe2e9@default \
    --to=drew.adams@oracle.com \
    --cc=27897@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.