diff --git a/.emacs.d/lisp/init-emms.el b/.emacs.d/lisp/init-emms.el index 0646074a..490a6437 100644 --- a/.emacs.d/lisp/init-emms.el +++ b/.emacs.d/lisp/init-emms.el @@ -144,24 +144,28 @@ character." (defun ambrevar/emms-tracks-duration (begin end) "Display play time of tracks in region." (interactive "r") - (if (not (use-region-p)) - (message "%s" (emms-browser-track-duration - (car (emms-browser-tracks-at-point)))) - (let* ((total-time) - (first-line (line-number-at-pos begin)) - (last-line (line-number-at-pos end)) - (count 0)) - (setq total-time - (save-mark-and-excursion - (cl-loop for line from first-line to last-line - do (goto-line line) - for time = (emms-track-get (car (emms-browser-tracks-at-point)) - 'info-playing-time) - when time - do (cl-incf count) - when time - sum time))) - (message "%02d:%02d for %d tracks" (/ total-time 60) (% total-time 60) - count)))) + (cl-flet ((track-at-point () + (if (eq major-mode 'emms-playlist-mode) + (emms-playlist-track-at) + (car (emms-browser-tracks-at-point))))) + (if (not (use-region-p)) + (message "%s" (emms-browser-track-duration + (track-at-point))) + (let* ((total-time) + (first-line (line-number-at-pos begin)) + (last-line (line-number-at-pos end)) + (count 0)) + (setq total-time + (save-mark-and-excursion + (cl-loop for line from first-line to last-line + do (goto-line line) + for time = (emms-track-get (track-at-point) + 'info-playing-time) + when time + do (cl-incf count) + when time + sum time))) + (message "%02d:%02d for %d tracks" (/ total-time 60) (% total-time 60) + count))))) (provide 'init-emms)