From 25246b8fc6c50cb4dae804e3bab154dad67e9fe9 Mon Sep 17 00:00:00 2001 From: Simon Parri Date: Tue, 26 Aug 2025 11:55:15 -0500 Subject: Emacs: Add current time and total time to empv mode line string --- common/.emacs.d/init.el | 60 ++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/common/.emacs.d/init.el b/common/.emacs.d/init.el index 0ade3ee..9c5e4f6 100644 --- a/common/.emacs.d/init.el +++ b/common/.emacs.d/init.el @@ -3005,38 +3005,46 @@ instead." empv-mpv-args (cl-delete "--no-video" empv-mpv-args :test #'equal)) (defvar empv-mode-line-format - (concat " " (propertize "%t" 'face 'bold) " " (propertize "[%p]" 'face 'italic))) + (concat " " (propertize "%t" 'face 'bold) " " (propertize "[%T/%D]" 'face 'italic))) (defvar empv-mode-line-string) (defvar empv-mode-line-timer) (defun empv-mode-line-update () - (empv--let-properties - '(time-pos - duration - metadata - path) - (if .path - (let ((progress - (when (and .time-pos .duration) - (thread-last - (/ .time-pos .duration) - (* 100) - (format "%d%%")))) - (path .path)) - (let-alist .metadata - (setq empv-mode-line-string - (format-spec empv-mode-line-format - `((?t . ,(or (and .TITLE - (string-limit .TITLE 50)) - (string-limit path 50 t))) - (?a . ,(or .ARTIST "")) - (?A . ,(or .ALBUM "")) - (?G . ,(or .GENRE "")) - (?p . ,(or progress "")))))) - (force-mode-line-update)) - (setq empv-mode-line-string "")))) + (cl-flet ((time-str (sec total) + (if (> (or total 0) (* 60 60)) + (format-seconds "%.2h:%.2m:%.2s" (or sec 0)) + (format-seconds "%.2m:%.2s" (or sec 0))))) + (empv--let-properties + '(time-pos + duration + metadata + path) + (if .path + (let ((time-pos (time-str .time-pos .duration)) + (duration (time-str .duration .duration)) + (progress + (when (and .time-pos .duration) + (thread-last + (/ .time-pos .duration) + (* 100) + (format "%d%%")))) + (path .path)) + (let-alist .metadata + (setq empv-mode-line-string + (format-spec empv-mode-line-format + `((?t . ,(or (and .TITLE + (string-limit .TITLE 50)) + (string-limit path 50 t))) + (?a . ,(or .ARTIST "")) + (?A . ,(or .ALBUM "")) + (?G . ,(or .GENRE "")) + (?p . ,(or progress "")) + (?T . ,(or time-pos "")) + (?D . ,(or duration "")))))) + (force-mode-line-update)) + (setq empv-mode-line-string ""))))) (define-minor-mode empv-mode-line-mode "" -- cgit v1.2.3