emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing occur-hook to occur-functions


From: Juanma Barranquero
Subject: Re: Changing occur-hook to occur-functions
Date: Tue, 5 Jul 2005 12:15:03 +0200

On 7/5/05, Juri Linkov <address@hidden> wrote:

> That's exactly what I tried.  With the latest CVS state
> 
> (add-hook 'occur-hook (lambda () (occur-rename-buffer t)))
> 
> renames the *Occur* buffer to `*Occur: original-buffer-name*', but
> 
> (add-hook 'occur-mode-hook (lambda () (occur-rename-buffer t)))
> 
> produces a name with empty original-buffer-name (i.e. just `*Occur: *'),
> because `occur-1' sets the value of `occur-revert-arguments'
> after running `occur-mode-hook', but before `occur-hook'.

Ah, very funny. I was right that originally changing the docstring was
a mistake (I know for sure, the mistake was mine :) And you're right,
as it now stands, it'd be better to advise the user to use
`occur-hook' and not `occur-mode-hook'.

> This would be good, but without adding original-buffer-name to the
> buffer name, to produce a unique buffer name, the user can simply put
> 
> (add-hook 'occur-mode-hook 'rename-uniquely)

Sure. But we really want the original buffer name. So the right fix is
to modify `occur-rename-buffer' to do the right thing in a hook, and
change back its docstring to recommend using `occur-hook'.

-- 
                    /L/e/k/t/u


Index: lisp/replace.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v
retrieving revision 1.218
diff -c -r1.218 replace.el
*** lisp/replace.el     4 Jul 2005 23:08:57 -0000       1.218
--- lisp/replace.el     5 Jul 2005 10:10:52 -0000
***************
*** 921,941 ****
        (when current-prefix-arg
          (prefix-numeric-value current-prefix-arg))))
  
! (defun occur-rename-buffer (&optional unique-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")
    (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)))
  
  (defun occur (regexp &optional nlines)
    "Show all lines in the current buffer containing a match for REGEXP.
--- 921,942 ----
        (when current-prefix-arg
          (prefix-numeric-value current-prefix-arg))))
  
! (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, 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)) "/")
                             "*")
!                    (or unique-p (not interactive-p)))))
  
  (defun occur (regexp &optional nlines)
    "Show all lines in the current buffer containing a match for REGEXP.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]