emacs-devel
[Top][All Lists]
Advanced

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

RE: view-mode exit hook?


From: Drew Adams
Subject: RE: view-mode exit hook?
Date: Tue, 18 Dec 2007 14:47:59 -0800

>  > 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?






reply via email to

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