From 8c8a175bfe767013186cdd92b13b3ad18d841f05 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 28 Jan 2025 19:51:55 +1100 Subject: [emacs] Make emms make proportional choice when selecting a random album Previously, it selects a random album from the list of albums, regardless of number of tracks in the album. Now it first goes to a random line in the playlist, then finds the first track in the same album. --- emacs/.emacs.d/lisp/my/my-emms.el | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'emacs/.emacs.d/lisp/my/my-emms.el') diff --git a/emacs/.emacs.d/lisp/my/my-emms.el b/emacs/.emacs.d/lisp/my/my-emms.el index e6fb0e2..e3e4d32 100644 --- a/emacs/.emacs.d/lisp/my/my-emms.el +++ b/emacs/.emacs.d/lisp/my/my-emms.el @@ -374,17 +374,20 @@ artist/album/track." my-emms-favourites-playlist))) ;;; random album in emms -(defun my-my-emms-current-album-name () +(defun my-emms-current-album-name () (file-name-directory (my-emms-get-current-track-name))) +(defun my-emms-playlist-album-name-at-point () + (file-name-directory (emms-track-get (emms-playlist-track-at) 'name))) + (defun my-emms-next-track-or-random-album () (interactive) - (let ((current-album (my-my-emms-current-album-name))) + (let ((current-album (my-emms-current-album-name))) (when emms-player-playing-p (emms-stop)) (emms-playlist-current-select-next) - (if (string-equal (my-my-emms-current-album-name) current-album) + (if (string-equal (my-emms-current-album-name) current-album) (emms-start) - (my-emms-random-album nil)))) + (my-emms-playlist-random-album nil)))) (defvar-local my-emms-albums-cache (vector)) @@ -415,20 +418,15 @@ under /zzz-seren/." (elt my-emms-albums-cache (random (length my-emms-albums-cache))))) album)) -(defun my-emms-random-album (update-album) - (interactive "P") +(defun my-emms-playlist-random-album () + (interactive) (with-current-emms-playlist - (when (or update-album (length= my-emms-albums-cache 0)) - (my-emms-save-albums-cache)) - (when emms-player-playing-p (emms-stop)) - (let ((saved-position (point))) + (goto-line (1+ (random (count-lines (point-min) (point-max))))) + (let ((album-name (my-emms-playlist-album-name-at-point))) (goto-char (point-min)) - (if (search-forward - (my-emms-get-random-album) - nil t) - (emms-playlist-mode-play-current-track) - (goto-char saved-position) - (error "Cannot play random album"))))) + (search-forward album-name) + (beginning-of-line) + (emms-playlist-mode-play-current-track)))) ;;; override the minor mode ;;;###autoload -- cgit v1.2.3