diff options
| author | Juri Linkov | 2018-04-19 23:30:46 +0300 |
|---|---|---|
| committer | Juri Linkov | 2018-04-19 23:30:46 +0300 |
| commit | 99de04e6a84dbc93aab479666af126c8fb109b95 (patch) | |
| tree | 20ceee48fe073cdc4713017b64025975df5bf879 /lisp/replace.el | |
| parent | 54f60fcad198be5f39fead6f4d453cea0942322a (diff) | |
| download | emacs-99de04e6a84dbc93aab479666af126c8fb109b95.tar.gz emacs-99de04e6a84dbc93aab479666af126c8fb109b95.zip | |
Use text properties to save search parameters. (Bug#22479)
* lisp/isearch.el (isearch-update-ring): Call isearch-string-propertize.
Delete duplicates with possibly different text properties.
(isearch-string-propertize)
(isearch-update-from-string-properties): New functions.
(with-isearch-suspended, isearch-ring-adjust1):
Call isearch-update-from-string-properties.
(isearch-edit-string): Let-bind minibuffer-allow-text-properties to t.
(isearch-query-replace): Use propertized isearch-string.
(isearch--lax-regexp-function-p): Simplify.
* lisp/replace.el (query-replace-descr): Rewrite to keep text properties
non-destructively in the replacement string.
(query-replace--split-string): Don't remove text properties
by substring-no-properties.
(query-replace-read-args): Try to get isearch-regexp-function
from text-properties.
(perform-replace): Display parameters in the replacement message.
* lisp/desktop.el (desktop--v2s): Check if text properties are unreadable.
(Bug#30786)
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 7f3541d7735..0e723390347 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -147,15 +147,26 @@ is highlighted lazily using isearch lazy highlighting (see | |||
| 147 | See `replace-regexp' and `query-replace-regexp-eval'.") | 147 | See `replace-regexp' and `query-replace-regexp-eval'.") |
| 148 | 148 | ||
| 149 | (defun query-replace-descr (string) | 149 | (defun query-replace-descr (string) |
| 150 | (mapconcat 'isearch-text-char-description string "")) | 150 | (setq string (copy-sequence string)) |
| 151 | (dotimes (i (length string) string) | ||
| 152 | (let ((c (aref string i))) | ||
| 153 | (cond | ||
| 154 | ((< c ?\s) (add-text-properties | ||
| 155 | i (1+ i) | ||
| 156 | `(display ,(propertize (format "^%c" (+ c 64)) 'face 'escape-glyph)) | ||
| 157 | string)) | ||
| 158 | ((= c ?\^?) (add-text-properties | ||
| 159 | i (1+ i) | ||
| 160 | `(display ,(propertize "^?" 'face 'escape-glyph)) | ||
| 161 | string)))))) | ||
| 151 | 162 | ||
| 152 | (defun query-replace--split-string (string) | 163 | (defun query-replace--split-string (string) |
| 153 | "Split string STRING at a substring with property `separator'." | 164 | "Split string STRING at a substring with property `separator'." |
| 154 | (let* ((length (length string)) | 165 | (let* ((length (length string)) |
| 155 | (split-pos (text-property-any 0 length 'separator t string))) | 166 | (split-pos (text-property-any 0 length 'separator t string))) |
| 156 | (if (not split-pos) | 167 | (if (not split-pos) |
| 157 | (substring-no-properties string) | 168 | string |
| 158 | (cons (substring-no-properties string 0 split-pos) | 169 | (cons (substring string 0 split-pos) |
| 159 | (substring-no-properties | 170 | (substring-no-properties |
| 160 | string (or (text-property-not-all | 171 | string (or (text-property-not-all |
| 161 | (1+ split-pos) length 'separator t string) | 172 | (1+ split-pos) length 'separator t string) |
| @@ -301,7 +312,9 @@ the original string if not." | |||
| 301 | (to (if (consp from) (prog1 (cdr from) (setq from (car from))) | 312 | (to (if (consp from) (prog1 (cdr from) (setq from (car from))) |
| 302 | (query-replace-read-to from prompt regexp-flag)))) | 313 | (query-replace-read-to from prompt regexp-flag)))) |
| 303 | (list from to | 314 | (list from to |
| 304 | (and current-prefix-arg (not (eq current-prefix-arg '-))) | 315 | (or (and current-prefix-arg (not (eq current-prefix-arg '-))) |
| 316 | (and (memq 'isearch-regexp-function (text-properties-at 0 from)) | ||
| 317 | (get-text-property 0 'isearch-regexp-function from))) | ||
| 305 | (and current-prefix-arg (eq current-prefix-arg '-))))) | 318 | (and current-prefix-arg (eq current-prefix-arg '-))))) |
| 306 | 319 | ||
| 307 | (defun query-replace (from-string to-string &optional delimited start end backward region-noncontiguous-p) | 320 | (defun query-replace (from-string to-string &optional delimited start end backward region-noncontiguous-p) |
| @@ -2379,8 +2392,17 @@ characters." | |||
| 2379 | (message | 2392 | (message |
| 2380 | (if query-flag | 2393 | (if query-flag |
| 2381 | (apply 'propertize | 2394 | (apply 'propertize |
| 2382 | (substitute-command-keys | 2395 | (concat "Query replacing " |
| 2383 | "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) ") | 2396 | (if backward "backward " "") |
| 2397 | (if delimited-flag | ||
| 2398 | (or (and (symbolp delimited-flag) | ||
| 2399 | (get delimited-flag | ||
| 2400 | 'isearch-message-prefix)) | ||
| 2401 | "word ") "") | ||
| 2402 | (if regexp-flag "regexp " "") | ||
| 2403 | "%s with %s: " | ||
| 2404 | (substitute-command-keys | ||
| 2405 | "(\\<query-replace-map>\\[help] for help) ")) | ||
| 2384 | minibuffer-prompt-properties)))) | 2406 | minibuffer-prompt-properties)))) |
| 2385 | 2407 | ||
| 2386 | ;; Unless a single contiguous chunk is selected, operate on multiple chunks. | 2408 | ;; Unless a single contiguous chunk is selected, operate on multiple chunks. |
| @@ -2598,13 +2620,13 @@ characters." | |||
| 2598 | (with-output-to-temp-buffer "*Help*" | 2620 | (with-output-to-temp-buffer "*Help*" |
| 2599 | (princ | 2621 | (princ |
| 2600 | (concat "Query replacing " | 2622 | (concat "Query replacing " |
| 2623 | (if backward "backward " "") | ||
| 2601 | (if delimited-flag | 2624 | (if delimited-flag |
| 2602 | (or (and (symbolp delimited-flag) | 2625 | (or (and (symbolp delimited-flag) |
| 2603 | (get delimited-flag | 2626 | (get delimited-flag |
| 2604 | 'isearch-message-prefix)) | 2627 | 'isearch-message-prefix)) |
| 2605 | "word ") "") | 2628 | "word ") "") |
| 2606 | (if regexp-flag "regexp " "") | 2629 | (if regexp-flag "regexp " "") |
| 2607 | (if backward "backward " "") | ||
| 2608 | from-string " with " | 2630 | from-string " with " |
| 2609 | next-replacement ".\n\n" | 2631 | next-replacement ".\n\n" |
| 2610 | (substitute-command-keys | 2632 | (substitute-command-keys |