;;; 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.
: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)))
`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
(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)
(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")
(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)
(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,