summaryrefslogtreecommitdiff
path: root/lisp/tab-bar.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2019-11-27 00:29:31 +0200
committerJuri Linkov <juri@linkov.net>2019-11-27 00:29:31 +0200
commit6960a7543cef8cadc2cb9c20d3f21983ed71621a (patch)
treeae3ed690c4ca2fcec6a1acfefe6dd0132d98be02 /lisp/tab-bar.el
parentcffa5703b95fba3624dc54db5e693bae559eac5f (diff)
downloademacs-6960a7543cef8cadc2cb9c20d3f21983ed71621a.tar.gz
emacs-6960a7543cef8cadc2cb9c20d3f21983ed71621a.tar.bz2
emacs-6960a7543cef8cadc2cb9c20d3f21983ed71621a.zip
* lisp/tab-bar.el (display-buffer-in-tab): New function (bug#38354)
Diffstat (limited to 'lisp/tab-bar.el')
-rw-r--r--lisp/tab-bar.el30
1 files changed, 30 insertions, 0 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 69a26c515ec..5eb332884c5 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1255,6 +1255,36 @@ in the selected frame."
(tab-bar-list-select))
+(defun display-buffer-in-tab (buffer alist)
+ "Display BUFFER in a tab.
+ALIST is an association list of action symbols and values. See
+Info node `(elisp) Buffer Display Action Alists' for details of
+such alists.
+
+If ALIST contains a `name' entry, it creates a new tab with that name and
+displays BUFFER in a new tab. If a tab with this name already exists, it
+switches to that tab before displaying BUFFER. The `name' entry can be
+a function, then it is called with two arguments: BUFFER and ALIST, and
+should return the tab name. When a `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 ((name (cdr (assq 'name alist))))
+ (when (functionp name)
+ (setq name (funcall name buffer alist)))
+ (if name
+ (let ((tab-index (tab-bar--tab-index-by-name 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 name))))
+ (tab-bar-new-tab))))
+
+
(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."