[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master c06b5961ee 2/2: * lisp/tab-bar.el: Use customizable button icons
From: |
Juri Linkov |
Subject: |
master c06b5961ee 2/2: * lisp/tab-bar.el: Use customizable button icons (bug#51309, bug#51648) |
Date: |
Mon, 24 Oct 2022 03:34:16 -0400 (EDT) |
branch: master
commit c06b5961ee447780fb5dc15ec8ed38d14c2398df
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>
* lisp/tab-bar.el: Use customizable button icons (bug#51309, bug#51648)
* lisp/tab-bar.el (tab-bar--load-buttons): Use 'define-icon' to
define icons for tab-bar-new, tab-bar-close, tab-bar-menu-bar.
Also set tab-bar-new-button, tab-bar-close-button, tab-bar-menu-bar-button
to the specified icon-string.
(tab-bar-history-mode): Use 'define-icon' to
define icons for tab-bar-back, tab-bar-forward.
Also set tab-bar-back-button, tab-bar-forward-button
to the specified icon-string.
* lisp/emacs-lisp/icons.el (icons--create)<image>: Allow to easy
add new image props by using 'apply' on them. Add :margin.
---
lisp/emacs-lisp/icons.el | 25 ++++++------
lisp/tab-bar.el | 98 ++++++++++++++++++++++++++++++------------------
2 files changed, 75 insertions(+), 48 deletions(-)
diff --git a/lisp/emacs-lisp/icons.el b/lisp/emacs-lisp/icons.el
index a08ac7463c..86c4483030 100644
--- a/lisp/emacs-lisp/icons.el
+++ b/lisp/emacs-lisp/icons.el
@@ -196,18 +196,21 @@ present if the icon is represented by an image."
(image-supported-file-p file)
(propertize
" " 'display
- (if-let ((height (plist-get keywords :height)))
- (create-image file
- nil nil
- :height (if (eq height 'line)
+ (let ((props
+ (append
+ (if-let ((height (plist-get keywords :height)))
+ (list :height (if (eq height 'line)
(window-default-line-height)
- height)
- :scale 1
- :rotation (or (plist-get keywords :rotation) 0)
- :ascent (if (plist-member keywords :ascent)
- (plist-get keywords :ascent)
- 'center))
- (create-image file))))))
+ height)))
+ '(:scale 1)
+ (if-let ((rotation (plist-get keywords :rotation)))
+ (list :rotation rotation))
+ (if-let ((margin (plist-get keywords :margin)))
+ (list :margin margin))
+ (list :ascent (if (plist-member keywords :ascent)
+ (plist-get keywords :ascent)
+ 'center)))))
+ (apply 'create-image file nil nil props))))))
(cl-defmethod icons--create ((_type (eql 'emoji)) icon _keywords)
(when-let ((font (and (display-multi-font-p)
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index abefd996a8..ea615b92a2 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -155,25 +155,44 @@ For easier selection of tabs by their numbers, consider
customizing
(defun tab-bar--load-buttons ()
"Load the icons for the tab buttons."
- (when (and tab-bar-new-button
- (not (get-text-property 0 'display tab-bar-new-button)))
- ;; This file is pre-loaded so only here we can use the right
data-directory:
- (add-text-properties 0 (length tab-bar-new-button)
- `(display (image :type xpm
- :file "tabs/new.xpm"
- :margin ,tab-bar-button-margin
- :ascent center))
- tab-bar-new-button))
-
- (when (and tab-bar-close-button
- (not (get-text-property 0 'display tab-bar-close-button)))
- ;; This file is pre-loaded so only here we can use the right
data-directory:
- (add-text-properties 0 (length tab-bar-close-button)
- `(display (image :type xpm
- :file "tabs/close.xpm"
- :margin ,tab-bar-button-margin
- :ascent center))
- tab-bar-close-button)))
+ (require 'icons)
+
+ (unless (iconp 'tab-bar-new)
+ (define-icon tab-bar-new nil
+ `((image "tabs/new.xpm"
+ :margin ,tab-bar-button-margin
+ :ascent center)
+ ;; (emoji "➕")
+ ;; (symbol "+")
+ (text " + "))
+ "Icon for creating a new tab."
+ :version "29.1"
+ :help-echo "New tab"))
+ (setq tab-bar-new-button (icon-string 'tab-bar-new))
+
+ (unless (iconp 'tab-bar-close)
+ (define-icon tab-bar-close nil
+ `((image "tabs/close.xpm"
+ :margin ,tab-bar-button-margin
+ :ascent center)
+ ;; (emoji " ❌")
+ ;; (symbol "✕") ;; "ⓧ"
+ (text " x"))
+ "Icon for closing the clicked tab."
+ :version "29.1"
+ :help-echo "Click to close tab"))
+ (setq tab-bar-close-button (propertize (icon-string 'tab-bar-close)
+ 'close-tab t))
+
+ (unless (iconp 'tab-bar-menu-bar)
+ (define-icon tab-bar-menu-bar nil
+ '(;; (emoji "🍔")
+ (symbol "☰")
+ (text "Menu" :face tab-bar-tab-inactive))
+ "Icon for for the menu bar."
+ :version "29.1"
+ :help-echo "Menu bar"))
+ (setq tab-bar-menu-bar-button (icon-string 'tab-bar-menu-bar)))
(defun tab-bar--tab-bar-lines-for-frame (frame)
"Determine and return the value of `tab-bar-lines' for FRAME.
@@ -721,7 +740,7 @@ If a function returns nil, it doesn't directly affect the
tab bar appearance, but can do that by some side-effect.
If the list ends with `tab-bar-format-align-right' and
`tab-bar-format-global', then after enabling `display-time-mode'
-(or any other mode that uses `global-mode-string'),
+\(or any other mode that uses `global-mode-string'),
it will display time aligned to the right on the tab bar instead
of the mode line. Replacing `tab-bar-format-tabs' with
`tab-bar-format-tabs-groups' will group tabs on the tab bar."
@@ -921,7 +940,7 @@ when the tab is current. Return the result as a keymap."
(defun tab-bar-format-global ()
"Produce display of `global-mode-string' in the tab bar.
When `tab-bar-format-global' is added to `tab-bar-format'
-(possibly appended after `tab-bar-format-align-right'),
+\(possibly appended after `tab-bar-format-align-right'),
then modes that display information on the mode line
using `global-mode-string' will display the same text
on the tab bar instead."
@@ -1916,22 +1935,27 @@ and can restore them."
:global t :group 'tab-bar
(if tab-bar-history-mode
(progn
- (when (and tab-bar-mode (not (get-text-property 0 'display
tab-bar-back-button)))
- ;; This file is pre-loaded so only here we can use the right
data-directory:
- (add-text-properties 0 (length tab-bar-back-button)
- `(display (image :type xpm
- :file "tabs/left-arrow.xpm"
- :margin ,tab-bar-button-margin
- :ascent center))
- tab-bar-back-button))
- (when (and tab-bar-mode (not (get-text-property 0 'display
tab-bar-forward-button)))
- ;; This file is pre-loaded so only here we can use the right
data-directory:
- (add-text-properties 0 (length tab-bar-forward-button)
- `(display (image :type xpm
- :file "tabs/right-arrow.xpm"
- :margin ,tab-bar-button-margin
- :ascent center))
- tab-bar-forward-button))
+ (require 'icons)
+
+ (unless (iconp 'tab-bar-back)
+ (define-icon tab-bar-back nil
+ `((image "tabs/left-arrow.xpm"
+ :margin ,tab-bar-button-margin
+ :ascent center)
+ (text " < "))
+ "Icon for going back in tab history."
+ :version "29.1"))
+ (setq tab-bar-back-button (icon-string 'tab-bar-back))
+
+ (unless (iconp 'tab-bar-forward)
+ (define-icon tab-bar-forward nil
+ `((image "tabs/right-arrow.xpm"
+ :margin ,tab-bar-button-margin
+ :ascent center)
+ (text " > "))
+ "Icon for going forward in tab history."
+ :version "29.1"))
+ (setq tab-bar-forward-button (icon-string 'tab-bar-forward))
(add-hook 'pre-command-hook 'tab-bar--history-pre-change)
(add-hook 'window-configuration-change-hook 'tab-bar--history-change))