From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#38354: 27.0.50; Implement display action display-buffer-in-tab Date: Wed, 27 Nov 2019 00:43:56 +0200 Organization: LINKOV.NET Message-ID: <8736ea5kcz.fsf@mail.linkov.net> References: <87imna2nsi.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="102067"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 38354@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 26 23:58:36 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iZjn1-000QRS-Lr for geb-bug-gnu-emacs@m.gmane.org; Tue, 26 Nov 2019 23:58:36 +0100 Original-Received: from localhost ([::1]:59888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZjn0-0002sO-Hs for geb-bug-gnu-emacs@m.gmane.org; Tue, 26 Nov 2019 17:58:34 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZjmX-0002r8-Iv for bug-gnu-emacs@gnu.org; Tue, 26 Nov 2019 17:58:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iZjmV-00035y-GW for bug-gnu-emacs@gnu.org; Tue, 26 Nov 2019 17:58:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47182) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iZjmU-00034a-Gm for bug-gnu-emacs@gnu.org; Tue, 26 Nov 2019 17:58:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iZjmU-0007md-8t for bug-gnu-emacs@gnu.org; Tue, 26 Nov 2019 17:58:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 Nov 2019 22:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38354 X-GNU-PR-Package: emacs Original-Received: via spool by 38354-submit@debbugs.gnu.org id=B38354.157480902629815 (code B ref 38354); Tue, 26 Nov 2019 22:58:02 +0000 Original-Received: (at 38354) by debbugs.gnu.org; 26 Nov 2019 22:57:06 +0000 Original-Received: from localhost ([127.0.0.1]:53148 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iZjlZ-0007kp-Ns for submit@debbugs.gnu.org; Tue, 26 Nov 2019 17:57:06 -0500 Original-Received: from dragonfly.birch.relay.mailchannels.net ([23.83.209.51]:29785) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iZjlX-0007kg-Ja for 38354@debbugs.gnu.org; Tue, 26 Nov 2019 17:57:04 -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 1D9AB3C0C2E; Tue, 26 Nov 2019 22:57:02 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a82.g.dreamhost.com (100-96-4-107.trex.outbound.svc.cluster.local [100.96.4.107]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 891FE3C0B25; Tue, 26 Nov 2019 22:57:01 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a82.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); Tue, 26 Nov 2019 22:57:02 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Eight-Robust: 53fbbda90a647539_1574809021801_2780614693 X-MC-Loop-Signature: 1574809021801:525596005 X-MC-Ingress-Time: 1574809021801 Original-Received: from pdx1-sub0-mail-a82.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a82.g.dreamhost.com (Postfix) with ESMTP id 454947F1C8; Tue, 26 Nov 2019 14:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=gFoRAT2ZHMcaDUlTozzO5nYvetw=; b= RMFJYwxab1jy8gD66OVJ41eVIISMHMQ6jbKkVJk9/6y0ZbpGu79WBnuN13uQfNUg fLtJ81XX4skm5o2JLbZN5bInMWt06uoyIXiZylqUPE/BJXtbS3r2FcP1CHPfoX3x 0aH+4RqmXDM8cFGi3nbAgRspiHaMdywWaWPbG2/LXOc= Original-Received: from mail.jurta.org (m91-129-96-42.cust.tele2.ee [91.129.96.42]) (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-a82.g.dreamhost.com (Postfix) with ESMTPSA id A56CD7F1D1; Tue, 26 Nov 2019 14:56:54 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a82 In-Reply-To: (martin rudalics's message of "Tue, 26 Nov 2019 10:32:21 +0100") 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:172501 Archived-At: --=-=-= Content-Type: text/plain >> The only problem is that I don't know how to use matched numbered groups >> \1 from matches of buffer names in display conditions. >> >> display-buffer-assq-regexp uses string-match-p, not string-match. > > If you really need 'string-match', we have to save the match data. display-buffer-in-tab is implemented now, but we need also an action to display the buffer in an existing tab if such buffer is already displayed in it. I tried to copy an existing action that supports frames, but can't find such a frame action that would select another frame if the buffer is already is displayed in it. Does such frame action exist whose behavior could be copied to tabs? This will require a new function function tab-bar-buffer-visible-in-tabs. Also I use this function in a wrapper that kills the buffer, such wrapper checks (tab-bar-buffer-visible-in-tabs-p (current-buffer)) If true, it doesn't kill the buffer, but buries it. So switching back to that tab still displays the buffer. Another place where I use tab-bar-buffer-visible-in-tabs-p is to save Dired buffers to the desktop file only when the Dired buffer is displayed in a tab: (setq desktop-buffers-not-to-save-function (lambda (_filename bufname mode &rest _) (or (not (memq mode '(dired-mode vc-dir-mode))) (memq (get-buffer bufname) (mapcar #'window-buffer (window-list-1))) (tab-bar-buffer-visible-in-tabs-p (get-buffer bufname))))) This also required changes in desktop.el to support new predicate function desktop-buffers-not-to-save-function. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tab-bar-buffer-visible-in-tabs-p.patch diff --git a/lisp/window.el b/lisp/window.el index c750ea71ea..b46abd6ced 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -6231,6 +6231,17 @@ window-state-put (delete-window window)))) (window--check frame)))) +(defun window-state-buffers (state) + "Return all buffers saved to the given window state STATE." + (let ((buffer (cadr (assq 'buffer state))) + (buffers (mapcan (lambda (item) + (when (memq (car item) '(leaf vc hc)) + (window-state-buffers item))) + (if (consp (car state)) (list (cdr state)) (cdr state))))) + (if buffer + (cons (get-buffer buffer) buffers) + buffers))) + (defun window-swap-states (&optional window-1 window-2 size) "Swap the states of live windows WINDOW-1 and WINDOW-2. WINDOW-1 must specify a live window and defaults to the selected diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 5eb332884c..9c8c38fb83 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -1284,6 +1284,12 @@ display-buffer-in-tab (tab-bar-rename-tab name)))) (tab-bar-new-tab)))) +(defun tab-bar-buffer-visible-in-tabs-p (buffer) + "Return non-nil when BUFFER is visible in other tabs." + (seq-some (lambda (tab) + (memq buffer (window-state-buffers (cdr (assq 'ws tab))))) + (funcall tab-bar-tabs-function))) + (defun switch-to-buffer-other-tab (buffer-or-name &optional norecord) "Switch to buffer BUFFER-OR-NAME in another tab. diff --git a/lisp/desktop.el b/lisp/desktop.el index 498f769bd3..6f45278218 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el @@ -946,7 +946,9 @@ desktop-outvar ")\n")))) ;; ---------------------------------------------------------------------------- -(defun desktop-save-buffer-p (filename bufname mode &rest _dummy) +(defvar desktop-buffers-not-to-save-function nil) + +(defun desktop-save-buffer-p (filename bufname mode &rest rest) "Return t if buffer should have its state saved in the desktop file. FILENAME is the visited file name, BUFNAME is the buffer name, and MODE is the major mode. @@ -970,6 +972,9 @@ desktop-save-buffer-p (and (null filename) (null dired-skip) ; bug#5755 (with-current-buffer bufname desktop-save-buffer))) + (or (null desktop-buffers-not-to-save-function) + (funcall desktop-buffers-not-to-save-function + filename bufname mode rest)) t))) ;; ---------------------------------------------------------------------------- --=-=-=--