emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/listen c13ee53dbe 2/3: Add: Lighter faces


From: ELPA Syncer
Subject: [elpa] externals/listen c13ee53dbe 2/3: Add: Lighter faces
Date: Thu, 28 Mar 2024 18:58:20 -0400 (EDT)

branch: externals/listen
commit c13ee53dbe1b8496e079b211d9950d439b65233b
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Add: Lighter faces
    
    Setting the 'risky-local-variable' symbol property on the lighter
    variable is the key to allowing faces (and, e.g. image display
    properties) to work in mode line strings.  This was discovered by
    careful reading of the fine manual.
---
 README.org      |  3 ++-
 docs/README.org |  3 ++-
 listen-lib.el   | 30 ++++++++++++++++++++++++++++++
 listen.el       | 39 +++++++++++++++++++++++++--------------
 4 files changed, 59 insertions(+), 16 deletions(-)

diff --git a/README.org b/README.org
index 078d55e015..054885aeca 100644
--- a/README.org
+++ b/README.org
@@ -225,7 +225,8 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 
 ** v0.10-pre
 
-Nothing new yet.
+*Additions*
+- Faces for parts of mode line lighter.
 
 ** v0.9
 
diff --git a/docs/README.org b/docs/README.org
index 4d2a96f965..e798590a6b 100644
--- a/docs/README.org
+++ b/docs/README.org
@@ -237,7 +237,8 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 
 ** v0.10-pre
 
-Nothing new yet.
+*Additions*
++ Faces for parts of mode line lighter.
 
 ** v0.9
 
diff --git a/listen-lib.el b/listen-lib.el
index be9a7e7331..600afc5056 100644
--- a/listen-lib.el
+++ b/listen-lib.el
@@ -107,6 +107,36 @@ return a list of values; otherwise return the sole value."
 (defface listen-rating '((t :inherit font-lock-escape-face))
   "Track rating.")
 
+(defgroup listen-lighter-faces nil
+  "Faces used in the mode line lighter."
+  :group 'listen-faces)
+
+(defface listen-lighter-artist '((t :inherit listen-artist))
+  "Track artist.")
+
+(defface listen-lighter-title '((t :inherit listen-title))
+  "Track title.")
+
+(defface listen-lighter-album '((t :inherit listen-album))
+  "Track album.")
+
+(defface listen-lighter-filename '((t :inherit listen-filename))
+  "Track filename.")
+
+(defface listen-lighter-genre '((t :inherit listen-genre))
+  "Track genre.")
+
+(defface listen-lighter-rating '((t :inherit listen-rating))
+  "Track rating.")
+
+(defface listen-lighter-time '((t :inherit fixed-pitch))
+  "Track time elapsed/remaining.")
+
+(defface listen-lighter-extra '((t :inherit font-lock-comment-face))
+  "See `listen-lighter-extra-functions'.")
+
+
+
 ;;;; Functions
 
 ;; FIXME: Declare this differently or something.
diff --git a/listen.el b/listen.el
index fb8e0b7a75..039a94fc30 100755
--- a/listen.el
+++ b/listen.el
@@ -208,6 +208,9 @@ Interactively, jump to current queue's current track."
 ;;;; Mode
 
 (defvar listen-mode-lighter nil)
+;; Setting this symbol property allows faces and display properties to affect 
the lighter in the
+;; mode line and tab bar.
+(put 'listen-mode-lighter 'risky-local-variable t)
 
 ;;;###autoload
 (define-minor-mode listen-mode
@@ -237,29 +240,37 @@ According to `listen-lighter-format', which see."
              (info (listen--info listen-player)))
     (format-spec listen-lighter-format
                  `((?a . ,(lambda ()
-                            (or (alist-get "artist" info nil nil #'equal) "")))
+                            (propertize (or (alist-get "artist" info nil nil 
#'equal) "")
+                                        'face 'listen-lighter-artist)))
                    (?A . ,(lambda ()
-                            (or (alist-get "album" info nil nil #'equal) "")))
+                            (propertize (or (alist-get "album" info nil nil 
#'equal) "")
+                                        'face 'listen-lighter-album)))
                    (?t . ,(lambda ()
                             (if-let ((title (alist-get "title" info nil nil 
#'equal)))
-                                (truncate-string-to-width title 
listen-lighter-title-max-length
-                                                          nil nil t)
+                                (propertize
+                                 (truncate-string-to-width title 
listen-lighter-title-max-length
+                                                           nil nil t)
+                                 'face 'listen-lighter-title)
                               "")))
                    (?e . ,(lambda ()
-                            (listen-format-seconds (listen--elapsed 
listen-player))))
+                            (propertize (listen-format-seconds 
(listen--elapsed listen-player))
+                                        'face 'listen-lighter-time)))
                    (?r . ,(lambda ()
-                            (concat "-" (listen-format-seconds
-                                         (- (listen--length listen-player)
-                                            (listen--elapsed 
listen-player))))))
+                            (propertize (concat "-" (listen-format-seconds
+                                                     (- (listen--length 
listen-player)
+                                                        (listen--elapsed 
listen-player))))
+                                        'face 'listen-lighter-time)))
                    (?s . ,(lambda ()
-                            (pcase (listen--status listen-player)
-                              ("playing" "▶")
-                              ("paused" "⏸")
-                              ("stopped" "■")
-                              (_ ""))))
+                            (propertize (pcase (listen--status listen-player)
+                                          ("playing" "▶")
+                                          ("paused" "⏸")
+                                          ("stopped" "■")
+                                          (_ ""))
+                                        'face 'bold)))
                    (?E . ,(lambda ()
                             (if-let ((extra (mapconcat #'funcall 
listen-lighter-extra-functions " ")))
-                                (concat " " extra)
+                                (propertize (concat " " extra)
+                                            'face 'listen-lighter-extra)
                               "")))))))
 
 (defun listen-lighter-format-rating ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]