diff options
| author | Juri Linkov | 2021-03-10 19:57:48 +0200 |
|---|---|---|
| committer | Juri Linkov | 2021-03-10 19:57:48 +0200 |
| commit | 5fa2775c0cab746d49aa0bcc96ecdcff23a9ba05 (patch) | |
| tree | 5870747250f75d07b4691d0396165190a59e404a | |
| parent | 88409b21c23de13d0eac82f579cae9cc2f58d8b3 (diff) | |
| download | emacs-5fa2775c0cab746d49aa0bcc96ecdcff23a9ba05.tar.gz emacs-5fa2775c0cab746d49aa0bcc96ecdcff23a9ba05.zip | |
* lisp/tab-bar.el: 'C-x t G' (tab-group) assigns a group name to the tab.
* lisp/tab-bar.el (tab-bar--tab, tab-bar--current-tab): Add tab group if any.
(tab-bar-change-tab-group): New command.
(display-buffer-in-new-tab): Handle tab-group alist entry.
(tab-group): New alias.
(tab-prefix-map): Bind "G" to 'tab-group'.
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/tab-bar.el | 53 |
2 files changed, 54 insertions, 2 deletions
| @@ -541,6 +541,9 @@ It also supports a negative argument. | |||
| 541 | It also supports a negative argument. | 541 | It also supports a negative argument. |
| 542 | 542 | ||
| 543 | --- | 543 | --- |
| 544 | *** 'C-x t G' assigns a group name to the tab. | ||
| 545 | |||
| 546 | --- | ||
| 544 | *** New user option 'tab-bar-tab-name-format-function'. | 547 | *** New user option 'tab-bar-tab-name-format-function'. |
| 545 | 548 | ||
| 546 | --- | 549 | --- |
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 2f97bd4eaf9..bc89a114228 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el | |||
| @@ -648,6 +648,7 @@ on the tab bar instead." | |||
| 648 | (defun tab-bar--tab (&optional frame) | 648 | (defun tab-bar--tab (&optional frame) |
| 649 | (let* ((tab (assq 'current-tab (frame-parameter frame 'tabs))) | 649 | (let* ((tab (assq 'current-tab (frame-parameter frame 'tabs))) |
| 650 | (tab-explicit-name (alist-get 'explicit-name tab)) | 650 | (tab-explicit-name (alist-get 'explicit-name tab)) |
| 651 | (tab-group (alist-get 'group tab)) | ||
| 651 | (bl (seq-filter #'buffer-live-p (frame-parameter frame 'buffer-list))) | 652 | (bl (seq-filter #'buffer-live-p (frame-parameter frame 'buffer-list))) |
| 652 | (bbl (seq-filter #'buffer-live-p (frame-parameter frame 'buried-buffer-list)))) | 653 | (bbl (seq-filter #'buffer-live-p (frame-parameter frame 'buried-buffer-list)))) |
| 653 | `(tab | 654 | `(tab |
| @@ -655,6 +656,7 @@ on the tab bar instead." | |||
| 655 | (alist-get 'name tab) | 656 | (alist-get 'name tab) |
| 656 | (funcall tab-bar-tab-name-function))) | 657 | (funcall tab-bar-tab-name-function))) |
| 657 | (explicit-name . ,tab-explicit-name) | 658 | (explicit-name . ,tab-explicit-name) |
| 659 | ,@(if tab-group `((group . ,tab-group))) | ||
| 658 | (time . ,(float-time)) | 660 | (time . ,(float-time)) |
| 659 | (ws . ,(window-state-get | 661 | (ws . ,(window-state-get |
| 660 | (frame-root-window (or frame (selected-frame))) 'writable)) | 662 | (frame-root-window (or frame (selected-frame))) 'writable)) |
| @@ -670,12 +672,14 @@ on the tab bar instead." | |||
| 670 | ;; necessary when switching tabs, otherwise the destination tab | 672 | ;; necessary when switching tabs, otherwise the destination tab |
| 671 | ;; inherits the current tab's `explicit-name' parameter. | 673 | ;; inherits the current tab's `explicit-name' parameter. |
| 672 | (let* ((tab (or tab (assq 'current-tab (frame-parameter frame 'tabs)))) | 674 | (let* ((tab (or tab (assq 'current-tab (frame-parameter frame 'tabs)))) |
| 673 | (tab-explicit-name (alist-get 'explicit-name tab))) | 675 | (tab-explicit-name (alist-get 'explicit-name tab)) |
| 676 | (tab-group (alist-get 'group tab))) | ||
| 674 | `(current-tab | 677 | `(current-tab |
| 675 | (name . ,(if tab-explicit-name | 678 | (name . ,(if tab-explicit-name |
| 676 | (alist-get 'name tab) | 679 | (alist-get 'name tab) |
| 677 | (funcall tab-bar-tab-name-function))) | 680 | (funcall tab-bar-tab-name-function))) |
| 678 | (explicit-name . ,tab-explicit-name)))) | 681 | (explicit-name . ,tab-explicit-name) |
| 682 | ,@(if tab-group `((group . ,tab-group)))))) | ||
| 679 | 683 | ||
| 680 | (defun tab-bar--current-tab-index (&optional tabs frame) | 684 | (defun tab-bar--current-tab-index (&optional tabs frame) |
| 681 | (seq-position (or tabs (funcall tab-bar-tabs-function frame)) | 685 | (seq-position (or tabs (funcall tab-bar-tabs-function frame)) |
| @@ -1240,6 +1244,40 @@ function `tab-bar-tab-name-function'." | |||
| 1240 | (tab-bar-rename-tab new-name (1+ (tab-bar--tab-index-by-name tab-name)))) | 1244 | (tab-bar-rename-tab new-name (1+ (tab-bar--tab-index-by-name tab-name)))) |
| 1241 | 1245 | ||
| 1242 | 1246 | ||
| 1247 | ;;; Tab groups | ||
| 1248 | |||
| 1249 | (defun tab-bar-change-tab-group (group-name &optional arg) | ||
| 1250 | "Add the tab specified by its absolute position ARG to GROUP-NAME. | ||
| 1251 | If no ARG is specified, then set the GROUP-NAME for the current tab. | ||
| 1252 | ARG counts from 1. | ||
| 1253 | If GROUP-NAME is the empty string, then remove the tab from any group." | ||
| 1254 | (interactive | ||
| 1255 | (let* ((tabs (funcall tab-bar-tabs-function)) | ||
| 1256 | (tab-index (or current-prefix-arg (1+ (tab-bar--current-tab-index tabs)))) | ||
| 1257 | (group-name (alist-get 'group (nth (1- tab-index) tabs)))) | ||
| 1258 | (list (completing-read | ||
| 1259 | "Group name for tab (leave blank to remove group): " | ||
| 1260 | (delete-dups (delq nil (cons group-name | ||
| 1261 | (mapcar (lambda (tab) | ||
| 1262 | (alist-get 'group tab)) | ||
| 1263 | (funcall tab-bar-tabs-function)))))) | ||
| 1264 | current-prefix-arg))) | ||
| 1265 | (let* ((tabs (funcall tab-bar-tabs-function)) | ||
| 1266 | (tab-index (if arg | ||
| 1267 | (1- (max 0 (min arg (length tabs)))) | ||
| 1268 | (tab-bar--current-tab-index tabs))) | ||
| 1269 | (tab (nth tab-index tabs)) | ||
| 1270 | (group (assq 'group tab)) | ||
| 1271 | (group-new-name (and (> (length group-name) 0) group-name))) | ||
| 1272 | (if group | ||
| 1273 | (setcdr group group-new-name) | ||
| 1274 | (nconc tab `((group . ,group-new-name)))) | ||
| 1275 | |||
| 1276 | (force-mode-line-update) | ||
| 1277 | (unless tab-bar-mode | ||
| 1278 | (message "Set tab group to '%s'" group-new-name)))) | ||
| 1279 | |||
| 1280 | |||
| 1243 | ;;; Tab history mode | 1281 | ;;; Tab history mode |
| 1244 | 1282 | ||
| 1245 | (defvar tab-bar-history-limit 10 | 1283 | (defvar tab-bar-history-limit 10 |
| @@ -1630,6 +1668,8 @@ a function, then it is called with two arguments: BUFFER and ALIST, and | |||
| 1630 | should return the tab name. When a `tab-name' entry is omitted, create | 1668 | should return the tab name. When a `tab-name' entry is omitted, create |
| 1631 | a new tab without an explicit name. | 1669 | a new tab without an explicit name. |
| 1632 | 1670 | ||
| 1671 | The ALIST entry `tab-group' (string or function) defines the tab group. | ||
| 1672 | |||
| 1633 | If ALIST contains a `reusable-frames' entry, its value determines | 1673 | If ALIST contains a `reusable-frames' entry, its value determines |
| 1634 | which frames to search for a reusable tab: | 1674 | which frames to search for a reusable tab: |
| 1635 | nil -- the selected frame (actually the last non-minibuffer frame) | 1675 | nil -- the selected frame (actually the last non-minibuffer frame) |
| @@ -1682,6 +1722,8 @@ then it is called with two arguments: BUFFER and ALIST, and should return | |||
| 1682 | the tab name. When a `tab-name' entry is omitted, create a new tab without | 1722 | the tab name. When a `tab-name' entry is omitted, create a new tab without |
| 1683 | an explicit name. | 1723 | an explicit name. |
| 1684 | 1724 | ||
| 1725 | The ALIST entry `tab-group' (string or function) defines the tab group. | ||
| 1726 | |||
| 1685 | This is an action function for buffer display, see Info | 1727 | This is an action function for buffer display, see Info |
| 1686 | node `(elisp) Buffer Display Action Functions'. It should be | 1728 | node `(elisp) Buffer Display Action Functions'. It should be |
| 1687 | called only by `display-buffer' or a function directly or | 1729 | called only by `display-buffer' or a function directly or |
| @@ -1693,6 +1735,11 @@ indirectly called by the latter." | |||
| 1693 | (setq tab-name (funcall tab-name buffer alist))) | 1735 | (setq tab-name (funcall tab-name buffer alist))) |
| 1694 | (when tab-name | 1736 | (when tab-name |
| 1695 | (tab-bar-rename-tab tab-name))) | 1737 | (tab-bar-rename-tab tab-name))) |
| 1738 | (let ((tab-group (alist-get 'tab-group alist))) | ||
| 1739 | (when (functionp tab-group) | ||
| 1740 | (setq tab-group (funcall tab-group buffer alist))) | ||
| 1741 | (when tab-group | ||
| 1742 | (tab-bar-change-tab-group tab-group))) | ||
| 1696 | (window--display-buffer buffer (selected-window) 'tab alist))) | 1743 | (window--display-buffer buffer (selected-window) 'tab alist))) |
| 1697 | 1744 | ||
| 1698 | (defun switch-to-buffer-other-tab (buffer-or-name &optional norecord) | 1745 | (defun switch-to-buffer-other-tab (buffer-or-name &optional norecord) |
| @@ -1770,6 +1817,7 @@ When `switch-to-buffer-obey-display-actions' is non-nil, | |||
| 1770 | (defalias 'tab-move 'tab-bar-move-tab) | 1817 | (defalias 'tab-move 'tab-bar-move-tab) |
| 1771 | (defalias 'tab-move-to 'tab-bar-move-tab-to) | 1818 | (defalias 'tab-move-to 'tab-bar-move-tab-to) |
| 1772 | (defalias 'tab-rename 'tab-bar-rename-tab) | 1819 | (defalias 'tab-rename 'tab-bar-rename-tab) |
| 1820 | (defalias 'tab-group 'tab-bar-change-tab-group) | ||
| 1773 | (defalias 'tab-list 'tab-switcher) | 1821 | (defalias 'tab-list 'tab-switcher) |
| 1774 | 1822 | ||
| 1775 | (define-key tab-prefix-map "n" 'tab-duplicate) | 1823 | (define-key tab-prefix-map "n" 'tab-duplicate) |
| @@ -1782,6 +1830,7 @@ When `switch-to-buffer-obey-display-actions' is non-nil, | |||
| 1782 | (define-key tab-prefix-map "O" 'tab-previous) | 1830 | (define-key tab-prefix-map "O" 'tab-previous) |
| 1783 | (define-key tab-prefix-map "m" 'tab-move) | 1831 | (define-key tab-prefix-map "m" 'tab-move) |
| 1784 | (define-key tab-prefix-map "M" 'tab-move-to) | 1832 | (define-key tab-prefix-map "M" 'tab-move-to) |
| 1833 | (define-key tab-prefix-map "G" 'tab-group) | ||
| 1785 | (define-key tab-prefix-map "r" 'tab-rename) | 1834 | (define-key tab-prefix-map "r" 'tab-rename) |
| 1786 | (define-key tab-prefix-map "\r" 'tab-switch) | 1835 | (define-key tab-prefix-map "\r" 'tab-switch) |
| 1787 | (define-key tab-prefix-map "b" 'switch-to-buffer-other-tab) | 1836 | (define-key tab-prefix-map "b" 'switch-to-buffer-other-tab) |