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 20:58:10 +0300 Organization: LINKOV.NET Message-ID: <86zfruc7qh.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> <868qzehxie.fsf@mail.linkov.net> <86msnu9fhg.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2944"; 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, abdo.haji.ali@gmail.com, 71386@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 09 20:26:17 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 1sGNFB-0000do-5h for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Jun 2024 20:26:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGNEl-0003yy-SU; Sun, 09 Jun 2024 14:25:51 -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-0003wQ-4c 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 1sGNEg-0008GS-SO for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 14:25:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sGNEx-00080h-C1 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.171795752730639 (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]:53367 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGNEL-0007xz-K8 for submit@debbugs.gnu.org; Sun, 09 Jun 2024 14:25:27 -0400 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:39959) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGMx0-0004N7-Un for 71386@debbugs.gnu.org; Sun, 09 Jun 2024 14:07:32 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id DD2AA1BF207; Sun, 9 Jun 2024 18:07:06 +0000 (UTC) In-Reply-To: <86msnu9fhg.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 09 Jun 2024 20:46:03 +0300") 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:286959 Archived-At: >> +(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. > > The first and the second sentences contradict each other. The first > implies that this is a predicate which returns a boolean, whereas the > second says that it closes the tab and negtlets to say anything about > the return value. > >> +(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.") > > This doc string should at least explain what is the KILL argument and > its meaning. I tried to improve these doc strings: diff --git a/lisp/window.el b/lisp/window.el index 2208346ec8c..e97557b5bb2 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4968,6 +4968,13 @@ frame-auto-hide-function :group 'frames :version "26.1") +(defvar window-delete-frame-functions nil + "A list of functions to handle the frame deletion. +Each of functions is called with two arguments: FRAME and KILL where +KILL means the buffer shown in window will be killed. When one of functions +returns a non-nil value then `window--delete' will not delete the frame. +The function can also perform own 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 +4989,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)) diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 6ab6324540e..2f7578b842b 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -2659,6 +2659,17 @@ tab-switcher-mouse-select (goto-char (posn-point (event-end event))) (tab-switcher-select)) + +(defun tab-bar-window-delete-frame (frame _kill) + "Handle frame deletion in `tab-bar-mode'. +When there are more than one tab on the selected frame, then close +the current tab. In this case return t to not delete the frame +in `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