(query-replace-read-args): New optional arg NOERROR.
[bpt/emacs.git] / lisp / replace.el
index 71ec81b..0e5f05a 100644 (file)
@@ -1,6 +1,6 @@
 ;;; replace.el --- replace commands for Emacs
 
-;; Copyright (C) 1985, 86, 87, 92, 94, 96, 1997, 2000, 2001
+;; Copyright (C) 1985, 86, 87, 92, 94, 96, 1997, 2000, 2001, 2002
 ;;  Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
@@ -62,7 +62,9 @@ strings or patterns."
   :group 'matching
   :version "21.3")
 
-(defun query-replace-read-args (string regexp-flag)
+(defun query-replace-read-args (string regexp-flag &optional noerror)
+  (unless noerror
+    (barf-if-buffer-read-only))
   (let (from to)
     (if query-replace-interactive
        (setq from (car (if regexp-flag regexp-search-ring search-ring)))
@@ -152,8 +154,8 @@ If the result of TO-EXPR is not a string, it is converted to one using
 `prin1-to-string' with the NOESCAPE argument (which see).
 
 For convenience, when entering TO-EXPR interactively, you can use `\\&' or
-`\0' to stand for whatever matched the whole of REGEXP, and `\N' (where
-N is a digit) to stand for whatever matched the Nth `\(...\)' in REGEXP.
+`\\0' to stand for whatever matched the whole of REGEXP, and `\\N' (where
+N is a digit) to stand for whatever matched the Nth `\\(...\\)' in REGEXP.
 Use `\\#&' or `\\#N' if you want a number instead of a string.
 
 In Transient Mark mode, if the mark is active, operate on the contents
@@ -436,6 +438,8 @@ end of the buffer."
     (define-key map [mouse-2] 'occur-mode-mouse-goto)
     (define-key map "\C-c\C-c" 'occur-mode-goto-occurrence)
     (define-key map "\C-m" 'occur-mode-goto-occurrence)
+    (define-key map "\o" 'occur-mode-goto-occurrence-other-window)
+    (define-key map "\C-o" 'occur-mode-display-occurrence)
     (define-key map "\M-n" 'occur-next)
     (define-key map "\M-p" 'occur-prev)
     (define-key map "g" 'revert-buffer)
@@ -512,6 +516,26 @@ Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
     (pop-to-buffer occur-buffer)
     (goto-char (marker-position pos))))
 
+(defun occur-mode-goto-occurrence-other-window ()
+  "Go to the occurrence the current line describes, in another window."
+  (interactive)
+  (let ((pos (occur-mode-find-occurrence)))
+    (switch-to-buffer-other-window occur-buffer)
+    (goto-char (marker-position pos))))
+
+(defun occur-mode-display-occurrence ()
+  "Display in another window the occurrence the current line describes."
+  (interactive)
+  (let ((pos (occur-mode-find-occurrence))
+       same-window-buffer-names
+       same-window-regexps
+       window)
+    (setq window (display-buffer occur-buffer))
+    ;; This is the way to set point in the proper window.
+    (save-selected-window
+      (select-window window)
+      (goto-char (marker-position pos)))))
+
 (defun occur-next (&optional n)
   "Move to the Nth (default 1) next match in the *Occur* buffer."
   (interactive "p")
@@ -776,7 +800,7 @@ the matching is case-sensitive."
                  (add-text-properties
                   (marker-position text-beg) (- (marker-position text-end) 1)
                   '(mouse-face highlight
-                    help-echo "mouse-2: go to this occurence"))
+                    help-echo "mouse-2: go to this occurrence"))
                  (put-text-property (marker-position text-beg)
                                     (marker-position text-end)
                                     'occur occur-marker)
@@ -1105,7 +1129,9 @@ see the documentation of `replace-match' to find out how to simulate
                           (save-excursion
                             (funcall search-function search-string limit t)
                             (setq real-match-data (match-data)))
-                          (save-excursion (recursive-edit))
+                          (save-excursion
+                            (save-window-excursion
+                              (recursive-edit)))
                           (goto-char opos))
                         (set-match-data real-match-data)
                         ;; Before we make the replacement,