aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2017-02-28 00:50:57 +0200
committerJuri Linkov2017-02-28 00:50:57 +0200
commit61881d32ad4a8407fd4a3386a5f05b9f446f58fc (patch)
treef30fcdbcc40045c2bd47b282f1b9e38a33b01f8b /lisp
parent3bf717b05b9d8fb53e953aa56649ffc38fd6e5d1 (diff)
downloademacs-61881d32ad4a8407fd4a3386a5f05b9f446f58fc.tar.gz
emacs-61881d32ad4a8407fd4a3386a5f05b9f446f58fc.zip
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)
Diffstat (limited to 'lisp')
-rw-r--r--lisp/replace.el34
1 files changed, 20 insertions, 14 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index b96c883982e..0841ba11b8b 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -149,14 +149,17 @@ See `replace-regexp' and `query-replace-regexp-eval'.")
149 (mapconcat 'isearch-text-char-description string "")) 149 (mapconcat 'isearch-text-char-description string ""))
150 150
151(defun query-replace--split-string (string) 151(defun query-replace--split-string (string)
152 "Split string STRING at a character with property `separator'" 152 "Split string STRING at a substring with property `separator'."
153 (let* ((length (length string)) 153 (let* ((length (length string))
154 (split-pos (text-property-any 0 length 'separator t string))) 154 (split-pos (text-property-any 0 length 'separator t string)))
155 (if (not split-pos) 155 (if (not split-pos)
156 (substring-no-properties string) 156 (substring-no-properties string)
157 (cl-assert (not (text-property-any (1+ split-pos) length 'separator t string)))
158 (cons (substring-no-properties string 0 split-pos) 157 (cons (substring-no-properties string 0 split-pos)
159 (substring-no-properties string (1+ split-pos) length))))) 158 (substring-no-properties
159 string (or (text-property-not-all
160 (1+ split-pos) length 'separator t string)
161 length)
162 length)))))
160 163
161(defun query-replace-read-from (prompt regexp-flag) 164(defun query-replace-read-from (prompt regexp-flag)
162 "Query and return the `from' argument of a query-replace operation. 165 "Query and return the `from' argument of a query-replace operation.
@@ -165,17 +168,19 @@ wants to replace FROM with TO."
165 (if query-replace-interactive 168 (if query-replace-interactive
166 (car (if regexp-flag regexp-search-ring search-ring)) 169 (car (if regexp-flag regexp-search-ring search-ring))
167 (let* ((history-add-new-input nil) 170 (let* ((history-add-new-input nil)
168 (separator 171 (separator-string
169 (when query-replace-from-to-separator 172 (when query-replace-from-to-separator
170 (propertize "\0" 173 ;; Check if the first non-whitespace char is displayable
171 'display 174 (if (char-displayable-p
172 (propertize 175 (string-to-char (replace-regexp-in-string
173 (if (char-displayable-p 176 " " "" query-replace-from-to-separator)))
174 (string-to-char (replace-regexp-in-string 177 query-replace-from-to-separator
175 " " "" query-replace-from-to-separator))) 178 " -> ")))
176 query-replace-from-to-separator 179 (separator
177 " -> ") 180 (when separator-string
178 'face 'minibuffer-prompt) 181 (propertize separator-string
182 'display separator-string
183 'face 'minibuffer-prompt
179 'separator t))) 184 'separator t)))
180 (minibuffer-history 185 (minibuffer-history
181 (append 186 (append
@@ -203,7 +208,8 @@ wants to replace FROM with TO."
203 (minibuffer-with-setup-hook 208 (minibuffer-with-setup-hook
204 (lambda () 209 (lambda ()
205 (setq-local text-property-default-nonsticky 210 (setq-local text-property-default-nonsticky
206 (cons '(separator . t) text-property-default-nonsticky))) 211 (append '((separator . t) (face . t))
212 text-property-default-nonsticky)))
207 (if regexp-flag 213 (if regexp-flag
208 (read-regexp prompt nil 'minibuffer-history) 214 (read-regexp prompt nil 'minibuffer-history)
209 (read-from-minibuffer 215 (read-from-minibuffer