[Top][All Lists]

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

Re: Window configurations

From: martin rudalics
Subject: Re: Window configurations
Date: Tue, 11 May 2010 09:01:59 +0200
User-agent: Thunderbird (Windows/20090302)

> Thinking more about this, I believe now this function should be
> like `view-mode-exit':

I had something like this in mind.  BTW, I have rewritten this code in
the meantime using a window parameter called `quit-restore'.  From a
preliminary description ...

   The `quit-restore' parameter tells how to proceed with a window when
the user "quits" it by invoking `quit-restore-window', see *Note
Displaying Buffers::.  The following non-`nil' values of this parameter
have a special meaning.

     This means to delete the associated window.  By default, `t' is
     used for a "temporary" window that was obtained by splitting an
     existing window.

     This means to delete the associated window's frame.  This value
     indicates that the associated windows was obtained by popping up a
     new frame showing just this window.  If the window is no more
     needed, it should be deleted together with the containing frame.

A list
     This option is useful when the associated window was borrowed to
     temporarily display some buffer and quitting shall "restore" the
     previous contents of the window.  The first three elements of the
     list must specify a buffer, a window start position, and a window
     point.  Quitting the window will then try to display the indicated
     buffer with the given start position and point in that window.

     The fourth element, if non-`nil', must denote a live buffer.  If
     specified, quitting will restore the previous window contents if
     and only if the buffer shown in the window is the buffer named by
     this element.

     The fifth element, if non-`nil', should specify the desired height
     of the window when its buffer is restored.  This value is applied
     if the buffer temporarily shown in the window was in
     `temp-buffer-resize-mode' to restore the original height of the

... and the description of `quit-restore-window' goes like ...

   The command described next allows to quit the window chosen by
`display-buffer' and restore the previous state without undoing changes
to the window configuration that happend _after_ `display-buffer' was
called.  A more drastic solution is to save the window configuration
before calling `display-buffer' and eventually restoring the saved
configuration, *Note Window Configurations::.  That solution sometimes
has the undesirable side-effect that all changes that happened after
the configuration was saved are undone too.

 -- Command: quit-restore-window &optional window kill
     This command "quits" WINDOW restoring its previous contents if
     possible.  The argument WINDOW must be a live window and defaults
     to the selected one.  This function always returns `nil'.

     According to information stored in WINDOW's `quit-restore' window
     parameter (*note Window Parameters::) this function performs one
     of the following actions.

        * Delete WINDOW and its frame.  This action is useful when
          WINDOW was created on a standalone frame and there are other
          frames left.

        * Delete WINDOW.  This action is usually taken when WINDOW was
          obtained by splitting some existing window.

        * Restore the buffer previously displayed in WINDOW.  This
          action is taken when WINDOW was temporarily reused for
          displaying some other buffer.

        * Make WINDOW display some other buffer.  This action is usually
          taken when the three preceding ones are not applicable.

     If its value was non-`nil', this function resets WINDOW's
     `quit-restore' parameter to `nil'.

     If the optional argument KILL is non-`nil', this means in addition
     kill WINDOW's buffer.  If KILL is `nil', this simply puts WINDOW's
     buffer at the end of the buffer list.  Interactively, KILL is the
     prefix argument.

... where `quit-restore-window' here replaces `quit-window' which has
too obscure semantics for my taste.  And obviously, exiting `view-mode'
calls `quit-restore-window' here too.

However, restoring a window configuration is a more primitive operation
than exiting `view-mode'.  One of the most hairy situation occurs when
you kill a buffer: There's a window of vulnerability when the
`kill-buffer' routine calls `replace_buffer_in_all_windows' and the
latter, for some reason, doesn't do what it has been told, for example,
because a `window-configuration-change-hook' shows the buffer to be
killed in some other window.  Obviously, doing things like that in a
configuration change hook is foolish as in

(get-buffer-create "*foo*")

(defun foo-lish ()
  (let (window-configuration-change-hook)
    (set-window-buffer (frame-first-window) "*foo*")))

(add-hook 'window-configuration-change-hook 'foo-lish)

and now doing (kill-buffer "*foo*").  But I'm not sure whether there are
useful things a `window-configuration-change-hook' could do along these


reply via email to

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