* 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
* Re: occur-mode-hook run too early to be useful
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
0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2002-08-28 14:30 UTC (permalink / raw)
Cc: emacs-devel
> 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'?
No.
> 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?
That would be wrong. The hook should be run at the end of the major mode's
function. Another way would be to call `occur-mode' later (which would
require the occur-revert-arguments variable to be made permanent-local)
or to provide another hook (like `occur-hook').
See edit-log-mode for an example where there is edit-log-mode-hook
and edit-log-hook.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
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:29 ` Kai Großjohann
0 siblings, 2 replies; 11+ messages in thread
From: Juanma Barranquero @ 2002-08-28 15:06 UTC (permalink / raw)
Cc: emacs-devel
On Wed, 28 Aug 2002 10:30:05 -0400, "Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> wrote:
> That would be wrong. The hook should be run at the end of the major mode's
> function.
Yes, sure. That's the normal way and that's why I asked.
But in this case things aren't that clear, as the distinction between
code in occur-mode and code in occur-1 seems rather arbitrary:
1. occur-mode is only called from occur-1
2. occur-mode is called unconditionally
3. occur-1 is the engine to all the interactive occur functions
4. M-x occur-mode in a non-occur buffer is meaningless
5. occur-mode-hook now serves almost no practical purpose
> Another way would be to call `occur-mode' later (which would
> require the occur-revert-arguments variable to be made permanent-local)
That just does credence to my idea that occur-mode is but an ugly
artifact.
> or to provide another hook (like `occur-hook').
Yeah, of course. But it feels a bit silly to have two hooks for almost
nothing. In fact, if I add an `occur-hook' I could move the call to
`turn-on-font-lock' to it and `occur-mode-hook' would be useless... Not
to mention that its docstring just says "Hooks run when `occur' is called.",
so it's difficult, from a user's POV, to see what purpose it serves that
occur-hook does not.
So I think that's what I'm going to do: changing occur-mode-hook to just
occur-hook and executing it at the end of occur-1.
Thanks for your comments,
/L/e/k/t/u
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
2002-08-28 15:06 ` Juanma Barranquero
@ 2002-08-28 15:11 ` Stefan Monnier
2002-08-28 15:25 ` Juanma Barranquero
2002-08-29 17:50 ` Richard Stallman
2002-08-28 15:29 ` Kai Großjohann
1 sibling, 2 replies; 11+ messages in thread
From: Stefan Monnier @ 2002-08-28 15:11 UTC (permalink / raw)
Cc: Stefan Monnier, emacs-devel
> On Wed, 28 Aug 2002 10:30:05 -0400, "Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> wrote:
>
> > That would be wrong. The hook should be run at the end of the major mode's
> > function.
>
> Yes, sure. That's the normal way and that's why I asked.
>
> But in this case things aren't that clear, as the distinction between
> code in occur-mode and code in occur-1 seems rather arbitrary:
>
> 1. occur-mode is only called from occur-1
No. `occur-mode' in an interactive function.
Oops, scratch that:
Yes, except that `occur-mode' should be an interactive function.
> 4. M-x occur-mode in a non-occur buffer is meaningless
Maybe you're right. But how about
M-x occur RET foo RET
...
M-x some-other-mode RET
...
M-x occur-mode RET
I switch major modes like that sometimes in order to get a particular
kind of font-lock highlighting, or some particular set of key-bindings.
I must admit that I'm not convinced it's very compelling in the case of
an occur buffer.
> So I think that's what I'm going to do: changing occur-mode-hook to just
> occur-hook and executing it at the end of occur-1.
That sounds good to me.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
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
1 sibling, 1 reply; 11+ messages in thread
From: Juanma Barranquero @ 2002-08-28 15:25 UTC (permalink / raw)
Cc: emacs-devel
On Wed, 28 Aug 2002 11:11:37 -0400, "Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> wrote:
> No. `occur-mode' in an interactive function.
> Oops, scratch that:
> Yes, except that `occur-mode' should be an interactive function.
:)
> Maybe you're right. But how about
>
> M-x occur RET foo RET
> ...
> M-x some-other-mode RET
> ...
> M-x occur-mode RET
You're right, I hadn't thought of that because I almost never do that
kind of thing.
> I switch major modes like that sometimes in order to get a particular
> kind of font-lock highlighting, or some particular set of key-bindings.
> I must admit that I'm not convinced it's very compelling in the case of
> an occur buffer.
Not only is not very compelling, it doesn't work right now with
occur-mode :)
(After adding an interactive declaration to occur-mode:)
M-x occur "whatever"
C-x o
M-x text-mode
M-x occur-mode
and the font-locking isn't right.
> That sounds good to me.
Great.
Thanks,
/L/e/k/t/u
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
2002-08-28 15:06 ` Juanma Barranquero
2002-08-28 15:11 ` Stefan Monnier
@ 2002-08-28 15:29 ` Kai Großjohann
2002-08-28 15:32 ` Stefan Monnier
1 sibling, 1 reply; 11+ messages in thread
From: Kai Großjohann @ 2002-08-28 15:29 UTC (permalink / raw)
Cc: Stefan Monnier, emacs-devel
Juanma Barranquero <lektu@terra.es> writes:
> But in this case things aren't that clear, as the distinction between
> code in occur-mode and code in occur-1 seems rather arbitrary:
>
> 1. occur-mode is only called from occur-1
> 2. occur-mode is called unconditionally
> 3. occur-1 is the engine to all the interactive occur functions
> 4. M-x occur-mode in a non-occur buffer is meaningless
> 5. occur-mode-hook now serves almost no practical purpose
How about making the distinction less arbitrary?
How about this: Rename occur-mode to occur-setup or occur-initialize
or occur-frobnicate, make a new function occur-mode which just sets up
keymaps and such stuff, call that function at the end of occur-1 and
run the hook from there. WDYT?
Caveat: I haven't even looked at the code!
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
2002-08-28 15:25 ` Juanma Barranquero
@ 2002-08-28 15:30 ` Juanma Barranquero
0 siblings, 0 replies; 11+ messages in thread
From: Juanma Barranquero @ 2002-08-28 15:30 UTC (permalink / raw)
Cc: emacs-devel
On Wed, 28 Aug 2002 17:25:56 +0200, I wrote:
> Not only is not very compelling, it doesn't work right now with
> occur-mode :)
>
> (After adding an interactive declaration to occur-mode:)
>
> M-x occur "whatever"
> C-x o
> M-x text-mode
> M-x occur-mode
>
> and the font-locking isn't right.
Oops, stupid me. That's not true. It's *me* who just broke that, by
taking 'turn-on-font-lock from the now-nonexistant `occur-mode-hook' and
putting it into `occur-hook'.
So: Is that use worth putting back occur-mode-hook and having two hooks?
/L/e/k/t/u
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
2002-08-28 15:29 ` Kai Großjohann
@ 2002-08-28 15:32 ` Stefan Monnier
2002-08-28 15:39 ` Kai Großjohann
0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2002-08-28 15:32 UTC (permalink / raw)
Cc: Juanma Barranquero, Stefan Monnier, emacs-devel
> How about this: Rename occur-mode to occur-setup or occur-initialize
> or occur-frobnicate, make a new function occur-mode which just sets up
> keymaps and such stuff, call that function at the end of occur-1 and
> run the hook from there. WDYT?
That's pretty much already what happens except for the `call at the end'
because occur sets up buffer-local variables which would be killed
by the `kill-all-local-variables', so it needs to setup the mode first
(or to mark them as temporary-local which might be the right thing
to do anyway for all I know).
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
2002-08-28 15:32 ` Stefan Monnier
@ 2002-08-28 15:39 ` Kai Großjohann
0 siblings, 0 replies; 11+ messages in thread
From: Kai Großjohann @ 2002-08-28 15:39 UTC (permalink / raw)
Cc: Juanma Barranquero, emacs-devel
"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> writes:
>> How about this: Rename occur-mode to occur-setup or occur-initialize
>> or occur-frobnicate, make a new function occur-mode which just sets up
>> keymaps and such stuff, call that function at the end of occur-1 and
>> run the hook from there. WDYT?
>
> That's pretty much already what happens except for the `call at the end'
> because occur sets up buffer-local variables which would be killed
> by the `kill-all-local-variables', so it needs to setup the mode first
> (or to mark them as temporary-local which might be the right thing
> to do anyway for all I know).
If you want to allow the user to say M-x occur-mode RET, then you
need to somehow handle the `occur-mode is called too late' case,
anyway. Whatever the solution, afterwards you can call occur-mode at
the end of occur-1 :-)
But the logic in occur-1 is really not obvious, so it might not be
easy to handle the too-late case...
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
2002-08-28 15:11 ` Stefan Monnier
2002-08-28 15:25 ` Juanma Barranquero
@ 2002-08-29 17:50 ` Richard Stallman
2002-08-30 2:14 ` Juanma Barranquero
1 sibling, 1 reply; 11+ messages in thread
From: Richard Stallman @ 2002-08-29 17:50 UTC (permalink / raw)
Cc: lektu, monnier+gnu/emacs, emacs-devel
> So I think that's what I'm going to do: changing occur-mode-hook to just
> occur-hook and executing it at the end of occur-1.
That sounds good to me.
It is ok to have an occur-hook which is run at that point.
However, occur-mode-hook should not be deleted. Every major mode
should run a mode hook.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: occur-mode-hook run too early to be useful
2002-08-29 17:50 ` Richard Stallman
@ 2002-08-30 2:14 ` Juanma Barranquero
0 siblings, 0 replies; 11+ messages in thread
From: Juanma Barranquero @ 2002-08-30 2:14 UTC (permalink / raw)
Cc: monnier+gnu/emacs, emacs-devel
> It is ok to have an occur-hook which is run at that point.
> However, occur-mode-hook should not be deleted. Every major mode
> should run a mode hook.
OK. Moreover, that fixes the small problem with font-locking in occur
buffers that I accidentally introduced.
--
Juanma Barranquero <lektu@terra.es>
^ 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).