unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* view-mode exit hook?
@ 2007-12-18 19:03 Drew Adams
  2007-12-18 21:52 ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2007-12-18 19:03 UTC (permalink / raw)
  To: Emacs-Devel; +Cc: rudalics

What is the recommended way to run some code when view-mode exits? For
entering view-mode, `view-mode-hook' can be used (it is run by
`view-mode-enable'), but I don't see anything equivalent for exiting. Are
users supposed to advise view-mode code (e.g. `view-mode-exit'), or is there
a better, recommended course of action?

My use case: When view-mode is entered, my own code fits the frame (assuming
it's one-window-p) to the viewed buffer. My tweaked version of
`display-buffer' takes care of that. But when view-mode is exited, the frame
is not re-fit to the buffer that is now displayed there. I'm looking for a
way to call my function `fit-frame', preferably via a hook run after
view-mode has exited and the other buffer is displayed in the frame, that
is, at the very end of `view-mode-exit'.

Even better, perhaps, would be for view-mode to restore the frame config
after it exits. That way, the frame would return to its prior state for the
buffer that was shown there previously. That is preferable for two reasons:
(1) no need to explicitly re-fit the buffer and (2) if the user had manually
resized the frame for the prior buffer, returning to that buffer would not
override the user's frame size preference by fitting it.

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

* Re: view-mode exit hook?
  2007-12-18 19:03 Drew Adams
@ 2007-12-18 21:52 ` martin rudalics
  2007-12-18 22:47   ` Drew Adams
  0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2007-12-18 21:52 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs-Devel

 > What is the recommended way to run some code when view-mode exits? For
 > entering view-mode, `view-mode-hook' can be used (it is run by
 > `view-mode-enable'), but I don't see anything equivalent for exiting. Are
 > users supposed to advise view-mode code (e.g. `view-mode-exit'), or is there
 > a better, recommended course of action?
 >
 > My use case: When view-mode is entered, my own code fits the frame (assuming
 > it's one-window-p) to the viewed buffer. My tweaked version of
 > `display-buffer' takes care of that. But when view-mode is exited, the frame
 > is not re-fit to the buffer that is now displayed there. I'm looking for a
 > way to call my function `fit-frame', preferably via a hook run after
 > view-mode has exited and the other buffer is displayed in the frame, that
 > is, at the very end of `view-mode-exit'.
 >
 > Even better, perhaps, would be for view-mode to restore the frame config
 > after it exits. That way, the frame would return to its prior state for the
 > buffer that was shown there previously. That is preferable for two reasons:
 > (1) no need to explicitly re-fit the buffer and (2) if the user had manually
 > resized the frame for the prior buffer, returning to that buffer would not
 > override the user's frame size preference by fitting it.

`view-mode-hook' is hardly suitable for observing window configuration
changes.  When `view-mode-hook' is called, the window used for viewing
might be already there or not exist yet.  `temp-buffer-setup-hook' seems
more useful here.  `view-mode-hook' could be used, however, to put a
function on `post-command-hook' which sets `view-exit-action'
appropriately.  Since `view-exit-action' is called before exiting
`view-mode' it could call `fit-frame'.

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

* RE: view-mode exit hook?
  2007-12-18 21:52 ` martin rudalics
@ 2007-12-18 22:47   ` Drew Adams
  2007-12-19  6:39     ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2007-12-18 22:47 UTC (permalink / raw)
  To: martin rudalics; +Cc: Emacs-Devel

>  > What is the recommended way to run some code when view-mode exits?
>  > For entering view-mode, `view-mode-hook' can be used (it is run by
>  > `view-mode-enable'), but I don't see anything equivalent for
>  > exiting. Are users supposed to advise view-mode code (e.g.
>  > `view-mode-exit'), or is there a better, recommended course of
>  > action?
>  >
>  > My use case: When view-mode is entered, my own code fits the
>  > frame (assuming it's one-window-p) to the viewed buffer. My
>  > tweaked version of `display-buffer' takes care of that. But
>  > when view-mode is exited, the frame is not re-fit to the
>  > buffer that is now displayed there. I'm looking for a way to
>  > call my function `fit-frame', preferably via a hook run after
>  > view-mode has exited and the other buffer is displayed in the
>  > frame, that is, at the very end of `view-mode-exit'.
>  >
>  > Even better, perhaps, would be for view-mode to restore the
>  > frame config after it exits. That way, the frame would return
>  > to its prior state for the buffer that was shown there
>  > previously. That is preferable for two reasons:
>  > (1) no need to explicitly re-fit the buffer and (2) if the
>  > user had manually resized the frame for the prior buffer,
>  > returning to that buffer would not override the user's frame
>  > size preference by fitting it.
>
> `view-mode-hook' is hardly suitable for observing window configuration
> changes.  When `view-mode-hook' is called, the window used for viewing
> might be already there or not exist yet.  `temp-buffer-setup-hook' seems
> more useful here.  `view-mode-hook' could be used, however, to put a
> function on `post-command-hook' which sets `view-exit-action'
> appropriately.  Since `view-exit-action' is called before exiting
> `view-mode' it could call `fit-frame'.

I wasn't suggesting to use `view-mode-hook'. As I noted, that is run only
upon entering the mode. I don't know whether view-mode manages to keep track
of window configs - I thought it did, but that's beside the point here. What
would be needed in this case would be restoring the frame config, not a
window config. _If_ that were feasible.

If the frame cannot be restored, I'm happy to deal with this by fitting the
frame again upon view-mode exit, even though that is less desirable for a
user than putting back the frame parameters s?he had before view-mode.

I don't want to go near `view-exit-action', if I can avoid it. That code is
far too complicated for a mortal such as I. I did think that I could
recuperate the current value of `view-exit-action' and then tack my function
call onto it, but that seems quite ugly. I'd sooner advise `view-mode-exit',
I think (and I don't like to use advice either).

I was looking for a simple and clean way to go, such as a hook.

Does it make sense for Emacs to have a `view-mode-exit-hook'?

What is the recommended approach in a situation such as mine?

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

* Re: view-mode exit hook?
  2007-12-18 22:47   ` Drew Adams
@ 2007-12-19  6:39     ` martin rudalics
  2007-12-19  7:24       ` Drew Adams
  0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2007-12-19  6:39 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs-Devel

> I wasn't suggesting to use `view-mode-hook'. As I noted, that is run only
> upon entering the mode. I don't know whether view-mode manages to keep track
> of window configs - I thought it did, but that's beside the point here. What
> would be needed in this case would be restoring the frame config, not a
> window config. _If_ that were feasible.

If you want to restore the frame configuration you have to save it first.
Where do you want to do that?  All I said was that `view-mode-hook' might
be the wrong place.

> If the frame cannot be restored, I'm happy to deal with this by fitting the
> frame again upon view-mode exit, even though that is less desirable for a
> user than putting back the frame parameters s?he had before view-mode.
> 
> I don't want to go near `view-exit-action', if I can avoid it. That code is
> far too complicated for a mortal such as I. I did think that I could
> recuperate the current value of `view-exit-action' and then tack my function
> call onto it, but that seems quite ugly. I'd sooner advise `view-mode-exit',
> I think (and I don't like to use advice either).
> 
> I was looking for a simple and clean way to go, such as a hook.
> 
> Does it make sense for Emacs to have a `view-mode-exit-hook'?

You can always think of `view-exit-action' as doing that.  For example,
there's no harm setting `view-exit-action' to a function that restores
a frame configuration saved earlier.  The question remains _which_ frame
configuration you want to restore.

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

* RE: view-mode exit hook?
  2007-12-19  6:39     ` martin rudalics
@ 2007-12-19  7:24       ` Drew Adams
  2008-01-06  0:33         ` Drew Adams
  0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2007-12-19  7:24 UTC (permalink / raw)
  To: martin rudalics; +Cc: Emacs-Devel

> > I wasn't suggesting to use `view-mode-hook'. As I noted, that
> > is run only upon entering the mode. I don't know whether
> > view-mode manages to keep track of window configs - I thought
> > it did, but that's beside the point here. What would be
> > needed in this case would be restoring the frame config, not
> > a window config. _If_ that were feasible.
>
> If you want to restore the frame configuration you have to save it first.
> Where do you want to do that?  All I said was that `view-mode-hook' might
> be the wrong place.

I don't want to save and restore it. I'm not trying to redesign view-mode.
If you have an idea for that, fine; I'm not proposing one.

I've said that I don't understand view-mode - especially its convoluted
attempts to deal with remembering past contexts, trying to restore the right
context in various scenarios, and all that. I won't get involved with that.
If someone who does understand all that and is interested in this issue
wants to tackle it to provide better behavior, fine. I'm not up to that
task.

I'm only asking a question about how users should deal with this kind of
thing, what might be the recommended practice in this case. That's all.

And, especially if there is no good answer (recommendation), I'm asking
whether we should perhaps have a `view-mode-exit-hook'. This last question
can make sense regardless of whether someone undertakes to make view-mode
always DTRT wrt final frame configuration (if a consensus could even be
reached about what that might mean).

> > If the frame cannot be restored, I'm happy to deal with this by
> > fitting the frame again upon view-mode exit, even though that is less
> > desirable for a user than putting back the frame parameters s?he had
> > before view-mode.
> >
> > I don't want to go near `view-exit-action', if I can avoid it.
> > That code is far too complicated for a mortal such as I. I did think
> > that I could recuperate the current value of `view-exit-action' and
> > then tack my function call onto it, but that seems quite ugly. I'd
> > sooner advise `view-mode-exit', I think (and I don't like to use
> > advice either).
> >
> > I was looking for a simple and clean way to go, such as a hook.
> >
> > Does it make sense for Emacs to have a `view-mode-exit-hook'?
>
> You can always think of `view-exit-action' as doing that.  For example,
> there's no harm setting `view-exit-action' to a function that restores
> a frame configuration saved earlier.  The question remains _which_ frame
> configuration you want to restore.

`view-exit-action' is not currently a no-op, AFAICT. So adding the feature
of fitting the frame would not simply be a matter of setting or binding
`view-exit-action' to a `fit-frame' function. It would instead mean _adding_
frame fitting to whatever `view-exit-action' might already be doing. And
that "whatever" is different, IIUC, depending on how view-mode is exited,
and even, I think, depending on how view-mode was entered. (Again, I don't
master that code, nor do I want to.)

`view-exit-action' is not simply a hook; it is more complex (and perhaps
more fragile). As I said, I can imagine tacking `fit-frame' onto whatever
`view-exit-action' does already, but I'd sooner advise `view-mode-exit'. And
neither of those prospects looks particularly appealing (clean) to me.

From what I've heard so far, there seems to be no recommended way to handle
this kind of thing. In that case, I ask again, shouldn't there be a
`view-mode-exit-hook'?

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

* RE: view-mode exit hook?
  2007-12-19  7:24       ` Drew Adams
@ 2008-01-06  0:33         ` Drew Adams
  0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2008-01-06  0:33 UTC (permalink / raw)
  To: Emacs-Devel

> > > Does it make sense for Emacs to have a `view-mode-exit-hook'?
> >
> > You can always think of `view-exit-action' as doing that.  For example,
> > there's no harm setting `view-exit-action' to a function that restores
> > a frame configuration saved earlier.  The question remains _which_ frame
> > configuration you want to restore.
>
> `view-exit-action' is not currently a no-op, AFAICT. So adding the feature
> of fitting the frame would not simply be a matter of setting or binding
> `view-exit-action' to a `fit-frame' function. It would instead
> mean _adding_ frame fitting to whatever `view-exit-action' might
> already be doing. And that "whatever" is different, IIUC, depending
> on how view-mode is exited, and even, I think, depending on how
> view-mode was entered. (Again, I don't master that code, nor do I want
> to.)
>
> `view-exit-action' is not simply a hook; it is more complex (and perhaps
> more fragile). As I said, I can imagine tacking `fit-frame' onto whatever
> `view-exit-action' does already, but I'd sooner advise
> `view-mode-exit'. And neither of those prospects looks particularly
> appealing (clean) to me.
>
> From what I've heard so far, there seems to be no recommended way
> to handle this kind of thing. In that case, I ask again, shouldn't
> there be a `view-mode-exit-hook'?

How about such a hook?

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

* FW: view-mode exit hook?
@ 2008-03-11 19:00 Drew Adams
  2008-08-04 15:03 ` Drew Adams
  0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2008-03-11 19:00 UTC (permalink / raw)
  To: 'Emacs-Devel'

Resending. 

Any arguments against adding such a hook? Argument for adding it is below. 

----------
From: Drew Adams Sent: Saturday, January 05, 2008 4:33 PM

> > > Does it make sense for Emacs to have a `view-mode-exit-hook'?
> >
> > You can always think of `view-exit-action' as doing that.  For example,
> > there's no harm setting `view-exit-action' to a function that restores
> > a frame configuration saved earlier.  The question remains _which_ frame
> > configuration you want to restore.
>
> `view-exit-action' is not currently a no-op, AFAICT. So adding the feature
> of fitting the frame would not simply be a matter of setting or binding
> `view-exit-action' to a `fit-frame' function. It would instead
> mean _adding_ frame fitting to whatever `view-exit-action' might
> already be doing. And that "whatever" is different, IIUC, depending
> on how view-mode is exited, and even, I think, depending on how
> view-mode was entered. (Again, I don't master that code, nor do I want
> to.)
>
> `view-exit-action' is not simply a hook; it is more complex (and perhaps
> more fragile). As I said, I can imagine tacking `fit-frame' onto whatever
> `view-exit-action' does already, but I'd sooner advise
> `view-mode-exit'. And neither of those prospects looks particularly
> appealing (clean) to me.
>
> From what I've heard so far, there seems to be no recommended way
> to handle this kind of thing. In that case, I ask again, shouldn't
> there be a `view-mode-exit-hook'?

How about such a hook?








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

* RE: view-mode exit hook?
  2008-03-11 19:00 FW: view-mode exit hook? Drew Adams
@ 2008-08-04 15:03 ` Drew Adams
  0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2008-08-04 15:03 UTC (permalink / raw)
  To: 'Emacs-Devel'

Resending.

> From: Drew Adams Sent: Tuesday, March 11, 2008 12:00 PM
> Resending. 
> 
> Any arguments against adding such a hook?
> Argument for adding it is below. 
> 
> ----------
> From: Drew Adams Sent: Saturday, January 05, 2008 4:33 PM
> 
> > > > Does it make sense for Emacs to have a `view-mode-exit-hook'?
> > >
> > > You can always think of `view-exit-action' as doing that. 
>  For example,
> > > there's no harm setting `view-exit-action' to a function 
> that restores
> > > a frame configuration saved earlier.  The question 
> remains _which_ frame
> > > configuration you want to restore.
> >
> > `view-exit-action' is not currently a no-op, AFAICT. So 
> adding the feature
> > of fitting the frame would not simply be a matter of 
> setting or binding
> > `view-exit-action' to a `fit-frame' function. It would instead
> > mean _adding_ frame fitting to whatever `view-exit-action' might
> > already be doing. And that "whatever" is different, IIUC, depending
> > on how view-mode is exited, and even, I think, depending on how
> > view-mode was entered. (Again, I don't master that code, 
> nor do I want
> > to.)
> >
> > `view-exit-action' is not simply a hook; it is more complex 
> (and perhaps
> > more fragile). As I said, I can imagine tacking `fit-frame' 
> onto whatever
> > `view-exit-action' does already, but I'd sooner advise
> > `view-mode-exit'. And neither of those prospects looks particularly
> > appealing (clean) to me.
> >
> > From what I've heard so far, there seems to be no recommended way
> > to handle this kind of thing. In that case, I ask again, shouldn't
> > there be a `view-mode-exit-hook'?
> 
> How about such a hook?









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

end of thread, other threads:[~2008-08-04 15:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-11 19:00 FW: view-mode exit hook? Drew Adams
2008-08-04 15:03 ` Drew Adams
  -- strict thread matches above, loose matches on Subject: below --
2007-12-18 19:03 Drew Adams
2007-12-18 21:52 ` martin rudalics
2007-12-18 22:47   ` Drew Adams
2007-12-19  6:39     ` martin rudalics
2007-12-19  7:24       ` Drew Adams
2008-01-06  0:33         ` Drew Adams

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