emacs-diffs
[Top][All Lists]
Advanced

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

master c4549d3 2/2: * lisp/tab-bar.el (tab-bar-new-tab-group): New defcu


From: Juri Linkov
Subject: master c4549d3 2/2: * lisp/tab-bar.el (tab-bar-new-tab-group): New defcustom.
Date: Mon, 15 Mar 2021 13:22:21 -0400 (EDT)

branch: master
commit c4549d3b37f7f3b9a9b5376eebb39b1929c48bd1
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/tab-bar.el (tab-bar-new-tab-group): New defcustom.
    
    (tab-bar--current-tab, tab-bar-new-tab-to, tab-bar-duplicate-tab): Use it.
---
 etc/NEWS        |  1 +
 lisp/tab-bar.el | 28 +++++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 01fd7af..18b1252 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -545,6 +545,7 @@ It also supports a negative argument.
 ---
 *** 'C-x t G' assigns a group name to the tab.
 'tab-close-group' can close all tabs that belong to the selected group.
+The option 'tab-bar-new-tab-group' defines the default group of a new tab.
 
 ---
 *** New user option 'tab-bar-tab-name-format-function'.
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 3cbdd52..a241127 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -327,6 +327,20 @@ before calling the command that adds a new tab."
   :group 'tab-bar
   :version "27.1")
 
+(defcustom tab-bar-new-tab-group nil
+  "Defines what group to assign to a new tab.
+If nil, don't set a default group automatically.
+If t, inherit the group name from the previous tab.
+If the value is a string, use it as the group name of a new tab.
+If the value is a function, call it with no arguments
+to get the group name."
+  :type '(choice (const    :tag "No automatic group" nil)
+                 (const    :tag "Inherit group from previous tab" t)
+                 (string   :tag "Fixed group name")
+                 (function :tag "Function that returns group name"))
+  :group 'tab-bar
+  :version "28.1")
+
 (defcustom tab-bar-new-button-show t
   "If non-nil, show the \"New tab\" button in the tab bar.
 When this is nil, you can create new tabs with \\[tab-new]."
@@ -751,7 +765,11 @@ on the tab bar instead."
   ;; inherits the current tab's `explicit-name' parameter.
   (let* ((tab (or tab (assq 'current-tab (frame-parameter frame 'tabs))))
          (tab-explicit-name (alist-get 'explicit-name tab))
-         (tab-group (alist-get 'group tab)))
+         (tab-group (if tab
+                        (alist-get 'group tab)
+                      (pcase tab-bar-new-tab-group
+                        ((pred stringp) tab-bar-new-tab-group)
+                        ((pred functionp) (funcall tab-bar-new-tab-group))))))
     `(current-tab
       (name . ,(if tab-explicit-name
                    (alist-get 'name tab)
@@ -1035,7 +1053,10 @@ After the tab is created, the hooks in
 
     (when from-index
       (setf (nth from-index tabs) from-tab))
-    (let* ((to-tab (tab-bar--current-tab))
+
+    (let* ((to-tab (tab-bar--current-tab
+                    (when (eq tab-bar-new-tab-group t)
+                      `((group . ,(alist-get 'group from-tab))))))
            (to-index (and to-index (prefix-numeric-value to-index)))
            (to-index (or (if to-index
                              (if (< to-index 0)
@@ -1090,7 +1111,8 @@ where argument addressing is absolute."
 If a negative ARG, duplicate the tab to ARG positions to the left.
 If ARG is zero, duplicate the tab in place of the current tab."
   (interactive "P")
-  (let ((tab-bar-new-tab-choice nil))
+  (let ((tab-bar-new-tab-choice nil)
+        (tab-bar-new-tab-group t))
     (tab-bar-new-tab arg)))
 
 



reply via email to

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