From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#59862: quit-restore per window buffer Date: Thu, 10 Oct 2024 21:28:22 +0300 Organization: LINKOV.NET Message-ID: <86msjbyfqx.fsf@mail.linkov.net> References: <86fsds8mlm.fsf@mail.linkov.net> <86plsgrfvu.fsf@mail.linkov.net> <86le2b12ni.fsf@mail.linkov.net> <86y169kafb.fsf@mail.linkov.net> <61c4f245-3dd8-4e24-9c84-7ddd4cfe3c49@gmx.at> <86a5ioo269.fsf@mail.linkov.net> <867cdr3xs7.fsf@mail.linkov.net> <3f399d4f-3dd2-4624-b857-e198f70b5565@gmx.at> <86h6csct0w.fsf@mail.linkov.net> <38aedd8d-8966-44eb-afc0-79b4db412483@gmx.at> <86r0b9tqo3.fsf@mail.linkov.net> <22c18c89-b288-4c2e-83ae-11fd7cb1ec24@gmx.at> <86ed78w7t4.fsf@mail.linkov.net> <86msjefqfa.fsf@mail.linkov.net> <6272a373-1e7c-4df9-b0c2-e535ca3fe49b@gmx.at> <864j5ll110.fsf@mail.linkov.net> <9c103d92-c8f5-4fe7-934f-2f56219475b8@gmx.at> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5300"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: 59862@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 10 20:32:08 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1syxxG-0001CB-5U for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 10 Oct 2024 20:32:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syxx9-00012o-Rm; Thu, 10 Oct 2024 14:32:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syxx0-00012A-NY for bug-gnu-emacs@gnu.org; Thu, 10 Oct 2024 14:31:52 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1syxx0-0001oc-F4 for bug-gnu-emacs@gnu.org; Thu, 10 Oct 2024 14:31:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=/6aLnTt7MzUVmutJr2ZSNdqFX5gK0NlkUhFFlF8BpX0=; b=ikF7Xil/Le3Ju+zdLNidpj8ZSgHSwr4Zqw3DryzUlWA553R84l/oXNVOyq8b8UCTrUqtbV+/Lhu4Wp2vvJ1YzeZMEUoQ8MWsDGJLXp3R0glsRw0LwR/s1raULHKZHwSKo+6MPaD3PmmZZaV7TmyvohaKXSHwJwimwY8xdDG2SP6lFgUv1rtFSyVU7bzUHctt1BHovASg+N/sW7DRBLm+xRgLUhrsCIRYUm7ZGpdS+pJkjOloQbx6Ucy48zVf4Ns8psDdABBKFl4JtlUhzDG8QNYHKiLz/QF/4V3UafFZaXPbJHFT7nZoPf9tWol/uxXy4StqITYj3xQvyxLEIQAKgw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1syxxC-0001Iq-1m for bug-gnu-emacs@gnu.org; Thu, 10 Oct 2024 14:32: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: Thu, 10 Oct 2024 18:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59862 X-GNU-PR-Package: emacs Original-Received: via spool by 59862-submit@debbugs.gnu.org id=B59862.17285851104988 (code B ref 59862); Thu, 10 Oct 2024 18:32:02 +0000 Original-Received: (at 59862) by debbugs.gnu.org; 10 Oct 2024 18:31:50 +0000 Original-Received: from localhost ([127.0.0.1]:60546 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1syxwz-0001IN-8f for submit@debbugs.gnu.org; Thu, 10 Oct 2024 14:31:49 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:59289) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1syxwu-0001Hs-Mr for 59862@debbugs.gnu.org; Thu, 10 Oct 2024 14:31:45 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 217701C0002; Thu, 10 Oct 2024 18:31:04 +0000 (UTC) In-Reply-To: <9c103d92-c8f5-4fe7-934f-2f56219475b8@gmx.at> (martin rudalics's message of "Thu, 10 Oct 2024 16:54:02 +0200") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:293305 Archived-At: --=-=-= Content-Type: text/plain > > Because tabs have priority over frames. The precedence is: > > windows -> tabs -> frames. When there are many tabs > > then quit-restore-window should close tabs, and only > > on the last tab should delete the frame. This is bug#71386, > > but first need to finish bug#59862. > > So which bug are we discussing here? Bug#59862 or Bug#71386? I intended to finish first bug#59862, then to do bug#71386 later. But really they are closely related, so I fixed them both now and added corresponding references to bug numbers in comments. > >> I don't understand the problem yet. 'window-deletable-p' calls > >> 'frame-deletable-p' iff WINDOW is the root window of the frame. At this > >> time we can only either delete the frame or show another buffer in > >> WINDOW; tertium non datur. What am I missing? > > > > The third first-class citizen is the tab-bar. > > But I haven't written anything for the tab-bar code. This is something > you have to provide. Earlier you proposed So I extended this patch, and now all tests pass successfully with: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=quit-restore-tab.patch diff --git a/lisp/window.el b/lisp/window.el index 5822947f2fe..119de1eb38f 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4143,6 +4143,18 @@ window-deletable-p (let ((frame (window-frame window))) (cond + ((and tab-bar-mode + ;; Fall back to frame handling in case of less than 2 tabs + (> (length (funcall tab-bar-tabs-function frame)) 1) + ;; Close the tab with the initial window (bug#59862) + (or (eq (nth 1 (window-parameter window 'quit-restore)) 'tab) + ;; or with the dedicated window (bug#71386) + (window-dedicated-p window)) + ;; Don't close the tab if more windows were created explicitly + (< (seq-count (lambda (w) (window-parameter w 'quit-restore)) + (window-list-1 nil 'nomini)) + 2)) + 'tab) ((frame-root-window-p window) ;; WINDOW's frame can be deleted only if there are other frames ;; on the same terminal, and it does not contain the active @@ -4979,6 +4991,9 @@ window--delete (unless (and dedicated-only (not (window-dedicated-p window))) (let ((deletable (window-deletable-p window))) (cond + ((eq deletable 'tab) + (tab-bar-close-tab) + 'tab) ((eq deletable 'frame) (let ((frame (window-frame window))) (cond @@ -5340,13 +5355,7 @@ quit-restore-window ;; If the previously selected window is still alive, select it. (window--quit-restore-select-window quit-restore-2)) ((and (not prev-buffer) - (eq (nth 1 quit-restore) 'tab) - (eq (nth 3 quit-restore) buffer)) - (tab-bar-close-tab) - ;; If the previously selected window is still alive, select it. - (window--quit-restore-select-window quit-restore-2)) - ((and (not prev-buffer) - (or (eq (nth 1 quit-restore) 'frame) + (or (memq (nth 1 quit-restore) '(frame tab)) (and (eq (nth 1 quit-restore) 'window) ;; If the window has been created on an existing ;; frame and ended up as the sole window on that diff --git a/test/lisp/tab-bar-tests.el b/test/lisp/tab-bar-tests.el index aa8384b24e8..8e8e75ce720 100644 --- a/test/lisp/tab-bar-tests.el +++ b/test/lisp/tab-bar-tests.el @@ -42,10 +42,116 @@ tab-bar-tests-close-other-tabs (should (eq (length tab-bar-closed-tabs) 0))) (ert-deftest tab-bar-tests-close-other-tabs-default () - (tab-bar-tests-close-other-tabs nil)) + (tab-bar-tests-close-other-tabs nil) + ;; Clean up tabs afterwards + (tab-bar-tabs-set nil)) (ert-deftest tab-bar-tests-close-other-tabs-with-arg () - (dotimes (i 5) (tab-bar-tests-close-other-tabs i))) + (dotimes (i 5) (tab-bar-tests-close-other-tabs i)) + ;; Clean up tabs afterwards + (tab-bar-tabs-set nil)) + +(ert-deftest tab-bar-tests-quit-restore-window () + (let* ((frame-params (when noninteractive + '((window-system . nil) + (tty-type . "linux")))) + (pop-up-frame-alist frame-params) + (frame-auto-hide-function 'delete-frame)) + + ;; 1.1. 'quit-restore-window' should delete the frame + ;; from initial window (bug#59862) + (progn + (should (eq (length (frame-list)) 1)) + (other-frame-prefix) + (info) + (should (eq (length (frame-list)) 2)) + (should (equal (buffer-name) "*info*")) + (view-echo-area-messages) + (other-window 1) + (should (eq (length (window-list)) 2)) + (should (equal (buffer-name) "*Messages*")) + (quit-window) + (should (eq (length (window-list)) 1)) + (should (equal (buffer-name) "*info*")) + (quit-window) + (should (eq (length (frame-list)) 1))) + + ;; 1.2. 'quit-restore-window' should not delete the frame + ;; from non-initial window (bug#59862) + (progn + (should (eq (length (frame-list)) 1)) + (other-frame-prefix) + (info) + (should (eq (length (frame-list)) 2)) + (should (equal (buffer-name) "*info*")) + (view-echo-area-messages) + (should (eq (length (window-list)) 2)) + (should (equal (buffer-name) "*info*")) + (quit-window) + (should (eq (length (window-list)) 1)) + (should (eq (length (frame-list)) 2)) + (should (equal (buffer-name) "*Messages*")) + (quit-window) + (should (eq (length (frame-list)) 2)) + ;; Clean up the frame afterwards + (delete-frame)) + + ;; 2.1. 'quit-restore-window' should close the tab + ;; from initial window (bug#59862) + (progn + (should (eq (length (tab-bar-tabs)) 1)) + (other-tab-prefix) + (info) + (should (eq (length (tab-bar-tabs)) 2)) + (should (equal (buffer-name) "*info*")) + (view-echo-area-messages) + (other-window 1) + (should (eq (length (window-list)) 2)) + (should (equal (buffer-name) "*Messages*")) + (quit-window) + (should (eq (length (window-list)) 1)) + (should (equal (buffer-name) "*info*")) + (quit-window) + (should (eq (length (tab-bar-tabs)) 1))) + + ;; 2.2. 'quit-restore-window' should not close the tab + ;; from non-initial window (bug#59862) + (progn + (should (eq (length (tab-bar-tabs)) 1)) + (other-tab-prefix) + (info) + (should (eq (length (tab-bar-tabs)) 2)) + (should (equal (buffer-name) "*info*")) + (view-echo-area-messages) + (should (eq (length (window-list)) 2)) + (should (equal (buffer-name) "*info*")) + (quit-window) + (should (eq (length (window-list)) 1)) + (should (eq (length (tab-bar-tabs)) 2)) + (should (equal (buffer-name) "*Messages*")) + (quit-window) + (should (eq (length (tab-bar-tabs)) 2)) + ;; Clean up the tab afterwards + (tab-close)) + + ;; 3. Don't delete the frame with dedicated window + ;; from the second tab (bug#71386) + (with-selected-frame (make-frame frame-params) + (switch-to-buffer (generate-new-buffer "test1")) + (tab-new) + (switch-to-buffer (generate-new-buffer "test2")) + (set-window-dedicated-p (selected-window) t) + (kill-buffer) + (should (eq (length (frame-list)) 2)) + (should (eq (length (tab-bar-tabs)) 1)) + ;; But now should delete the frame with dedicated window + ;; from the last tab + (set-window-dedicated-p (selected-window) t) + (kill-buffer) + (should (eq (length (frame-list)) 1))) + + ;; Clean up tabs afterwards + (tab-bar-tabs-set nil))) (provide 'tab-bar-tests) ;;; tab-bar-tests.el ends here --=-=-=--