From 83de113f4e9d2cde0a0ff6c2d56dbc2cba21b938 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 16 Feb 2022 23:06:05 -0600 Subject: Add bunches of tab-bar stuff --- lisp/+tab-bar.el | 144 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 91 insertions(+), 53 deletions(-) (limited to 'lisp/+tab-bar.el') diff --git a/lisp/+tab-bar.el b/lisp/+tab-bar.el index 169cb53..b88b7eb 100644 --- a/lisp/+tab-bar.el +++ b/lisp/+tab-bar.el @@ -20,7 +20,7 @@ (defun +tab-bar-misc-info () "Display `mode-line-misc-info', formatted for the tab-bar." `((misc-info menu-item ,(string-trim-right - (format-mode-line mode-line-misc-info)) + (format-mode-line mode-line-misc-info)) ignore))) (defun +tab-bar-tracking-mode () @@ -28,26 +28,64 @@ ;; TODO: write something to convert a mode-line construct to a tab-bar ;; construct. (when tracking-mode - (cl-loop for i from 0 below (length tracking-mode-line-buffers) - as item = (nth i tracking-mode-line-buffers) - collect (append (list (intern (format "tracking-mode-line-%s" i)) - 'menu-item - (format-mode-line item)) - (if-let ((keymap (plist-get item 'keymap))) - (list (alist-get 'down-mouse-1 (cdadr keymap))) - (list #'ignore)) - (when-let ((help (plist-get item 'help-echo))) - (list :help help)))))) + (cons (when (> (length tracking-mode-line-buffers) 0) + '(track-mode-line-separator menu-item " " ignore)) + (cl-loop for i from 0 below (length tracking-mode-line-buffers) + as item = (nth i tracking-mode-line-buffers) + collect (append (list (intern (format "tracking-mode-line-%s" i)) + 'menu-item + (string-trim (format-mode-line item))) + (if-let ((keymap (plist-get item 'keymap))) + (list (alist-get 'down-mouse-1 (cdadr keymap))) + (list #'ignore)) + (when-let ((help (plist-get item 'help-echo))) + (list :help help))))))) (defun +tab-bar-date () "Display `display-time-string' in the tab-bar." (when display-time-mode `((date-time-string menu-item - ,(propertize display-time-string - 'face 'font-lock-comment-face) + ,(propertize (concat " " display-time-string)) ignore :help (discord-date-string))))) +(defun +tab-bar-notmuch-count () + "Display a notmuch count in the tab-bar." + (when (featurep 'notmuch) + (let* ((counts (notmuch-hello-query-counts notmuch-saved-searches)) + (next (cl-find "next" counts :key (lambda (l) (plist-get l :name)) :test 'equal)) + (next-count (plist-get next :count))) + (when (and next-count (> next-count 0)) + `((notmuch-count menu-item + ,(format " |%s|" next-count) + ignore + :help ,(format "%s mails requiring attention." next-count))))))) + +(defun +tab-bar-org-clock () + "Display `org-mode-line-string' in the tab-bar." + (when (org-clocking-p) + ;; org-mode-line-string + `((org-clocking menu-item + ,org-mode-line-string + (lambda (ev) + (interactive "e") + (let ((menu (make-sparse-keymap + (or org-clock-current-task "Org-Clock")))) + (map-keymap (lambda (key binding) + (when (consp binding) + (define-key-after menu (vector key) + (copy-sequence binding)))) + (org-clock-menu)) + (message "%S" ev) + (popup-menu menu ev))) + :help ,(or (replace-regexp-in-string + (rx "[[" (group (* (not "]"))) + "][" (group (* (not "]"))) + "]]") + "\\2" + org-clock-current-task) + "Org-Clock"))))) + (defcustom +tab-bar-emms-max-length 24 "Maximum length of `+tab-bar-emms'." :type 'number) @@ -85,16 +123,16 @@ (lambda () (interactive) (let ((bongo-playlist-buffer ;; XXX: I'm sure this is terribly inefficient - (cl-some (lambda (b) - (with-current-buffer b - (when-let* ((modep (derived-mode-p - 'bongo-playlist-mode)) - (bongo-playlist-buffer b) - (playingp (bongo-playing-p))) - b))) - (buffer-list)))) - (with-bongo-playlist-buffer - (bongo-pause/resume)))) + (cl-some (lambda (b) + (with-current-buffer b + (when-let* ((modep (derived-mode-p + 'bongo-playlist-mode)) + (bongo-playlist-buffer b) + (playingp (bongo-playing-p))) + b))) + (buffer-list)))) + (with-bongo-playlist-buffer + (bongo-pause/resume)))) :help ,(funcall bongo-header-line-function))))) (defvar +tab-bar-show-original nil @@ -161,19 +199,19 @@ This is just like `tab-bar-tab-name-truncated', but truncates the name to the left." (let* ((tab-name (buffer-name (window-buffer (minibuffer-selected-window)))) - (ellipsis (cond - (tab-bar-tab-name-ellipsis) - ((char-displayable-p ?…) "…") - ("..."))) - (l-ell (length ellipsis)) - (l-name (length tab-name))) + (ellipsis (cond + (tab-bar-tab-name-ellipsis) + ((char-displayable-p ?…) "…") + ("..."))) + (l-ell (length ellipsis)) + (l-name (length tab-name))) (if (< (length tab-name) tab-bar-tab-name-truncated-max) tab-name (propertize (concat (when (> (+ l-name l-ell) tab-bar-tab-name-truncated-max) ellipsis) (truncate-string-to-width tab-name l-name - (max 0 (- l-name tab-bar-tab-name-truncated-max l-ell)))) + (max 0 (- l-name tab-bar-tab-name-truncated-max l-ell)))) 'help-echo tab-name)))) @@ -209,27 +247,27 @@ Used by `tab-bar-format-menu-bar'." (el-patch-feature tab-bar) (with-eval-after-load 'tab-bar (el-patch-defun tab-bar--format-tab (tab i) - "Format TAB using its index I and return the result as a keymap." - (append - (el-patch-remove - `((,(intern (format "sep-%i" i)) menu-item ,(tab-bar-separator) ignore))) - (cond - ((eq (car tab) 'current-tab) - `((current-tab - menu-item - ,(funcall tab-bar-tab-name-format-function tab i) - ignore - :help "Current tab"))) - (t - `((,(intern (format "tab-%i" i)) - menu-item - ,(funcall tab-bar-tab-name-format-function tab i) - ,(alist-get 'binding tab) - :help "Click to visit tab")))) - (when (alist-get 'close-binding tab) - `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i))) - menu-item "" - ,(alist-get 'close-binding tab))))))) + "Format TAB using its index I and return the result as a keymap." + (append + (el-patch-remove + `((,(intern (format "sep-%i" i)) menu-item ,(tab-bar-separator) ignore))) + (cond + ((eq (car tab) 'current-tab) + `((current-tab + menu-item + ,(funcall tab-bar-tab-name-format-function tab i) + ignore + :help "Current tab"))) + (t + `((,(intern (format "tab-%i" i)) + menu-item + ,(funcall tab-bar-tab-name-format-function tab i) + ,(alist-get 'binding tab) + :help "Click to visit tab")))) + (when (alist-get 'close-binding tab) + `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i))) + menu-item "" + ,(alist-get 'close-binding tab))))))) ;; Emacs 27 @@ -242,8 +280,8 @@ This is :filter-return advice for `tab-bar-make-keymap-1'." 'display `(space :align-to (- right (- 0 right-margin) ,reserve))))) (prog1 (append output - `((align-right menu-item ,str nil)) - (+tab-bar-misc-info))))) + `((align-right menu-item ,str nil)) + (+tab-bar-misc-info))))) ;; Emacs 28 -- cgit 1.4.1-21-gabe81