From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: Help with windows and 'quit-restore Date: Wed, 01 Mar 2017 08:09:55 -0800 Message-ID: <87wpc9dlm4.fsf@ericabrahamsen.net> References: <58B673CE.9030605@gmx.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1488384745 16349 195.159.176.226 (1 Mar 2017 16:12:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 1 Mar 2017 16:12:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 01 17:12:19 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cj6rR-0003eE-02 for geh-help-gnu-emacs@m.gmane.org; Wed, 01 Mar 2017 17:12:17 +0100 Original-Received: from localhost ([::1]:47401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj6rX-0002In-2x for geh-help-gnu-emacs@m.gmane.org; Wed, 01 Mar 2017 11:12:23 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj6pa-0001JY-ME for help-gnu-emacs@gnu.org; Wed, 01 Mar 2017 11:10:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cj6pX-0002Zi-AI for help-gnu-emacs@gnu.org; Wed, 01 Mar 2017 11:10:22 -0500 Original-Received: from [195.159.176.226] (port=58105 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cj6pX-0002ZE-3m for help-gnu-emacs@gnu.org; Wed, 01 Mar 2017 11:10:19 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cj6pH-0000pd-G2 for help-gnu-emacs@gnu.org; Wed, 01 Mar 2017 17:10:03 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 106 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:SZRrzbEn0f4OB/HTzJFp3U8r2kQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112405 Archived-At: martin rudalics 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