;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
:group 'matching)
(defcustom occur-hook nil
- "Hook run when `occur' is called."
+ "Hook run by Occur when there are any matches."
:type 'hook
:group 'matching)
(when current-prefix-arg
(prefix-numeric-value current-prefix-arg))))
-(defun occur-rename-buffer (&optional unique-p)
+(defun occur-rename-buffer (&optional unique-p interactive-p)
"Rename the current *Occur* buffer to *Occur: original-buffer-name*.
-Here `original-buffer-name' is the buffer name were occur was originally run.
-When given the prefix argument, the renaming will not clobber the existing
-buffer(s) of that name, but use `generate-new-buffer-name' instead.
-You can add this to `occur-mode-hook' if you always want a separate *Occur*
-buffer for each buffer where you invoke `occur'."
- (interactive "P")
+Here `original-buffer-name' is the buffer name were Occur was originally run.
+When given the prefix argument, or called non-interactively, the renaming
+will not clobber the existing buffer(s) of that name, but use
+`generate-new-buffer-name' instead. You can add this to `occur-hook'
+if you always want a separate *Occur* buffer for each buffer where you
+invoke `occur'."
+ (interactive "P\np")
(with-current-buffer
(if (eq major-mode 'occur-mode) (current-buffer) (get-buffer "*Occur*"))
(rename-buffer (concat "*Occur: "
(mapconcat #'buffer-name
(car (cddr occur-revert-arguments)) "/")
"*")
- unique-p)))
+ (or unique-p (not interactive-p)))))
(defun occur (regexp &optional nlines)
"Show all lines in the current buffer containing a match for REGEXP.
(if (= count 1) "" "es")
regexp))
(setq occur-revert-arguments (list regexp nlines bufs))
- (if (> count 0)
- (progn
- (display-buffer occur-buf)
- (setq next-error-last-buffer occur-buf)
- (setq buffer-read-only t)
- (set-buffer-modified-p nil))
- (kill-buffer occur-buf)))
- (run-hooks 'occur-hook)))))
+ (if (= count 0)
+ (kill-buffer occur-buf)
+ (display-buffer occur-buf)
+ (setq next-error-last-buffer occur-buf)
+ (setq buffer-read-only t)
+ (set-buffer-modified-p nil)
+ (run-hooks 'occur-hook)))))))
(defun occur-engine-add-prefix (lines)
(mapcar