From 883370eb1623b17ef88db0032e335fa9ad7d11bc Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 12 Mar 2020 01:22:04 +0800 Subject: [PATCH] [Feature] Support tab-bar-mode in workspace-name segment. Close #317. --- doom-modeline-segments.el | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/doom-modeline-segments.el b/doom-modeline-segments.el index 36a24f1..7e1c67d 100644 --- a/doom-modeline-segments.el +++ b/doom-modeline-segments.el @@ -193,6 +193,8 @@ (declare-function symbol-overlay-get-list 'symbol-overlay) (declare-function symbol-overlay-get-symbol 'symbol-overlay) (declare-function symbol-overlay-rename 'symbol-overlay) +(declare-function tab-bar--current-tab 'tab-bar) +(declare-function tab-bar--current-tab-index 'tab-bar) (declare-function tracking-next-buffer 'tracking) (declare-function tracking-previous-buffer 'tracking) (declare-function tracking-shorten 'tracking) @@ -1349,19 +1351,26 @@ one. The ignored buffers are excluded unless `aw-ignore-on' is nil." (doom-modeline-def-segment workspace-name "The current workspace name or number. -Requires `eyebrowse-mode' to be enabled." - (if (and (bound-and-true-p eyebrowse-mode) - (< 1 (length (eyebrowse--get 'window-configs)))) - (let* ((num (eyebrowse--get 'current-slot)) - (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) - (str (if (and tag (< 0 (length tag))) - tag - (when num (int-to-string num))))) - (assq-delete-all 'eyebrowse-mode mode-line-misc-info) - (propertize (format " %s " str) 'face - (if (doom-modeline--active) - 'doom-modeline-buffer-major-mode - 'mode-line-inactive))))) +Requires `eyebrowse-mode' or `tab-bar-mode' to be enabled." + (when-let + ((name (cond + ((and (bound-and-true-p eyebrowse-mode) + (< 1 (length (eyebrowse--get 'window-configs)))) + (assq-delete-all 'eyebrowse-mode mode-line-misc-info) + (when-let* + ((num (eyebrowse--get 'current-slot)) + (tag (nth 2 (assoc num (eyebrowse--get 'window-configs))))) + (if (< 0 (length tag)) tag (int-to-string num)))) + ((bound-and-true-p tab-bar-mode) + (let* ((current-tab (tab-bar--current-tab)) + (tab-index (tab-bar--current-tab-index)) + (explicit-name (alist-get 'explicit-name current-tab)) + (tab-name (alist-get 'name current-tab))) + (if explicit-name tab-name (+ 1 tab-index))))))) + (propertize (format " %s " name) 'face + (if (doom-modeline--active) + 'doom-modeline-buffer-major-mode + 'mode-line-inactive)))) ;;