[Top][All Lists]

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

Re: Help with windows and 'quit-restore

From: martin rudalics
Subject: Re: Help with windows and 'quit-restore
Date: Wed, 01 Mar 2017 08:10:06 +0100

> I'm having a heck of a time understanding how the 'quit-restore window
> parameter actually works.
> I've got a pop-up window that goes into special-mode, and I'm trying to
> get the right level of control over both the window splitting, and the
> behavior of "q" (quit-window).
> First it was the "manual way":
> #+BEGIN_SRC elisp
> (let* ((buf (get-buffer-I-want-to-pop-up))
>        (window (get-window-I-want-to-split))
>        (buffer-window (split-window window 0.5

Do these 0.5 mean that you have advised ‘split-window’?

>                                     'right)))
>   (set-window-buffer buffer-window buf)
>   (display-buffer-record-window 'window buffer-window buf))
> The SIZE and SIDE args to `split-window' are calculated elsewhere, just
> hard-coded in my cut-down example. This allows me to split windows
> exactly as I want.
> This call to `display-buffer-record-window', however, does *not* set up
> the `quit-restore parameter correctly: when I hit "q" in the buffer, the
> buffer quits but the popped-up window remains, displaying some other
> buffer, usually a copy of a buffer that's already visible.

It does set up the ‘quit-restore’ parameter correctly.  The one missing
piece is that you didn't clear the new window's previous buffers by
doing something like

(let* ((buf (get-buffer-I-want-to-pop-up))
       (window (get-window-I-want-to-split))
       (buffer-window (split-window window 0.5
  (set-window-buffer buffer-window buf)
  (display-buffer-record-window 'window buffer-window buf)
  (set-window-prev-buffers buffer-window nil))

This is a technical issue I can't solve at a lower level: When Emacs
creates a new window, it first displays the buffer displayed in the
selected window in that new window and that buffer becomes the first
"previous" buffer of the new window.  So the new window ("buffer-window"
in your parlance) already showed a buffer _before_ it did show the
buffer you specify by `get-buffer-I-want-to-pop-up´.  In order to make
‘quit-window’ do what you mean, you have to clear that remembrance

I'll probably add a sentence about this to the doc-string of
‘display-buffer-record-window’ although there will be no warranty that
that function will always work outside the scope of ‘display-buffer’.


reply via email to

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