"Non-nil means `query-replace' uses the last search string.
That becomes the \"string to replace\".")
+(defcustom query-replace-from-history-variable 'query-replace-history
+ "History list to use for the FROM argument of query-replace commands.
+The value of this variable should be a symbol; that symbol
+is used as a variable to hold a history list for the strings
+or patterns to be replaced."
+ :group 'matching
+ :type 'symbol
+ :version "20.3")
+
+(defcustom query-replace-to-history-variable 'query-replace-history
+ "History list to use for the TO argument of query-replace commands.
+The value of this variable should be a symbol; that symbol
+is used as a variable to hold a history list for replacement
+strings or patterns."
+ :group 'matching
+ :type 'symbol
+ :version "20.3")
+
(defun query-replace-read-args (string regexp-flag)
(let (from to)
(if query-replace-interactive
(setq from (car (if regexp-flag regexp-search-ring search-ring)))
(setq from (read-from-minibuffer (format "%s: " string)
nil nil nil
- 'query-replace-history nil t)))
+ query-replace-from-history-variable
+ nil t)))
(setq to (read-from-minibuffer (format "%s %s with: " string from)
nil nil nil
- 'query-replace-history nil t))
+ query-replace-to-history-variable from t))
(list from to current-prefix-arg)))
(defun query-replace (from-string to-string &optional arg)
(format "Query replace %s with (space-separated strings): "
from)
nil nil nil
- 'query-replace-history nil t))
+ 'query-replace-history from t))
(list from to current-prefix-arg)))
(let (replacements)
(if (listp to-strings)
default)
"List lines matching regexp: ")
nil nil nil 'regexp-history default t)))
- (set-text-properties 0 (length input) nil input)
+ (and (equal input "") default
+ (setq input default))
input)
current-prefix-arg))
(let ((nlines (if nlines
(setq replacement-index (% (1+ replacement-index) (length replacements)))))
(if (not query-flag)
(progn
- (store-match-data real-match-data)
+ (set-match-data real-match-data)
(replace-match next-replacement nocasify literal)
(setq replace-count (1+ replace-count)))
(undo-boundary)
;; Loop reading commands until one of them sets done,
;; which means it has finished handling this occurrence.
(while (not done)
- (store-match-data real-match-data)
+ (set-match-data real-match-data)
(replace-highlight (match-beginning 0) (match-end 0))
;; Bind message-log-max so we don't fill up the message log
;; with a bunch of identical messages.
(setq key (read-event))
;; Necessary in case something happens during read-event
;; that clobbers the match data.
- (store-match-data real-match-data)
+ (set-match-data real-match-data)
(setq key (vector key))
(setq def (lookup-key map key))
;; Restore the match data while we process the command.
(goto-char (car elt))
(setq replaced (eq t (cdr elt)))
(or replaced
- (store-match-data (cdr elt)))
+ (set-match-data (cdr elt)))
(setq stack (cdr stack)))
(message "No previous match")
(ding 'no-terminate)
((eq def 'recenter)
(recenter nil))
((eq def 'edit)
- (store-match-data
- (prog1 (match-data)
- (save-excursion (recursive-edit))))
+ (goto-char (match-beginning 0))
+ (funcall search-function search-string limit t)
+ (setq real-match-data (match-data))
+ (save-excursion (recursive-edit))
+ (set-match-data real-match-data)
;; Before we make the replacement,
;; decide whether the search string
;; can match again just after this match.
(match-data)))))
((eq def 'delete-and-edit)
(delete-region (match-beginning 0) (match-end 0))
- (store-match-data
+ (set-match-data
(prog1 (match-data)
(save-excursion (recursive-edit))))
(setq replaced t))