From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#39446: 28.0.50; Use quit-restore-window to close tab Date: Wed, 05 Feb 2020 23:53:13 +0200 Organization: LINKOV.NET Message-ID: <87wo90emmm.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="62478"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) To: 39446@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 05 23:42:14 2020 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 1izTN8-000G8C-KY for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Feb 2020 23:42:14 +0100 Original-Received: from localhost ([::1]:57848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izTN7-0006cA-Lu for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Feb 2020 17:42:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56439) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izTMy-0006bt-Mw for bug-gnu-emacs@gnu.org; Wed, 05 Feb 2020 17:42:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1izTMw-0005Gq-Uo for bug-gnu-emacs@gnu.org; Wed, 05 Feb 2020 17:42:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40951) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1izTMw-0005Fn-2B for bug-gnu-emacs@gnu.org; Wed, 05 Feb 2020 17:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1izTMv-000269-Up for bug-gnu-emacs@gnu.org; Wed, 05 Feb 2020 17:42:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Feb 2020 22:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 39446 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15809424637979 (code B ref -1); Wed, 05 Feb 2020 22:42:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Feb 2020 22:41:03 +0000 Original-Received: from localhost ([127.0.0.1]:46919 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1izTLz-00024b-2G for submit@debbugs.gnu.org; Wed, 05 Feb 2020 17:41:03 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:44851) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1izTLw-00023z-Kw for submit@debbugs.gnu.org; Wed, 05 Feb 2020 17:41:01 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55729) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izTLv-0006Vg-22 for bug-gnu-emacs@gnu.org; Wed, 05 Feb 2020 17:41:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1izTLt-00018h-EQ for bug-gnu-emacs@gnu.org; Wed, 05 Feb 2020 17:40:58 -0500 Original-Received: from black.elm.relay.mailchannels.net ([23.83.212.19]:7763) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1izTLs-00014J-Vv for bug-gnu-emacs@gnu.org; Wed, 05 Feb 2020 17:40:57 -0500 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 665401A1516 for ; Wed, 5 Feb 2020 22:40:54 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a97.g.dreamhost.com (100-96-206-172.trex.outbound.svc.cluster.local [100.96.206.172]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E9F061A150C for ; Wed, 5 Feb 2020 22:40:53 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a97.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.18.5); Wed, 05 Feb 2020 22:40:54 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Stop-Plucky: 0828b5c461372651_1580942454192_2845449410 X-MC-Loop-Signature: 1580942454192:1124801324 X-MC-Ingress-Time: 1580942454192 Original-Received: from pdx1-sub0-mail-a97.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a97.g.dreamhost.com (Postfix) with ESMTP id A0F737F0E0 for ; Wed, 5 Feb 2020 14:40:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to :subject:date:message-id:mime-version:content-type; s= linkov.net; bh=UZDjFueUyinRp1w2DyJSRh9iulA=; b=cA0sXU04rjTDsA7DV wynpc7vNbcBWiC4NM958xVb4qjDXkYGirlwh1hw/j686LDm/vNfQTABdHmuT9WeU EkOX6DOOo4mc036Be1Z5M8i4WuFdxI9GXs82D/KAN4DXEvbUnyp191NfPqJF+5Bn XefoLJVGy9mamt5bFRlSye6PDk= Original-Received: from mail.jurta.org (m91-129-105-126.cust.tele2.ee [91.129.105.126]) (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-a97.g.dreamhost.com (Postfix) with ESMTPSA id A3F047F108 for ; Wed, 5 Feb 2020 14:40:49 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a97 X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: 0 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrhedvgddtudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufhofffkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdehrdduvdeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepmhgrihhlrdhjuhhrthgrrdhorhhgpdhinhgvthepledurdduvdelrddutdehrdduvdeipdhrvghtuhhrnhdqphgrthhhpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhhrtghpthhtohepsghughdqghhnuhdqvghmrggtshesghhnuhdrohhrgh X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] 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: 209.51.188.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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:175716 Archived-At: --=-=-= Content-Type: text/plain Version: 28.0.50 Tags: patch The same way as quit-window deletes the frame when quitting the last window on the frame with e.g. C-x 5 d RET q this patch implements the same behavior for tabs: C-x t d RET q closes the tab. This is for master since it will take time to tweak. For example, it works fine everywhere except Gnus that doesn't call quit-window when exiting a summary buffer typing `q' (gnus-summary-exit) in a summary buffer that was automatically displayed in a new tab, so needed to customize Gnus by (add-hook 'gnus-summary-exit-hook 'quit-window) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=close-tab-quit-restore-window.patch diff --git a/lisp/window.el b/lisp/window.el index 40c4bf5ad4..bd825c09e1 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -5008,6 +5008,13 @@ quit-restore-window prev-buffer))) quad entry) (cond + ((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. + (when (window-live-p (nth 2 quit-restore)) + (select-window (nth 2 quit-restore)))) ((and (not prev-buffer) (or (eq (nth 1 quit-restore) 'frame) (and (eq (nth 1 quit-restore) 'window) @@ -6367,7 +6374,12 @@ display-buffer-record-window ;; WINDOW has been created on a new frame. (set-window-parameter window 'quit-restore - (list 'frame 'frame (selected-window) buffer))))) + (list 'frame 'frame (selected-window) buffer))) + ((eq type 'tab) + ;; WINDOW has been created on a new tab. + (set-window-parameter + window 'quit-restore + (list 'tab 'tab (selected-window) buffer))))) (defcustom display-buffer-function nil "If non-nil, function to call to handle `display-buffer'. @@ -7034,7 +7046,7 @@ window--display-buffer ;; use that. (display-buffer-mark-dedicated (set-window-dedicated-p window display-buffer-mark-dedicated)))) - (when (memq type '(window frame)) + (when (memq type '(window frame tab)) (set-window-prev-buffers window nil)) (let ((quit-restore (window-parameter window 'quit-restore)) (height (cdr (assq 'window-height alist))) diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index ebb0c566ad..d761000993 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -1480,26 +1479,55 @@ display-buffer-in-tab (tab-bar-select-tab (1+ index))) (when (get-buffer-window buffer frame) (select-window (get-buffer-window buffer frame)))) + (let ((tab-name (alist-get 'tab-name alist))) + (when (functionp tab-name) + (setq tab-name (funcall tab-name buffer alist))) + (if tab-name + (let ((tab-index (tab-bar--tab-index-by-name tab-name))) + (if tab-index + (progn + (tab-bar-select-tab (1+ tab-index)) + (when (get-buffer-window buffer) + (select-window (get-buffer-window buffer)))) + (display-buffer-in-new-tab buffer alist))) + (display-buffer-in-new-tab buffer alist)))))) + +(defun display-buffer-in-new-tab (buffer alist) + "Display BUFFER in a new tab. +ALIST is an association list of action symbols and values. See +Info node `(elisp) Buffer Display Action Alists' for details of +such alists. + +Like `display-buffer-in-tab', but always creates a new tab unconditionally, +without checking if a suitable tab already exists. + +If ALIST contains a `tab-name' entry, it creates a new tab with that name +and displays BUFFER in a new tab. The `tab-name' entry can be a function, +then it is called with two arguments: BUFFER and ALIST, and should return +the tab name. When a `tab-name' entry is omitted, create a new tab without +an explicit name. + +This is an action function for buffer display, see Info +node `(elisp) Buffer Display Action Functions'. It should be +called only by `display-buffer' or a function directly or +indirectly called by the latter." + (let ((tab-bar-new-tab-choice t)) + (tab-bar-new-tab) + (let ((tab-name (alist-get 'tab-name alist))) (when (functionp tab-name) (setq tab-name (funcall tab-name buffer alist))) - (if tab-name - (let ((tab-index (tab-bar--tab-index-by-name tab-name))) - (if tab-index - (tab-bar-select-tab (1+ tab-index)) - (let ((tab-bar-new-tab-choice t)) - (tab-bar-new-tab) - (tab-bar-rename-tab tab-name)))) - (let ((tab-bar-new-tab-choice t)) - (tab-bar-new-tab)))))) + (when tab-name + (tab-bar-rename-tab tab-name))) + (window--display-buffer buffer (selected-window) 'tab alist))) (defun switch-to-buffer-other-tab (buffer-or-name &optional norecord) "Switch to buffer BUFFER-OR-NAME in another tab. Like \\[switch-to-buffer-other-frame] (which see), but creates a new tab." (interactive (list (read-buffer-to-switch "Switch to buffer in other tab: "))) - (display-buffer buffer-or-name '((display-buffer-in-tab - display-buffer-same-window) - (inhibit-same-window . nil)) + (display-buffer buffer-or-name '((display-buffer-in-tab) + (inhibit-same-window . nil) + (reusable-frames . t)) norecord)) (defun find-file-other-tab (filename &optional wildcards) --=-=-=--