From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#32850: 27.0.50; window-swap-states doesn't swap window prev/next-buffers Date: Mon, 15 Oct 2018 23:48:36 +0300 Organization: LINKOV.NET Message-ID: <87ftx79brv.fsf@mail.linkov.net> References: <875zyrrhk8.fsf@mail.linkov.net> <5BAD2538.1060609@gmx.at> <871s9e1syw.fsf@mail.linkov.net> <5BB082A6.6040709@gmx.at> <87o9cepxfv.fsf@mail.linkov.net> <5BB1DC5D.2070903@gmx.at> <87ftxgqcx0.fsf@mail.linkov.net> <5BBC5C61.4090901@gmx.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1539638960 31455 195.159.176.226 (15 Oct 2018 21:29:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 15 Oct 2018 21:29:20 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 32850@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 15 23:29:16 2018 Return-path: Envelope-to: geb-bug-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 1gCAQN-00086H-Gm for geb-bug-gnu-emacs@m.gmane.org; Mon, 15 Oct 2018 23:29:15 +0200 Original-Received: from localhost ([::1]:54965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCASU-0004mO-25 for geb-bug-gnu-emacs@m.gmane.org; Mon, 15 Oct 2018 17:31:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCASD-0004jG-7d for bug-gnu-emacs@gnu.org; Mon, 15 Oct 2018 17:31:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCAS9-000586-SP for bug-gnu-emacs@gnu.org; Mon, 15 Oct 2018 17:31:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47302) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCAS6-000557-Fc for bug-gnu-emacs@gnu.org; Mon, 15 Oct 2018 17:31:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gCAS6-0005ET-Ee for bug-gnu-emacs@gnu.org; Mon, 15 Oct 2018 17:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Oct 2018 21:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32850 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32850-submit@debbugs.gnu.org id=B32850.153963905120076 (code B ref 32850); Mon, 15 Oct 2018 21:31:02 +0000 Original-Received: (at 32850) by debbugs.gnu.org; 15 Oct 2018 21:30:51 +0000 Original-Received: from localhost ([127.0.0.1]:51556 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gCARv-0005Dj-3E for submit@debbugs.gnu.org; Mon, 15 Oct 2018 17:30:51 -0400 Original-Received: from pop.dreamhost.com ([64.90.62.162]:41298 helo=pdx1-sub0-mail-a75.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gCARt-0005Dc-7z for 32850@debbugs.gnu.org; Mon, 15 Oct 2018 17:30:49 -0400 Original-Received: from pdx1-sub0-mail-a75.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a75.g.dreamhost.com (Postfix) with ESMTP id BE313805B6; Mon, 15 Oct 2018 14:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=Xy5d80PO/HWqbI5+G4dttCcjLVw=; b= KLUh3SSn6X2EeiaY0ZMbMfyhVKymEPKsP80wm0VP8SR6AM5s/hQ21PwJpb6Jp5wf yERtVh1RW0QX3bEhRpXvg1Olb/nFgiV/5KUDbsQQ/o1JLf0epsDnk7xwF8Y00Dib Giok75KYXYcIgxPtvtJmpffTdAzF2C999Pz5VVzzrl4= Original-Received: from localhost.linkov.net (m91-129-104-210.cust.tele2.ee [91.129.104.210]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a75.g.dreamhost.com (Postfix) with ESMTPSA id 55ADE805BB; Mon, 15 Oct 2018 14:30:46 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a75 In-Reply-To: <5BBC5C61.4090901@gmx.at> (martin rudalics's message of "Tue, 09 Oct 2018 09:44:33 +0200") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrvdelgdduvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffuohhfffgjkfgfgggtsehmtderredtredtnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecukfhppeeluddruddvledruddtgedrvddutdenucfrrghrrghmpehmohguvgepshhmthhppdhhvghloheplhhotggrlhhhohhsthdrlhhinhhkohhvrdhnvghtpdhinhgvthepledurdduvdelrddutdegrddvuddtpdhrvghtuhhrnhdqphgrthhhpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhhrtghpthhtoheprhhuuggrlhhitghssehgmhigrdgrthenucevlhhushhtvghrufhiiigvpedt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:151290 Archived-At: --=-=-= Content-Type: text/plain >> The root of the problem is not in window-swap-states, it's in >> window-state-get that it it relies upon. For a long time I have >> been using a package that keeps a list of window-configurations >> and switches between them in the same frame. But the problem >> is that we have no serialization for window-configurations, so >> no way to save in the desktop file and restore in another session. >> >> With the invention of window-state-get I tried to replace all calls >> of current-window-configuration with window-state-get (and >> set-window-configuration with window-state-put), and it worked >> perfectly (saved and restored serialized window-configurations >> in the desktop file), but still the problem that prevents its use >> is that it doesn't store prev/next-buffers that is a very important >> feature. > > Please provide a patch that makes the behavior you want optional. Are there cases where this behavior is undesirable? > I could try to come up with a patch myself but since you already have > coded such a thing why duplicate the efforts? IIUC we also have to > decide whether and how to expand your code to desktop saving and how > to handle buffers that got killed in between saving and restoring. This patch handles killed buffers, so it works for desktop saving as well (because the desktop restores the frameset only after it reads all buffers): --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=window-state-prev-next-buffers.1.patch diff --git a/lisp/window.el b/lisp/window.el index 0a42dae6ca..a41d7a6f3c 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -5541,6 +5541,10 @@ window--state-get-1 (t 'leaf))) (buffer (window-buffer window)) (selected (eq window (selected-window))) + (next-buffers (when (window-live-p window) + (window-next-buffers window))) + (prev-buffers (when (window-live-p window) + (window-prev-buffers window))) (head `(,type ,@(unless (window-next-sibling window) `((last . t))) @@ -5593,7 +5597,22 @@ window--state-get-1 (start . ,(if writable start (with-current-buffer buffer - (copy-marker start)))))))))) + (copy-marker start)))))))) + ,@(when next-buffers + `((next-buffers . ,(mapcar (lambda (buffer) + (buffer-name buffer)) + next-buffers)))) + ,@(when prev-buffers + `((prev-buffers . + ,(mapcar (lambda (entry) + (list (buffer-name (nth 0 entry)) + (if writable + (marker-position (nth 1 entry)) + (nth 1 entry)) + (if writable + (marker-position (nth 2 entry)) + (nth 2 entry)))) + prev-buffers)))))) (tail (when (memq type '(vc hc)) (let (list) @@ -5736,7 +5755,9 @@ window--state-put-2 (let ((window (car item)) (combination-limit (cdr (assq 'combination-limit item))) (parameters (cdr (assq 'parameters item))) - (state (cdr (assq 'buffer item)))) + (state (cdr (assq 'buffer item))) + (next-buffers (cdr (assq 'next-buffers item))) + (prev-buffers (cdr (assq 'prev-buffers item)))) (when combination-limit (set-window-combination-limit window combination-limit)) ;; Reset window's parameters and assign saved ones (we might want @@ -5748,7 +5769,8 @@ window--state-put-2 (set-window-parameter window (car parameter) (cdr parameter)))) ;; Process buffer related state. (when state - (let ((buffer (get-buffer (car state)))) + (let ((buffer (get-buffer (car state))) + (state (cdr state))) (if buffer (with-current-buffer buffer (set-window-buffer window buffer) @@ -5817,7 +5839,26 @@ window--state-put-2 (set-window-point window (cdr (assq 'point state)))) ;; Select window if it's the selected one. (when (cdr (assq 'selected state)) - (select-window window))) + (select-window window)) + (when next-buffers + (set-window-next-buffers + window + (delq nil (mapcar (lambda (buffer) + (setq buffer (get-buffer buffer)) + (when (buffer-live-p buffer) buffer)) + next-buffers)))) + (when prev-buffers + (set-window-prev-buffers + window + (delq nil (mapcar (lambda (entry) + (let ((buffer (get-buffer (nth 0 entry)))) + (when (buffer-live-p buffer) + (list buffer + (set-marker (make-marker) + (nth 1 entry) buffer) + (set-marker (make-marker) + (nth 2 entry) buffer))))) + prev-buffers))))) ;; We don't want to raise an error in case the buffer does ;; not exist anymore, so we switch to a previous one and ;; save the window with the intention of deleting it later --=-=-=--