bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#38354: 27.0.50; Implement display action display-buffer-in-tab


From: Juri Linkov
Subject: bug#38354: 27.0.50; Implement display action display-buffer-in-tab
Date: Wed, 27 Nov 2019 00:43:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu)

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

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)))
 
 ;; ----------------------------------------------------------------------------

reply via email to

[Prev in Thread] Current Thread [Next in Thread]