unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* occur-mode-hook run too early to be useful
@ 2002-08-28  9:16 Juanma Barranquero
  2002-08-28 14:30 ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Juanma Barranquero @ 2002-08-28  9:16 UTC (permalink / raw)


From the doc of `occur-rename-buffer':

> 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'.

That's not true because occur-mode-hook is run too early. For example:


M-: (add-hook 'occur-mode-hook #'(lambda () (occur-rename-buffer t)))
C-h N
M-x occur "GNU/Linux"   ; Buffer is called "*Occur: *"
C-x 1
M-x occur "Unix"        ; Buffer is called "*Occur: *<2>"


instead of "*Occur: NEWS*" and "*Occur: NEWS*<2>". The reason is that
occur-1 runs occur-mode (and hence occur-mode-hook), erases the buffer,
and only then sets `occur-revert-arguments' (that `occur-rename-buffer'
needs).

The patch to fix that is trivial: just move the call to (run-hooks
'occur-mode-hook) from `occur-mode' to the end of `occur-1', and voilà.

As always, though, I have a philosophical question: should be
`occur-mode-hook' be run from any other place than `occur-mode'?

For normal major modes the answer is no, I suppose, but `occur-mode' is
a special mode, only called from inside `occur-1'. After `occur-mode'
runs, the buffer either has the old contents (that will be obliterated
immediately afterwards) or it is empty, so in fact running
`occur-mode-hook' at that moment is only useful for non-contents-related
hook functions. I want, for example, to resize the occur window after
doing M-x occur, and as it stands now it's not posible to do that through
`occur-mode-hook' (I'd have to revert to using defadvice, etc.).

So, it is OK to move the call to run-hooks to occur-1?


                                                           /L/e/k/t/u

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-08-30  2:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-28  9:16 occur-mode-hook run too early to be useful Juanma Barranquero
2002-08-28 14:30 ` Stefan Monnier
2002-08-28 15:06   ` Juanma Barranquero
2002-08-28 15:11     ` Stefan Monnier
2002-08-28 15:25       ` Juanma Barranquero
2002-08-28 15:30         ` Juanma Barranquero
2002-08-29 17:50       ` Richard Stallman
2002-08-30  2:14         ` Juanma Barranquero
2002-08-28 15:29     ` Kai Großjohann
2002-08-28 15:32       ` Stefan Monnier
2002-08-28 15:39         ` Kai Großjohann

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).