unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: martin rudalics <rudalics@gmx.at>
Cc: 38354@debbugs.gnu.org
Subject: bug#38354: 27.0.50; Implement display action display-buffer-in-tab
Date: Wed, 27 Nov 2019 00:43:56 +0200	[thread overview]
Message-ID: <8736ea5kcz.fsf@mail.linkov.net> (raw)
In-Reply-To: <cc86d5bd-76fd-7a70-71b7-caa9bb4ad3c6@gmx.at> (martin rudalics's message of "Tue, 26 Nov 2019 10:32:21 +0100")

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: tab-bar-buffer-visible-in-tabs-p.patch --]
[-- Type: text/x-diff, Size: 2532 bytes --]

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

  parent reply	other threads:[~2019-11-26 22:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-23 23:09 bug#38354: 27.0.50; Implement display action display-buffer-in-tab Juri Linkov
2019-11-26  9:32 ` martin rudalics
2019-11-26 22:30   ` Juri Linkov
2019-11-26 22:43   ` Juri Linkov [this message]
2019-11-27  9:49     ` martin rudalics
2019-11-27 21:37       ` Juri Linkov
2019-11-28  9:20         ` martin rudalics
2019-11-28 23:02           ` Juri Linkov
2019-11-29  9:24             ` martin rudalics
2019-12-01 22:29               ` Juri Linkov
2019-12-02  9:40                 ` martin rudalics
2019-12-02 23:43                   ` Juri Linkov
2019-12-03  9:18                     ` martin rudalics
2019-12-03 23:36                       ` Juri Linkov
2019-12-04  9:22                         ` martin rudalics
2019-12-04 22:51                           ` Juri Linkov
2019-12-05  9:05                             ` martin rudalics
2019-12-05 23:54                               ` Juri Linkov
2019-12-06  7:37                                 ` martin rudalics
2022-12-06 17:40                                   ` Juri Linkov

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=8736ea5kcz.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=38354@debbugs.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).