help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Help with windows and 'quit-restore


From: Eric Abrahamsen
Subject: Re: Help with windows and 'quit-restore
Date: Wed, 01 Mar 2017 08:09:55 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

martin rudalics <rudalics@gmx.at> writes:

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

No, the 0.5 and 'right were there just to simplify the example. This
buffer is popped up differently in different contexts and those values
are dynamically generated.

>>                                     'right)))
>>   (set-window-buffer buffer-window buf)
>>   (display-buffer-record-window 'window buffer-window buf))
>> #+END_SRC
>>
>> 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.  

I could have phrased that more accurately :)

> 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
>                                     'right)))
>   (set-window-buffer buffer-window buf)
>   (display-buffer-record-window 'window buffer-window buf)
>   (set-window-prev-buffers buffer-window nil))

Aha! Michael Heerdegen's previous reply also pointed me in this
direction. I will give this a shot.

> 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
> first.
>
> 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’.

Whatever the correct technical solution is, both the docs and the code
are pretty confusing. I think the key piece of missing information re
quit-restore is that, if there's a history of previously-displayed
buffers in this window, quitting the displayed buffer will display the
next buffer in the history. If there *isn't* such a history, quitting
the buffer will delete the window completely.

(Is that always true? Are there any other factors that influence this
behavior?)

It's a complicated topic, and probably hard to document. The Window
History section of the manual mentions previous buffers, but doesn't
mentioned the connection to quit-restore behavior.

In Quitting Windows, under the description of `quit-restore-window', it
says "If WINDOW was created specially for displaying its buffer, this
function deletes WINDOW..." When I was writing my functions I read that,
but didn't understand what "created specially" meant. My understanding
now is that that means there's no previous buffer history, but this
documentation makes it sound like this is something that happens at
window creation time, not something you can set later.

Lastly, the quit-restore description in Window Parameters says what the
parameter elements *are*, but (for the first two elements at least) not
what they *do*.

Those are three areas where I'd suggest tweaking the docs. I'd be happy
to provide specific suggestions or patches.

Lastly, as a shot in the dark, mightn't it make sense to allow
`display-buffer-record-window' to set the window history? The docstring
says the purpose of the function is to install or update the
quit-restore parameter -- wouldn't it make sense to let it set the
history part of the parameter, too?

Anyway, thanks very much for these tips! I'm sure I have enough
information to solve my problem now.

Eric




reply via email to

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