81 lines
2.5 KiB
EmacsLisp
81 lines
2.5 KiB
EmacsLisp
;;; +tab-bar.el -*- lexical-binding: t; -*-
|
||
|
||
;;; Commentary:
|
||
|
||
;; Emacs 28 comes with an easy-to-use `tab-bar-format' option, but I still use
|
||
;; Emacs 27 on my Windows machine. Thus, the code in this file.
|
||
|
||
;;; Code:
|
||
|
||
(require 'tab-bar)
|
||
|
||
|
||
;; Common
|
||
|
||
(defun +tab-bar-misc-info ()
|
||
"Display `mode-line-misc-info', formatted for the tab-bar."
|
||
`((global menu-item ,(string-trim-right
|
||
(format-mode-line mode-line-misc-info))
|
||
ignore)))
|
||
|
||
(defvar +tab-bar-show-original nil
|
||
"Original value of `tab-bar-show'.")
|
||
|
||
|
||
;; Emacs 27
|
||
|
||
(defun +tab-bar-misc-info-27 (output &rest _)
|
||
"Display `mode-line-misc-info' in the `tab-bar' on Emacs 27.
|
||
This is :filter-return advice for `tab-bar-make-keymap-1'."
|
||
(let* ((reserve (length (format-mode-line mode-line-misc-info)))
|
||
(str (propertize " "
|
||
'display `(space :align-to (- right (- 0 right-margin)
|
||
,reserve)))))
|
||
(prog1 (append output
|
||
`((align-right menu-item ,str nil))
|
||
(+tab-bar-misc-info)))))
|
||
|
||
|
||
;; Emacs 28
|
||
|
||
(defvar +tab-bar-format-original nil
|
||
"Original value of `tab-bar-format'.")
|
||
|
||
(defun +tab-bar-misc-info-28 ()
|
||
"Display `mode-line-misc-info', right-aligned, on Emacs 28."
|
||
(append (unless (memq 'tab-bar-format-align-right tab-bar-format)
|
||
'(tab-bar-format-align-right))
|
||
'(+tab-bar-misc-info)))
|
||
|
||
|
||
|
||
(define-minor-mode +tab-bar-misc-info-mode
|
||
"Show the `mode-line-misc-info' in the `tab-bar'."
|
||
:lighter ""
|
||
:global t
|
||
(if +tab-bar-misc-info-mode
|
||
(progn ; Enable
|
||
(setq +tab-bar-show-original tab-bar-show)
|
||
(cond
|
||
((boundp 'tab-bar-format) ; Emacs 28
|
||
(setq +tab-bar-format-original tab-bar-format)
|
||
(unless (memq '+tab-bar-misc-info tab-bar-format)
|
||
(setq tab-bar-format
|
||
(append tab-bar-format (+tab-bar-misc-info-28)))))
|
||
((fboundp 'tab-bar-make-keymap-1) ; Emacs 27
|
||
(advice-add 'tab-bar-make-keymap-1 :filter-return
|
||
'+tab-bar-misc-info-27)))
|
||
(setq tab-bar-show t))
|
||
(progn ; Disable
|
||
(setq tab-bar-show +tab-bar-show-original)
|
||
(cond
|
||
((boundp 'tab-bar-format) ; Emacs 28
|
||
(setq tab-bar-format +tab-bar-format-original))
|
||
((fboundp 'tab-bar-make-keymap-1) ; Emacs 27
|
||
(advice-remove 'tab-bar-make-keymap-1 '+tab-bar-misc-info-27))))))
|
||
|
||
|
||
|
||
(provide '+tab-bar)
|
||
;;; +tab-bar.el ends here
|