From 70ed2a76302d0c9b123c31db0d6439ae544a110a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 2 May 2002 21:22:56 +0000 Subject: [PATCH] (occur-mode-map): Bind "q" to `delete-window'. (occur-1): If one of the buffers we're searching is the *Occur* buffer itself, handle it by creating a temporary buffer. If any of the buffers being searched are killed, note that in the search result message. Also, set local variables before we possibly kill the buffer. --- lisp/ChangeLog | 9 +++++++++ lisp/replace.el | 44 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fcbf26fd828..42f5a361c47 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2002-05-02 Colin Walters + + * replace.el (occur-mode-map): Bind "q" to `delete-window'. + (occur-1): If one of the buffers we're searching is the *Occur* + buffer itself, handle it by creating a temporary buffer. If any + of the buffers being searched are killed, note that in the search + result message. Also, set local variables before we possibly kill + the buffer. + 2002-05-02 Kim F. Storm * menu-bar.el (menu-bar-make-toggle): Added optional PROPS arg. diff --git a/lisp/replace.el b/lisp/replace.el index e60f08f8f22..4294428c45e 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -445,6 +445,7 @@ end of the buffer." (define-key map "\M-n" 'occur-next) (define-key map "\M-p" 'occur-prev) (define-key map "g" 'revert-buffer) + (define-key map "q" 'delete-window) map) "Keymap for `occur-mode'.") @@ -679,27 +680,50 @@ See also `multi-occur'." (buffer-list)))))) (defun occur-1 (regexp nlines bufs) - (let ((occur-buf (get-buffer-create "*Occur*"))) + (let ((occur-buf (get-buffer-create "*Occur*")) + (made-temp-buf nil) + (active-bufs (delq nil (mapcar #'(lambda (buf) + (when (buffer-live-p buf) buf)) + bufs)))) + ;; Handle the case where one of the buffers we're searching is the + ;; *Occur* buffer itself. + (when (memq occur-buf bufs) + (setq occur-buf (with-current-buffer occur-buf + (clone-buffer "*Occur-temp*")) + made-temp-buf t)) (with-current-buffer occur-buf (setq buffer-read-only nil) (occur-mode) (erase-buffer) (let ((count (occur-engine - regexp bufs occur-buf + regexp active-bufs occur-buf (or nlines list-matching-lines-default-context-lines) (and case-fold-search (isearch-no-upper-case-p regexp t)) nil nil nil nil))) - (message "Searched %d buffers; %s matches for `%s'" (length bufs) - (if (zerop count) - "no" - (format "%d" count)) - regexp) + (let* ((diff (- (length bufs) (length active-bufs))) + (msg (concat + (format "Searched %d buffers" (- (length bufs) diff)) + "%s; " + (format "%s matches for `%s'" + (if (zerop count) + "no" + (format "%d" count)) + regexp)))) + (message msg (if (zerop diff) + "" + (format " (%d killed)" diff)))) + ;; If we had to make a temporary buffer, make it the *Occur* + ;; buffer now. + (when made-temp-buf + (with-current-buffer (get-buffer "*Occur*") + (kill-this-buffer)) + (rename-buffer "*Occur*")) + (setq occur-revert-arguments (list regexp nlines bufs) + buffer-read-only t) (if (> count 0) (display-buffer occur-buf) - (kill-buffer occur-buf))) - (setq occur-revert-arguments (list regexp nlines bufs) - buffer-read-only t)))) + (kill-buffer occur-buf)))))) (defun occur-engine-add-prefix (lines) (mapcar -- 2.39.5