From 84c320cda4fd0257eb9d2e1d78ff1124a473cf69 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 16 Jan 2022 15:54:00 -0600 Subject: Make tab bar more better --- init.el | 12 ++++++++++- lisp/+tab-bar.el | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/init.el b/init.el index 4136271..63d0f87 100644 --- a/init.el +++ b/init.el @@ -584,7 +584,17 @@ tab-bar-tab-name-ellipsis truncate-string-ellipsis tab-bar-show t) (tab-bar-mode +1) - (+tab-bar-misc-info-mode +1)) + (if (version< emacs-version "28.0") + (+tab-bar-misc-info-mode +1) + (:option tab-bar-format '(+tab-bar-format-menu-bar + tab-bar-format-history + tab-bar-format-tabs + tab-bar-separator + tab-bar-format-add-tab + tab-bar-format-align-right + +tab-bar-misc-info + tab-bar-separator + )))) (setup text (:hook #'turn-on-auto-fill)) diff --git a/lisp/+tab-bar.el b/lisp/+tab-bar.el index 1ee7606..02f3a0d 100644 --- a/lisp/+tab-bar.el +++ b/lisp/+tab-bar.el @@ -24,10 +24,12 @@ (defun +tab-bar-basename () "Generate the tab name from the basename of the buffer of the selected window." - (let* ((tab-file-name (buffer-file-name (window-buffer (minibuffer-selected-window))))) - (if tab-file-name - (file-name-nondirectory tab-file-name) - (+tab-bar-tab-name-truncated-left)))) + (let* ((tab-file-name (buffer-file-name (window-buffer + (minibuffer-selected-window))))) + (concat " " + (if tab-file-name + (file-name-nondirectory tab-file-name) + (+tab-bar-tab-name-truncated-left))))) (defun +tab-bar-tab-name-truncated-left () "Generate the tab name from the buffer of the selected window. @@ -49,6 +51,62 @@ name to the left." (max 0 (- l-name tab-bar-tab-name-truncated-max l-ell)))) 'help-echo tab-name)))) + +;;; Menu bar +;; stole from https://github.com/emacs-mirror/emacs/blob/master/lisp/tab-bar.el + +(defun +tab-bar-menu-bar (event) + "Pop up the same menu as displayed by the menu bar. +Used by `tab-bar-format-menu-bar'." + (interactive "e") + (let ((menu (make-sparse-keymap (propertize "Menu Bar" 'hide t)))) + (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) + (map-keymap (lambda (key binding) + (when (consp binding) + (define-key-after menu (vector key) + (copy-sequence binding)))) + (menu-bar-keymap)) + (popup-menu menu event))) + +(defun +tab-bar-format-menu-bar () + "Produce the Menu button for the tab bar that shows the menu bar." + `((menu-bar menu-item (propertize "Ɛ " 'face 'tab-bar-tab-inactive) + +tab-bar-menu-bar :help "Menu Bar"))) + + +;;; Tab bar format tabs + +(require 'el-patch) + +(el-patch-defun tab-bar--format-tab (tab i) + (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) + ,(or + (alist-get 'binding tab) + `(lambda () + (interactive) + (tab-bar-select-tab ,i))) + :help "Click to visit tab")))) + `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i))) + menu-item "" + ,(or + (alist-get 'close-binding tab) + `(lambda () + (interactive) + (tab-bar-close-tab ,i))))))) + ;; Emacs 27 -- cgit 1.4.1-21-gabe81