diff options
| author | Adam Porter | 2020-12-13 05:54:28 +0000 |
|---|---|---|
| committer | Juri Linkov | 2020-12-23 23:05:55 +0200 |
| commit | 33210c8dc07fe8e1aed302aff09cac9ba798a221 (patch) | |
| tree | 122c53f06844a396e3566bfbd2381cf7b2ca3978 | |
| parent | 40bc77d9a6b8d824690fb6ee3003d74951bb3ae5 (diff) | |
| download | emacs-33210c8dc07fe8e1aed302aff09cac9ba798a221.tar.gz emacs-33210c8dc07fe8e1aed302aff09cac9ba798a221.zip | |
* lisp/tab-line.el: New options, faces, and functions
* lisp/tab-line.el:
(tab-line-tab-face-functions): New option.
(tab-line-tab-inactive-alternate): New face.
(tab-line-tab-special): New face.
(tab-line-tab-face-inactive-alternating): New function.
(tab-line-tab-face-special): New function.
(tab-line-format-template): Use them.
* etc/NEWS: Update.
With thanks to Juri Linkov and Eli Zaretskii for their guidance.
| -rw-r--r-- | etc/NEWS | 12 | ||||
| -rw-r--r-- | lisp/tab-line.el | 65 |
2 files changed, 71 insertions, 6 deletions
| @@ -383,6 +383,18 @@ value of 'tab-bar-show'. | |||
| 383 | If your mouse or trackpad supports it, you can now scroll tabs when | 383 | If your mouse or trackpad supports it, you can now scroll tabs when |
| 384 | the mouse pointer is in the tab line by scrolling left or right. | 384 | the mouse pointer is in the tab line by scrolling left or right. |
| 385 | 385 | ||
| 386 | --- | ||
| 387 | *** New tab-line faces and options | ||
| 388 | The face 'tab-line-tab-special' is used for tabs whose buffers are | ||
| 389 | special, i.e. not file-backed. The face | ||
| 390 | 'tab-line-tab-inactive-alternate' is used to display inactive tabs | ||
| 391 | with an alternating background color, making them easier to | ||
| 392 | distinguish between, especially if the face 'tab-line-tab' is | ||
| 393 | configured to not display with a box; this alternate face is only | ||
| 394 | applied when the option 'tab-line-tab-face-functions' is | ||
| 395 | so-configured. That option may also be used to customize tab-line | ||
| 396 | faces in other ways. | ||
| 397 | |||
| 386 | ** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and | 398 | ** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and |
| 387 | 'previous-error-no-select' bound to 'p'. | 399 | 'previous-error-no-select' bound to 'p'. |
| 388 | 400 | ||
diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 46bf89f14eb..c9444718536 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | ;;; Code: | 28 | ;;; Code: |
| 29 | 29 | ||
| 30 | (require 'cl-lib) | ||
| 30 | (require 'seq) ; tab-line.el is not pre-loaded so it's safe to use it here | 31 | (require 'seq) ; tab-line.el is not pre-loaded so it's safe to use it here |
| 31 | 32 | ||
| 32 | 33 | ||
| @@ -35,6 +36,18 @@ | |||
| 35 | :group 'convenience | 36 | :group 'convenience |
| 36 | :version "27.1") | 37 | :version "27.1") |
| 37 | 38 | ||
| 39 | (defcustom tab-line-tab-face-functions '(tab-line-tab-face-special) | ||
| 40 | "Functions called to modify tab faces. | ||
| 41 | Each function is called with five arguments: the tab, a list of | ||
| 42 | all tabs, the face returned by the previously called modifier, | ||
| 43 | whether the tab is a buffer, and whether the tab is selected." | ||
| 44 | :type '(repeat | ||
| 45 | (choice (function-item tab-line-tab-face-special) | ||
| 46 | (function-item tab-line-tab-face-inactive-alternating) | ||
| 47 | (function :tag "Custom function"))) | ||
| 48 | :group 'tab-line | ||
| 49 | :version "28.1") | ||
| 50 | |||
| 38 | (defgroup tab-line-faces '((tab-line custom-face)) ; tab-line is defined in faces.el | 51 | (defgroup tab-line-faces '((tab-line custom-face)) ; tab-line is defined in faces.el |
| 39 | "Faces used in the tab line." | 52 | "Faces used in the tab line." |
| 40 | :group 'tab-line | 53 | :group 'tab-line |
| @@ -63,6 +76,25 @@ | |||
| 63 | :version "27.1" | 76 | :version "27.1" |
| 64 | :group 'tab-line-faces) | 77 | :group 'tab-line-faces) |
| 65 | 78 | ||
| 79 | (defface tab-line-tab-inactive-alternate | ||
| 80 | `((t (:inherit tab-line-tab-inactive :background "grey65"))) | ||
| 81 | "Alternate face for inactive tab-line tabs. | ||
| 82 | Applied to alternating tabs when option | ||
| 83 | `tab-line-tab-face-functions' includes function | ||
| 84 | `tab-line-tab-face-inactive-alternating'." | ||
| 85 | :version "28.1" | ||
| 86 | :group 'tab-line-faces) | ||
| 87 | |||
| 88 | (defface tab-line-tab-special | ||
| 89 | '((default (:weight bold)) | ||
| 90 | (((supports :slant italic)) | ||
| 91 | (:slant italic :weight normal))) | ||
| 92 | "Face for special (i.e. non-file-backed) tabs. | ||
| 93 | Applied when option `tab-line-tab-face-functions' includes | ||
| 94 | function `tab-line-tab-face-special'." | ||
| 95 | :version "28.1" | ||
| 96 | :group 'tab-line-faces) | ||
| 97 | |||
| 66 | (defface tab-line-tab-current | 98 | (defface tab-line-tab-current |
| 67 | '((default | 99 | '((default |
| 68 | :inherit tab-line-tab) | 100 | :inherit tab-line-tab) |
| @@ -412,7 +444,14 @@ variable `tab-line-tabs-function'." | |||
| 412 | (cdr (assq 'selected tab)))) | 444 | (cdr (assq 'selected tab)))) |
| 413 | (name (if buffer-p | 445 | (name (if buffer-p |
| 414 | (funcall tab-line-tab-name-function tab tabs) | 446 | (funcall tab-line-tab-name-function tab tabs) |
| 415 | (cdr (assq 'name tab))))) | 447 | (cdr (assq 'name tab)))) |
| 448 | (face (if selected-p | ||
| 449 | (if (eq (selected-window) (old-selected-window)) | ||
| 450 | 'tab-line-tab-current | ||
| 451 | 'tab-line-tab) | ||
| 452 | 'tab-line-tab-inactive))) | ||
| 453 | (dolist (fn tab-line-tab-face-functions) | ||
| 454 | (setf face (funcall fn tab tabs face buffer-p selected-p))) | ||
| 416 | (concat | 455 | (concat |
| 417 | separator | 456 | separator |
| 418 | (apply 'propertize | 457 | (apply 'propertize |
| @@ -425,11 +464,7 @@ variable `tab-line-tabs-function'." | |||
| 425 | `( | 464 | `( |
| 426 | tab ,tab | 465 | tab ,tab |
| 427 | ,@(if selected-p '(selected t)) | 466 | ,@(if selected-p '(selected t)) |
| 428 | face ,(if selected-p | 467 | face ,face |
| 429 | (if (eq (selected-window) (old-selected-window)) | ||
| 430 | 'tab-line-tab-current | ||
| 431 | 'tab-line-tab) | ||
| 432 | 'tab-line-tab-inactive) | ||
| 433 | mouse-face tab-line-highlight))))) | 468 | mouse-face tab-line-highlight))))) |
| 434 | tabs)) | 469 | tabs)) |
| 435 | (hscroll-data (tab-line-auto-hscroll strings hscroll))) | 470 | (hscroll-data (tab-line-auto-hscroll strings hscroll))) |
| @@ -453,6 +488,24 @@ variable `tab-line-tabs-function'." | |||
| 453 | tab-line-new-button) | 488 | tab-line-new-button) |
| 454 | (list tab-line-new-button))))) | 489 | (list tab-line-new-button))))) |
| 455 | 490 | ||
| 491 | (defun tab-line-tab-face-inactive-alternating (tab tabs face _buffer-p selected-p) | ||
| 492 | "Return FACE for TAB in TABS with alternation. | ||
| 493 | When TAB is an inactive buffer and is even-numbered, make FACE | ||
| 494 | inherit from `tab-line-tab-inactive-alternate'. For use in | ||
| 495 | `tab-line-tab-face-functions'." | ||
| 496 | (when (and (not selected-p) (cl-evenp (cl-position tab tabs))) | ||
| 497 | (setf face `(:inherit (tab-line-tab-inactive-alternate ,face)))) | ||
| 498 | face) | ||
| 499 | |||
| 500 | (defun tab-line-tab-face-special (tab _tabs face buffer-p _selected-p) | ||
| 501 | "Return FACE for TAB according to whether it's special. | ||
| 502 | When TAB is a non-file-backed buffer, make FACE inherit from | ||
| 503 | `tab-line-tab-special'. For use in | ||
| 504 | `tab-line-tab-face-functions'." | ||
| 505 | (when (and buffer-p (not (buffer-file-name tab))) | ||
| 506 | (setf face `(:inherit (tab-line-tab-special ,face)))) | ||
| 507 | face) | ||
| 508 | |||
| 456 | (defvar tab-line-auto-hscroll) | 509 | (defvar tab-line-auto-hscroll) |
| 457 | 510 | ||
| 458 | (defun tab-line-format () | 511 | (defun tab-line-format () |