comparison lisp/replace.el @ 45079:bf76420e3297

(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.
author Colin Walters <walters@gnu.org>
date Thu, 02 May 2002 21:22:47 +0000
parents 829beb9a6a4b
children 2a245e4bdf59
comparison
equal deleted inserted replaced
45078:829beb9a6a4b 45079:bf76420e3297
443 (define-key map "\o" 'occur-mode-goto-occurrence-other-window) 443 (define-key map "\o" 'occur-mode-goto-occurrence-other-window)
444 (define-key map "\C-o" 'occur-mode-display-occurrence) 444 (define-key map "\C-o" 'occur-mode-display-occurrence)
445 (define-key map "\M-n" 'occur-next) 445 (define-key map "\M-n" 'occur-next)
446 (define-key map "\M-p" 'occur-prev) 446 (define-key map "\M-p" 'occur-prev)
447 (define-key map "g" 'revert-buffer) 447 (define-key map "g" 'revert-buffer)
448 (define-key map "q" 'delete-window)
448 map) 449 map)
449 "Keymap for `occur-mode'.") 450 "Keymap for `occur-mode'.")
450 451
451 (defvar occur-revert-arguments nil 452 (defvar occur-revert-arguments nil
452 "Arguments to pass to `occur-1' to revert an Occur mode buffer. 453 "Arguments to pass to `occur-1' to revert an Occur mode buffer.
677 (buffer-file-name buf))) 678 (buffer-file-name buf)))
678 buf)) 679 buf))
679 (buffer-list)))))) 680 (buffer-list))))))
680 681
681 (defun occur-1 (regexp nlines bufs) 682 (defun occur-1 (regexp nlines bufs)
682 (let ((occur-buf (get-buffer-create "*Occur*"))) 683 (let ((occur-buf (get-buffer-create "*Occur*"))
684 (made-temp-buf nil)
685 (active-bufs (delq nil (mapcar #'(lambda (buf)
686 (when (buffer-live-p buf) buf))
687 bufs))))
688 ;; Handle the case where one of the buffers we're searching is the
689 ;; *Occur* buffer itself.
690 (when (memq occur-buf bufs)
691 (setq occur-buf (with-current-buffer occur-buf
692 (clone-buffer "*Occur-temp*"))
693 made-temp-buf t))
683 (with-current-buffer occur-buf 694 (with-current-buffer occur-buf
684 (setq buffer-read-only nil) 695 (setq buffer-read-only nil)
685 (occur-mode) 696 (occur-mode)
686 (erase-buffer) 697 (erase-buffer)
687 (let ((count (occur-engine 698 (let ((count (occur-engine
688 regexp bufs occur-buf 699 regexp active-bufs occur-buf
689 (or nlines list-matching-lines-default-context-lines) 700 (or nlines list-matching-lines-default-context-lines)
690 (and case-fold-search 701 (and case-fold-search
691 (isearch-no-upper-case-p regexp t)) 702 (isearch-no-upper-case-p regexp t))
692 nil nil nil nil))) 703 nil nil nil nil)))
693 (message "Searched %d buffers; %s matches for `%s'" (length bufs) 704 (let* ((diff (- (length bufs) (length active-bufs)))
694 (if (zerop count) 705 (msg (concat
695 "no" 706 (format "Searched %d buffers" (- (length bufs) diff))
696 (format "%d" count)) 707 "%s; "
697 regexp) 708 (format "%s matches for `%s'"
709 (if (zerop count)
710 "no"
711 (format "%d" count))
712 regexp))))
713 (message msg (if (zerop diff)
714 ""
715 (format " (%d killed)" diff))))
716 ;; If we had to make a temporary buffer, make it the *Occur*
717 ;; buffer now.
718 (when made-temp-buf
719 (with-current-buffer (get-buffer "*Occur*")
720 (kill-this-buffer))
721 (rename-buffer "*Occur*"))
722 (setq occur-revert-arguments (list regexp nlines bufs)
723 buffer-read-only t)
698 (if (> count 0) 724 (if (> count 0)
699 (display-buffer occur-buf) 725 (display-buffer occur-buf)
700 (kill-buffer occur-buf))) 726 (kill-buffer occur-buf))))))
701 (setq occur-revert-arguments (list regexp nlines bufs)
702 buffer-read-only t))))
703 727
704 (defun occur-engine-add-prefix (lines) 728 (defun occur-engine-add-prefix (lines)
705 (mapcar 729 (mapcar
706 #'(lambda (line) 730 #'(lambda (line)
707 (concat " :" line "\n")) 731 (concat " :" line "\n"))