aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el96
1 files changed, 51 insertions, 45 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 001f7d1a78d..f192574a7e2 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -128,20 +128,21 @@ wants to replace FROM with TO."
128 (if query-replace-interactive 128 (if query-replace-interactive
129 (car (if regexp-flag regexp-search-ring search-ring)) 129 (car (if regexp-flag regexp-search-ring search-ring))
130 (let* ((history-add-new-input nil) 130 (let* ((history-add-new-input nil)
131 (prompt
132 (if query-replace-defaults
133 (format "%s (default %s -> %s): " prompt
134 (query-replace-descr (car query-replace-defaults))
135 (query-replace-descr (cdr query-replace-defaults)))
136 (format "%s: " prompt)))
131 (from 137 (from
132 ;; The save-excursion here is in case the user marks and copies 138 ;; The save-excursion here is in case the user marks and copies
133 ;; a region in order to specify the minibuffer input. 139 ;; a region in order to specify the minibuffer input.
134 ;; That should not clobber the region for the query-replace itself. 140 ;; That should not clobber the region for the query-replace itself.
135 (save-excursion 141 (save-excursion
136 (read-from-minibuffer 142 (if regexp-flag
137 (if query-replace-defaults 143 (read-regexp prompt nil query-replace-from-history-variable)
138 (format "%s (default %s -> %s): " prompt 144 (read-from-minibuffer
139 (query-replace-descr (car query-replace-defaults)) 145 prompt nil nil nil query-replace-from-history-variable nil t)))))
140 (query-replace-descr (cdr query-replace-defaults)))
141 (format "%s: " prompt))
142 nil nil nil
143 query-replace-from-history-variable
144 nil t))))
145 (if (and (zerop (length from)) query-replace-defaults) 146 (if (and (zerop (length from)) query-replace-defaults)
146 (cons (car query-replace-defaults) 147 (cons (car query-replace-defaults)
147 (query-replace-compile-replacement 148 (query-replace-compile-replacement
@@ -574,38 +575,47 @@ of `history-length', which see.")
574(defvar occur-collect-regexp-history '("\\1") 575(defvar occur-collect-regexp-history '("\\1")
575 "History of regexp for occur's collect operation") 576 "History of regexp for occur's collect operation")
576 577
577(defun read-regexp (prompt &optional default-value) 578(defun read-regexp (prompt &optional defaults history)
578 "Read regexp as a string using the regexp history and some useful defaults. 579 "Read and return a regular expression as a string.
579Prompt for a regular expression with PROMPT (without a colon and 580When PROMPT doesn't end with a colon and space, it adds a final \": \".
580space) in the minibuffer. The optional argument DEFAULT-VALUE 581If DEFAULTS is non-nil, it displays the first default in the prompt.
581provides the value to display in the minibuffer prompt that is 582
582returned if the user just types RET. 583Non-nil optional arg DEFAULTS is a string or a list of strings that
583Values available via M-n are the string at point, the last isearch 584are prepended to a list of standard default values, which include the
584regexp, the last isearch string, and the last replacement regexp." 585string at point, the last isearch regexp, the last isearch string, and
585 (let* ((defaults 586the last replacement regexp.
586 (list (regexp-quote 587
587 (or (funcall (or find-tag-default-function 588Non-nil HISTORY is a symbol to use for the history list.
588 (get major-mode 'find-tag-default-function) 589If HISTORY is nil, `regexp-history' is used."
589 'find-tag-default)) 590 (let* ((default (if (consp defaults) (car defaults) defaults))
590 "")) 591 (defaults
591 (car regexp-search-ring) 592 (append
592 (regexp-quote (or (car search-ring) "")) 593 (if (listp defaults) defaults (list defaults))
593 (car (symbol-value 594 (list (regexp-quote
594 query-replace-from-history-variable)))) 595 (or (funcall (or find-tag-default-function
596 (get major-mode 'find-tag-default-function)
597 'find-tag-default))
598 ""))
599 (car regexp-search-ring)
600 (regexp-quote (or (car search-ring) ""))
601 (car (symbol-value
602 query-replace-from-history-variable)))))
595 (defaults (delete-dups (delq nil (delete "" defaults)))) 603 (defaults (delete-dups (delq nil (delete "" defaults))))
596 ;; Don't add automatically the car of defaults for empty input 604 ;; Do not automatically add default to the history for empty input.
597 (history-add-new-input nil) 605 (history-add-new-input nil)
598 (input 606 (input (read-from-minibuffer
599 (read-from-minibuffer 607 (cond ((string-match-p ":[ \t]*\\'" prompt)
600 (if default-value 608 prompt)
601 (format "%s (default %s): " prompt 609 (default
602 (query-replace-descr default-value)) 610 (format "%s (default %s): " prompt
603 (format "%s: " prompt)) 611 (query-replace-descr default)))
604 nil nil nil 'regexp-history defaults t))) 612 (t
613 (format "%s: " prompt)))
614 nil nil nil (or history 'regexp-history) defaults t)))
605 (if (equal input "") 615 (if (equal input "")
606 (or default-value input) 616 (or default input)
607 (prog1 input 617 (prog1 input
608 (add-to-history 'regexp-history input))))) 618 (add-to-history (or history 'regexp-history) input)))))
609 619
610 620
611(defalias 'delete-non-matching-lines 'keep-lines) 621(defalias 'delete-non-matching-lines 'keep-lines)
@@ -1130,9 +1140,9 @@ which means to discard all text properties."
1130 "\\&" 1140 "\\&"
1131 ;; Get the regexp for collection pattern. 1141 ;; Get the regexp for collection pattern.
1132 (let ((default (car occur-collect-regexp-history))) 1142 (let ((default (car occur-collect-regexp-history)))
1133 (read-string 1143 (read-regexp
1134 (format "Regexp to collect (default %s): " default) 1144 (format "Regexp to collect (default %s): " default)
1135 nil 'occur-collect-regexp-history default))) 1145 default 'occur-collect-regexp-history)))
1136 ;; Otherwise normal occur takes numerical prefix argument. 1146 ;; Otherwise normal occur takes numerical prefix argument.
1137 (when current-prefix-arg 1147 (when current-prefix-arg
1138 (prefix-numeric-value current-prefix-arg)))))) 1148 (prefix-numeric-value current-prefix-arg))))))
@@ -1219,14 +1229,10 @@ See also `multi-occur'."
1219 (cons 1229 (cons
1220 (let* ((default (car regexp-history)) 1230 (let* ((default (car regexp-history))
1221 (input 1231 (input
1222 (read-from-minibuffer 1232 (read-regexp
1223 (if current-prefix-arg 1233 (if current-prefix-arg
1224 "List lines in buffers whose names match regexp: " 1234 "List lines in buffers whose names match regexp: "
1225 "List lines in buffers whose filenames match regexp: ") 1235 "List lines in buffers whose filenames match regexp: "))))
1226 nil
1227 nil
1228 nil
1229 'regexp-history)))
1230 (if (equal input "") 1236 (if (equal input "")
1231 default 1237 default
1232 input)) 1238 input))