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#71386: 29.1; Frame is auto-deleted even when it has multiple tabs Date: Sun, 09 Jun 2024 19:59:29 +0300 Organization: LINKOV.NET Message-ID: <868qzehxie.fsf@mail.linkov.net> References: <86ikymipzx.fsf@gnu.org> <7269c7c4-86a1-44bf-8d5d-378c3584027a@gmx.at> <86zfrx8ec0.fsf@mail.linkov.net> <8561a63a-66d3-44cd-872f-73d26af7edbe@gmx.at> <86msnw4qm4.fsf@mail.linkov.net> <86y17gej2x.fsf@gnu.org> <86y17gmxdg.fsf@mail.linkov.net> 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="3695"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: rudalics@gmx.at, Eli Zaretskii , 71386@debbugs.gnu.org To: Al Haji-Ali Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 09 20:26:25 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 1sGNFI-0000nc-7r for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Jun 2024 20:26:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGNEm-0003z9-6Y; Sun, 09 Jun 2024 14:25:52 -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 1sGNEh-0003wn-Jn for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 14:25:47 -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 1sGNEh-0008Ga-Aq for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 14:25:47 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sGNEx-00080p-Qn for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 14:26:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Jun 2024 18:26:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71386 X-GNU-PR-Package: emacs Original-Received: via spool by 71386-submit@debbugs.gnu.org id=B71386.171795752730646 (code B ref 71386); Sun, 09 Jun 2024 18:26:03 +0000 Original-Received: (at 71386) by debbugs.gnu.org; 9 Jun 2024 18:25:27 +0000 Original-Received: from localhost ([127.0.0.1]:53372 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGNEN-0007y8-2G for submit@debbugs.gnu.org; Sun, 09 Jun 2024 14:25:27 -0400 Original-Received: from mslow1.mail.gandi.net ([217.70.178.240]:60899) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGMxt-0004Pw-9m for 71386@debbugs.gnu.org; Sun, 09 Jun 2024 14:08:25 -0400 Original-Received: from relay2-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::222]) by mslow1.mail.gandi.net (Postfix) with ESMTP id B8A96C5A31 for <71386@debbugs.gnu.org>; Sun, 9 Jun 2024 17:00:53 +0000 (UTC) Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 216C240005; Sun, 9 Jun 2024 17:00:31 +0000 (UTC) In-Reply-To: (Al Haji-Ali's message of "Fri, 07 Jun 2024 19:44:45 +0100") 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:286960 Archived-At: --=-=-= Content-Type: text/plain > If I may interject a bit, I think it would be better if the tab is > closed (i.e., tab-bar-close-tab is called) and another tab is > displayed when the dedicated buffer is killed if its the only one in > a window. Thanks, good suggestion. > For example, I changed `window--delete` on my machine to > have this > > (if (and tab-bar-mode > (> (length (tab-bar-tabs)) 1)) > (tab-bar-close-tab) > (delete-frame frame)) > > In your patch, `tab-bar-window-delete-frame-p` doesn't do that, nor > should it as it is a predicate. Maybe > `window-delete-frame-predicate-functions` should be renamed to > `window-delete-frame-actions` or something and `tab-bar-close-tab` > should be called in `tab-bar-window-delete-frame-p` (removing `-p` > probably) -- in fact, the `delete-frame` code itself could be added as > such an action, if we are not averse to changes to the interface. It should be sufficient to rename it to just 'window-delete-frame-functions'. Then it's not a predicate, and also follows the naming convention of hooks having the '-functions' suffix. > Also, just FYI, your patch doesn't allow the branches with > `auto-hide-function` and `frame-auto-hide-function` to be called when > `kill` is nil. I don't know the side-effects of not calling these > functions in such cases, but might be worth checking. Probably the frame should not be hidden after closing the tab, so these branches should not be handled. Ok, here is the patch that supports your initial case: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tab-bar-window-delete-frame.patch diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 6ab6324540e..485ea1d5dd0 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -2659,6 +2659,16 @@ tab-switcher-mouse-select (goto-char (posn-point (event-end event))) (tab-switcher-select)) + +(defun tab-bar-window-delete-frame (frame _kill) + "Whether FRAME should be deleted when other tabs are available for that frame. +Instead of deleting the frame, close the current tab. +Used via `window-delete-frame-predicate-functions' by `window--delete'." + (and tab-bar-mode (> (length (funcall tab-bar-tabs-function frame)) 1) + (progn (tab-bar-close-tab) t))) + +(add-hook 'window-delete-frame-functions #'tab-bar-window-delete-frame) + (defun tab-bar--reusable-frames (all-frames) (cond diff --git a/lisp/window.el b/lisp/window.el index 2208346ec8c..b1e877b82a8 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4968,6 +4968,11 @@ frame-auto-hide-function :group 'frames :version "26.1") +(defvar window-delete-frame-functions nil + "Don't delete frame when one of functions returns t. +Each of functions is called with two arguments: FRAME and KILL. +The function can perform an action instead of deleting the frame.") + (defun window--delete (&optional window dedicated-only kill) "Delete WINDOW if possible. WINDOW must be a live window and defaults to the selected one. @@ -4982,6 +4987,10 @@ window--delete ((eq deletable 'frame) (let ((frame (window-frame window))) (cond + ((run-hook-with-args-until-success + 'window-delete-frame-functions + frame kill) + nil) (kill (delete-frame frame)) ((functionp (frame-parameter frame 'auto-hide-function)) --=-=-=--