What you probably want is a loop like this:
(while (search-forward FROM-STRING nil t)
(replace-match TO-STRING nil t))
-which will run faster and will not set the mark or print anything."
+which will run faster and will not set the mark or print anything.
+\(You may need a more complex loop if FROM-STRING can match the null string
+and TO-STRING is also null.)"
(interactive (query-replace-read-args "Replace string" nil))
(perform-replace from-string to-string nil nil delimited))
(setq occur-mode-map (make-sparse-keymap))
(define-key occur-mode-map [mouse-2] 'occur-mode-mouse-goto)
(define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence)
- (define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence))
+ (define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence)
+ (define-key occur-mode-map "g" 'revert-buffer))
(defvar occur-buffer nil)
(defvar occur-nlines nil)
(defvar occur-pos-list nil)
+(defvar occur-command-arguments nil
+ "Arguments that were given to `occur' when it made this buffer.")
(defun occur-mode ()
"Major mode for output from \\[occur].
(use-local-map occur-mode-map)
(setq major-mode 'occur-mode)
(setq mode-name "Occur")
+ (make-local-variable 'revert-buffer-function)
+ (setq revert-buffer-function 'occur-revert-function)
(make-local-variable 'occur-buffer)
(make-local-variable 'occur-nlines)
(make-local-variable 'occur-pos-list)
+ (make-local-variable 'occur-command-arguments)
(run-hooks 'occur-mode-hook))
+;; Handle revert-buffer for *Occur* buffers.
+(defun occur-revert-function (ignore1 ignore2)
+ (let ((args occur-command-arguments ))
+ (save-excursion
+ (set-buffer occur-buffer)
+ (apply 'occur args))))
+
(defun occur-mode-mouse-goto (event)
"In Occur mode, go to the occurrence whose line you click on."
(interactive "e")
The lines are shown in a buffer named `*Occur*'.
It serves as a menu to find any of the occurrences in this buffer.
-\\[describe-mode] in that buffer will explain how."
+\\[describe-mode] in that buffer will explain how.
+
+If REGEXP contains upper case characters (excluding those preceded by
+\\), the matching is case-sensitive."
(interactive
(list (let* ((default (car regexp-history))
(input
(dir default-directory)
(linenum 1)
(prevpos (point-min))
+ (case-fold-search (and case-fold-search
+ (isearch-no-upper-case-p regexp t)))
(final-context-start (make-marker)))
;;; (save-excursion
;;; (beginning-of-line)
(occur-mode)
(setq occur-buffer buffer)
(setq occur-nlines nlines)
- (setq occur-pos-list ()))
+ (setq occur-pos-list ())
+ (setq occur-command-arguments
+ (list regexp nlines)))
(if (eq buffer standard-output)
(goto-char (point-max)))
(save-excursion
(insert-buffer-substring buffer start end)
(set-marker final-context-start
(- (point) (- end (match-end 0))))
- (backward-char (- end start))
+ (goto-char (- (point) (- end start)))
(setq tem nlines)
(while (> tem 0)
(insert empty ?:)