]> code.delx.au - gnu-emacs/blobdiff - lisp/replace.el
Replace lisp-indent-hook with lisp-indent-function throughout.
[gnu-emacs] / lisp / replace.el
index 42480b656d6067ad028ceb69aadbc38c5a7095d6..d2a0370f93ea1ae14bc72b4eb9c140295e5d4eb5 100644 (file)
@@ -1,7 +1,7 @@
 ;;; replace.el --- replace commands for Emacs
 
 ;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1996, 1997, 2000, 2001, 2002,
-;;   2003, 2004  Free Software Foundation, Inc.
+;;   2003, 2004, 2005  Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 
@@ -115,8 +115,11 @@ wants to replace FROM with TO."
               query-replace-from-history-variable
               nil t t))))
       (if (and (zerop (length from)) lastto lastfrom)
-         (cons lastfrom
-               (query-replace-compile-replacement lastto regexp-flag))
+         (progn
+           (set query-replace-from-history-variable
+                (cdr (symbol-value query-replace-from-history-variable)))
+           (cons lastfrom
+                 (query-replace-compile-replacement lastto regexp-flag)))
        ;; Warn if user types \n or \t, but don't reject the input.
        (and regexp-flag
             (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
@@ -214,7 +217,11 @@ Fourth and fifth arg START and END specify the region to operate on.
 
 To customize possible responses, change the \"bindings\" in `query-replace-map'."
   (interactive (let ((common
-                     (query-replace-read-args "Query replace" nil)))
+                     (query-replace-read-args 
+                      (if (and transient-mark-mode mark-active)
+                        "Query replace in region"
+                        "Query replace")
+                        nil)))
                 (list (nth 0 common) (nth 1 common) (nth 2 common)
                       ;; These are done separately here
                       ;; so that command-history will record these expressions
@@ -274,7 +281,11 @@ text, TO-STRING is actually made a list instead of a string.
 Use \\[repeat-complex-command] after this command for details."
   (interactive
    (let ((common
-         (query-replace-read-args "Query replace regexp" t)))
+         (query-replace-read-args 
+          (if (and transient-mark-mode mark-active)
+              "Query replace regexp in region"
+            "Query replace regexp")
+          t)))
      (list (nth 0 common) (nth 1 common) (nth 2 common)
           ;; These are done separately here
           ;; so that command-history will record these expressions
@@ -420,7 +431,11 @@ which will run faster and will not set the mark or print anything.
 and TO-STRING is also null.)"
   (interactive
    (let ((common
-         (query-replace-read-args "Replace string" nil)))
+         (query-replace-read-args 
+          (if (and transient-mark-mode mark-active)
+              "Replace string in region"
+            "Replace string")
+          nil)))
      (list (nth 0 common) (nth 1 common) (nth 2 common)
           (if (and transient-mark-mode mark-active)
               (region-beginning))
@@ -474,7 +489,11 @@ What you probably want is a loop like this:
 which will run faster and will not set the mark or print anything."
   (interactive
    (let ((common
-         (query-replace-read-args "Replace regexp" t)))
+         (query-replace-read-args 
+          (if (and transient-mark-mode mark-active)
+              "Replace regexp in region" 
+            "Replace regexp") 
+          t)))
      (list (nth 0 common) (nth 1 common) (nth 2 common)
           (if (and transient-mark-mode mark-active)
               (region-beginning))
@@ -1435,7 +1454,8 @@ make, or the user didn't cancel the call."
                       query-replace-skip-read-only))
                  (unless (or literal noedit)
                    (replace-highlight (nth 0 real-match-data)
-                                      (nth 1 real-match-data)))
+                                      (nth 1 real-match-data)
+                                      start end))
                  (setq noedit
                        (replace-match-maybe-edit
                         next-replacement nocasify literal
@@ -1451,7 +1471,8 @@ make, or the user didn't cancel the call."
                ;; `real-match-data'.
                (while (not done)
                  (set-match-data real-match-data)
-                 (replace-highlight (match-beginning 0) (match-end 0))
+                 (replace-highlight (match-beginning 0) (match-end 0)
+                                    start end)
                  ;; Bind message-log-max so we don't fill up the message log
                  ;; with a bunch of identical messages.
                  (let ((message-log-max nil))
@@ -1627,15 +1648,15 @@ make, or the user didn't cancel the call."
 
 (defvar replace-overlay nil)
 
-(defun replace-highlight (beg end)
+(defun replace-highlight (match-beg match-end range-beg range-end)
   (if query-replace-highlight
       (if replace-overlay
-         (move-overlay replace-overlay beg end (current-buffer))
-       (setq replace-overlay (make-overlay beg end))
+         (move-overlay replace-overlay match-beg match-end (current-buffer))
+       (setq replace-overlay (make-overlay match-beg match-end))
        (overlay-put replace-overlay 'priority 1) ;higher than lazy overlays
        (overlay-put replace-overlay 'face 'query-replace)))
-  (if query-replace-lazy-highlight
-      (isearch-lazy-highlight-new-loop)))
+  (when query-replace-lazy-highlight
+    (isearch-lazy-highlight-new-loop range-beg range-end)))
 
 (defun replace-dehighlight ()
   (when replace-overlay