emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 61881d3: Put text properties on query-replace separ


From: Juri Linkov
Subject: [Emacs-diffs] master 61881d3: Put text properties on query-replace separator string instead of "\0"
Date: Mon, 27 Feb 2017 17:51:06 -0500 (EST)

branch: master
commit 61881d32ad4a8407fd4a3386a5f05b9f446f58fc
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    Put text properties on query-replace separator string instead of "\0"
    
    * lisp/replace.el (query-replace--split-string):
    Split at a substring instead of just character.
    (query-replace-read-from): Put text properties on the
    separator string instead of "\0".  (Bug#25482)
---
 lisp/replace.el | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/lisp/replace.el b/lisp/replace.el
index b96c883..0841ba1 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -149,14 +149,17 @@ See `replace-regexp' and `query-replace-regexp-eval'.")
   (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 @@ wants to replace FROM with TO."
   (if query-replace-interactive
       (car (if regexp-flag regexp-search-ring search-ring))
     (let* ((history-add-new-input nil)
-          (separator
+          (separator-string
            (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)
+             ;; 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 separator-string
+             (propertize separator-string
+                         'display separator-string
+                         'face 'minibuffer-prompt
                          'separator t)))
           (minibuffer-history
            (append
@@ -203,7 +208,8 @@ wants to replace FROM with TO."
               (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 via email to

[Prev in Thread] Current Thread [Next in Thread]