unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Al Haji-Ali <abdo.haji.ali@gmail.com>
Cc: rudalics@gmx.at, Eli Zaretskii <eliz@gnu.org>, 71386@debbugs.gnu.org
Subject: bug#71386: 29.1; Frame is auto-deleted even when it has multiple tabs
Date: Sun, 09 Jun 2024 19:59:29 +0300	[thread overview]
Message-ID: <868qzehxie.fsf@mail.linkov.net> (raw)
In-Reply-To: <m27cf0h9sy.fsf@gmail.com> (Al Haji-Ali's message of "Fri, 07 Jun 2024 19:44:45 +0100")

[-- Attachment #1: Type: text/plain, Size: 1497 bytes --]

> 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:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: tab-bar-window-delete-frame.patch --]
[-- Type: text/x-diff, Size: 1704 bytes --]

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))
 
+\f
+(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)
+
 \f
 (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))

  reply	other threads:[~2024-06-09 16:59 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05 23:44 bug#71386: 29.1; Frame is auto-deleted even when it has multiple tabs Al Haji-Ali
2024-06-06  5:45 ` Eli Zaretskii
2024-06-06  6:12   ` Juri Linkov
2024-06-06  9:20     ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-06 10:10     ` Eli Zaretskii
2024-06-06  9:19   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-07  6:39     ` Juri Linkov
2024-06-07  8:23       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-07 17:20         ` Juri Linkov
2024-06-07 17:52           ` Eli Zaretskii
2024-06-07 18:16             ` Juri Linkov
2024-06-07 18:44               ` Al Haji-Ali
2024-06-09 16:59                 ` Juri Linkov [this message]
2024-06-09 17:46                   ` Eli Zaretskii
2024-06-09 17:58                     ` Juri Linkov
2024-06-09 18:16                       ` Eli Zaretskii
2024-06-09 18:28                         ` Juri Linkov
2024-06-10  8:00                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-11  6:58                             ` Juri Linkov
2024-06-11 16:26                               ` Al Haji-Ali
2024-06-13  6:50                                 ` Juri Linkov
2024-06-12  8:57                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-13  6:53                                 ` Juri Linkov
2024-06-13  8:21                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-14  6:13                                     ` Juri Linkov
2024-06-14 17:46                                     ` Juri Linkov
2024-06-15  8:42                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-16  6:58                                         ` Juri Linkov
2024-06-16  7:52                                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-16 10:50                                             ` Al Haji-Ali
2024-06-17 14:47                                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-17 16:08                                                 ` Al Haji-Ali
2024-06-17 16:47                                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-17 17:01                                                     ` Al Haji-Ali
2024-06-18  9:52                                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-18 19:04                                                         ` Al Haji-Ali
2024-06-19  6:24                                                           ` Juri Linkov
2024-06-19  9:37                                                             ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-20  6:48                                                               ` Juri Linkov
2024-06-20  9:29                                                                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-16 16:45                                             ` Juri Linkov
2024-06-17  6:16                                               ` Juri Linkov
2024-06-17 14:47                                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-07 19:50               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=868qzehxie.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=71386@debbugs.gnu.org \
    --cc=abdo.haji.ali@gmail.com \
    --cc=eliz@gnu.org \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).