unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Thierry Volpiatto <thierry.volpiatto@gmail.com>
Cc: 25482@debbugs.gnu.org
Subject: bug#25482: 26.0.50; Allow setting `query-replace-from-to-separator` to nil
Date: Thu, 16 Feb 2017 22:43:08 +0200	[thread overview]
Message-ID: <87d1ehzx2b.fsf@localhost> (raw)
In-Reply-To: <871svzzcn4.fsf@gmail.com>

>> As for your idea of using plain ASCII separators without text properties,
>> the problem is that it will not work if the user wants to replace
>> the same string as is used for the separator, e.g. to replace
>> → with  -> in the current buffer.
>
> So yes, this is a good reason.

Wait, maybe you are right in the idea to use the separator string as is,
instead of the null character.  We still need to use text properties
to unambiguously mark separator boundaries, so we can't rely on
regexp matching to find separator boundaries.  But at least “ → ”
is not more frequent string to replace than the null character.

Putting special text properties on the separator itself instead of
the null character might be more beneficial for such situations
where the separator is exposed without text properties, e.g. when
copying the contents of the minibuffer.  However, one drawback is
that searching in the replacement minibuffer history for the same
string as the separator (e.g. “→”) will find matches in the separator,
not only in replacement strings.

This patch demonstrates what we could do.  It still uses the ‘display’
property because I see no other simple way to make the separator string
intangible.

diff --git a/lisp/replace.el b/lisp/replace.el
index b96c883..6600ff6 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -149,14 +149,17 @@ query-replace-descr
   (mapconcat 'isearch-text-char-description string ""))
 
 (defun query-replace--split-string (string)
-  "Split string STRING at a character with property `separator'"
+  "Split string STRING at a substring with property `separator'"
   (let* ((length (length string))
          (split-pos (text-property-any 0 length 'separator t string)))
     (if (not split-pos)
         (substring-no-properties string)
-      (cl-assert (not (text-property-any (1+ split-pos) length 'separator t string)))
       (cons (substring-no-properties string 0 split-pos)
-            (substring-no-properties string (1+ split-pos) length)))))
+            (substring-no-properties
+             string (or (text-property-not-all
+                         (1+ split-pos) length 'separator t string)
+                        length)
+             length)))))
 
 (defun query-replace-read-from (prompt regexp-flag)
   "Query and return the `from' argument of a query-replace operation.
@@ -165,17 +168,19 @@ query-replace-read-from
   (if query-replace-interactive
       (car (if regexp-flag regexp-search-ring search-ring))
     (let* ((history-add-new-input nil)
+           (separator-string
+            (when query-replace-from-to-separator
+              ;; Check if the first non-whitespace char is displayable
+	      (if (char-displayable-p
+                   (string-to-char (replace-regexp-in-string
+                                    " " "" query-replace-from-to-separator)))
+                  query-replace-from-to-separator
+                " -> ")))
 	   (separator
-	    (when query-replace-from-to-separator
-	      (propertize "\0"
-			  'display
-                          (propertize
-                           (if (char-displayable-p
-                                (string-to-char (replace-regexp-in-string
-                                                 " " "" query-replace-from-to-separator)))
-                               query-replace-from-to-separator
-                             " -> ")
-                           'face 'minibuffer-prompt)
+	    (when separator-string
+	      (propertize separator-string
+                         'display separator-string
+                         'face 'minibuffer-prompt
 			  'separator t)))
 	   (minibuffer-history
 	    (append
@@ -203,7 +210,8 @@ query-replace-read-from
               (minibuffer-with-setup-hook
                   (lambda ()
                     (setq-local text-property-default-nonsticky
-                                (cons '(separator . t) text-property-default-nonsticky)))
+                                (append '((separator . t) (face . t))
+                                        text-property-default-nonsticky)))
                 (if regexp-flag
                     (read-regexp prompt nil 'minibuffer-history)
                   (read-from-minibuffer





  reply	other threads:[~2017-02-16 20:43 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-19  8:18 bug#25482: 26.0.50; Allow setting `query-replace-from-to-separator` to nil Thierry Volpiatto
2017-01-19 16:01 ` Eli Zaretskii
     [not found]   ` <87vatac0a2.fsf@gmail.com>
2017-01-20  5:42     ` bug#25482: Fwd: " Thierry Volpiatto
2017-01-20  7:56     ` Eli Zaretskii
2017-01-20 11:35       ` Thierry Volpiatto
2017-01-20 13:06         ` Eli Zaretskii
2017-01-20 15:16           ` Thierry Volpiatto
2017-01-22 19:06             ` Eli Zaretskii
2017-01-22 20:14               ` Thierry Volpiatto
2017-01-22 20:32                 ` Eli Zaretskii
2017-01-23  8:13                   ` Thierry Volpiatto
2017-01-28  6:50                     ` Thierry Volpiatto
2017-01-28  7:31                       ` Eli Zaretskii
2017-01-28 10:43                         ` Thierry Volpiatto
2017-01-28 11:01                           ` Eli Zaretskii
2017-01-28 11:23                             ` Thierry Volpiatto
2017-01-28 13:50                               ` Eli Zaretskii
2017-01-28 16:46                                 ` Thierry Volpiatto
     [not found]                                   ` <87k29ey93n.fsf@mail.linkov.net>
2017-01-29  3:42                                     ` Eli Zaretskii
2017-01-30  0:16                                       ` Juri Linkov
2017-02-13  0:37                                   ` Juri Linkov
2017-02-13  2:24                                     ` Glenn Morris
2017-02-13  3:04                                       ` Glenn Morris
2017-02-13  5:51                                     ` Eli Zaretskii
2017-02-14  0:04                                       ` Juri Linkov
2017-02-14  0:24                                         ` Drew Adams
2017-02-18 10:45                                           ` Eli Zaretskii
2017-02-13  5:53                                     ` Thierry Volpiatto
2017-02-16 20:43                                       ` Juri Linkov [this message]
2017-01-21 10:05           ` Thierry Volpiatto
2017-01-21 10:24             ` Thierry Volpiatto
2017-01-20  5:54   ` Thierry Volpiatto

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87d1ehzx2b.fsf@localhost \
    --to=juri@linkov.net \
    --cc=25482@debbugs.gnu.org \
    --cc=thierry.volpiatto@gmail.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).