]> code.delx.au - gnu-emacs/blobdiff - lisp/replace.el
*** empty log message ***
[gnu-emacs] / lisp / replace.el
index b38a8165720c4a838b4c70e3f1402ef448447a0c..07d5892e458ff635af3b1ae4036503c28c74b1dc 100644 (file)
   "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)
@@ -125,7 +144,7 @@ before rotating to the next."
               (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)
@@ -406,7 +425,8 @@ the matching is case-sensitive."
                              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
@@ -751,7 +771,7 @@ which will run faster and probably do exactly what you want."
                (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)
@@ -759,7 +779,7 @@ which will run faster and probably do exactly what you want."
              ;; 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.
@@ -768,7 +788,7 @@ which will run faster and probably do exactly what you want."
                (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.
@@ -793,7 +813,7 @@ which will run faster and probably do exactly what you want."
                             (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)
@@ -828,9 +848,11 @@ which will run faster and probably do exactly what you want."
                      ((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.
@@ -839,7 +861,7 @@ which will run faster and probably do exactly what you want."
                                                  (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))