branch: externals/listen
commit 19e309b28a89d7fa289cd42df010ab554e8c2ade
Author: Adam Porter <[email protected]>
Commit: Adam Porter <[email protected]>
Change: (listen-lighter-format, listen-mode-lighter) Use format-spec
---
README.org | 1 +
docs/README.org | 1 +
listen.el | 82 +++++++++++++++++++++++++++++----------------------------
3 files changed, 44 insertions(+), 40 deletions(-)
diff --git a/README.org b/README.org
index f1b6702448..599cb1d66c 100644
--- a/README.org
+++ b/README.org
@@ -227,6 +227,7 @@ The ~listen-mode~ minor mode runs a timer which plays the
next track in the curr
*Additions*
- Info manual.
+- Option ~listen-lighter-format~ now allows customizing the mode line lighter.
*Changes*
- Command ~listen-queue~ switches to existing queue buffers without reverting
them.
diff --git a/docs/README.org b/docs/README.org
index bb47f91d88..5a17eedfa7 100644
--- a/docs/README.org
+++ b/docs/README.org
@@ -237,6 +237,7 @@ The ~listen-mode~ minor mode runs a timer which plays the
next track in the curr
*Additions*
+ Info manual.
++ Option ~listen-lighter-format~ now allows customizing the mode line lighter.
*Changes*
+ Command ~listen-queue~ switches to existing queue buffers without reverting
them.
diff --git a/listen.el b/listen.el
index 5df832c6c0..37358b2755 100755
--- a/listen.el
+++ b/listen.el
@@ -85,11 +85,21 @@
Used for mode line lighter and transient menu."
:type 'natnum)
-(defcustom listen-lighter-format 'remaining
- "Time elapsed/remaining format.
-For the currently playing track."
- :type '(choice (const :tag "Time remaining" remaining)
- (const :tag "Time elapsed/total" elapsed)))
+(defcustom listen-lighter-format "🎵:%s %a: %>15t (%r)%E "
+ "Format for mode line lighter.
+Uses `format-spec', which see. These format specs are available:
+
+%a: Artist
+%A: Album
+%t: Title
+
+%e: Elapsed time
+%r: Remaining time
+%s: Player status icon
+
+%E: Extra data specified in `listen-lighter-extra-functions',
+ which see."
+ :type 'string)
(defcustom listen-lighter-extra-functions nil
"Functions to show extra info in the lighter.
@@ -215,41 +225,33 @@ Interactively, jump to current queue's current track."
(remove lighter global-mode-string)))))
(defun listen-mode-lighter ()
- "Return lighter for `listen-mode'."
- (cl-labels ((format-track ()
- (when-let ((info (listen--info listen-player))
- ;; Sometimes when paused/stopped, the artist and/or
- ;; title are nil even if info isn't, so we must
- ;; check before treating them as strings.
- (artist (alist-get "artist" info nil nil #'equal))
- (title (alist-get "title" info nil nil #'equal)))
- (format "%s: %s" artist
- (truncate-string-to-width
- title listen-lighter-title-max-length nil nil t))))
- (format-status ()
- (pcase (listen--status listen-player)
- ("playing" "▶")
- ("paused" "⏸")
- ("stopped" "■")))
- (format-extra ()
- (mapconcat #'funcall listen-lighter-extra-functions " ")))
- (apply #'concat "🎵:"
- (if (and (listen--running-p listen-player)
- (listen--playing-p listen-player))
- (list (format-status) " " (format-track)
- " ("
- (pcase listen-lighter-format
- ('remaining (concat "-" (listen-format-seconds (-
(listen--length listen-player)
-
(listen--elapsed listen-player)))))
- (_ (concat (listen-format-seconds (listen--elapsed
listen-player))
- "/"
- (listen-format-seconds (listen--length
listen-player)))))
- ")"
- (if-let ((extra (format-extra)))
- (concat " " extra)
- "")
- " ")
- '("■ ")))))
+ "Return lighter for `listen-mode'.
+According to `listen-lighter-format', which see."
+ (if-let (((listen--running-p listen-player))
+ ((listen--playing-p listen-player))
+ (info (listen--info listen-player)))
+ (format-spec listen-lighter-format
+ `((?a . ,(lambda ()
+ (alist-get "artist" info nil nil #'equal)))
+ (?A . ,(lambda ()
+ (alist-get "album" info nil nil #'equal)))
+ (?t . ,(lambda ()
+ (alist-get "title" info nil nil #'equal)))
+ (?e . ,(lambda ()
+ (listen-format-seconds (listen--elapsed
listen-player))))
+ (?r . ,(lambda ()
+ (concat "-" (listen-format-seconds
+ (- (listen--length listen-player)
+ (listen--elapsed
listen-player))))))
+ (?s . ,(lambda ()
+ (pcase (listen--status listen-player)
+ ("playing" "▶")
+ ("paused" "⏸")
+ ("stopped" "■"))))
+ (?E . ,(lambda ()
+ (if-let ((extra (mapconcat #'funcall
listen-lighter-extra-functions " ")))
+ (concat " " extra)
+ "")))))))
(defun listen-lighter-format-rating ()
"Return the rating of the current track for display in the lighter."