From c94c41fd6b9618e4a6422266f9e712753a8c199c Mon Sep 17 00:00:00 2001 From: forcer Date: Mon, 12 Sep 2005 23:36:00 +0000 Subject: Added `emms-random[_\c3_]' (idea by twb) darcs-hash:20050912233602-2189f-15c33eafc9d4c587065046a26762fa07359aee0d.gz --- emms.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'emms.el') diff --git a/emms.el b/emms.el index c5ce905..67c9aae 100644 --- a/emms.el +++ b/emms.el @@ -250,6 +250,14 @@ This is a good function to put in `emms-player-finished-hook'." (emms-playlist-select-previous) (emms-start)) +(defun emms-random () + "Jump to a random track." + (interactive) + (when emms-player-playing-p + (emms-stop)) + (emms-playlist-select-random) + (emms-start)) + (defun emms-pause () "Pause the current player." (interactive) @@ -572,6 +580,32 @@ used, and the contents removed." (error (error "No previous track in playlist")))))) +(defun emms-playlist-select-random () + "Select a random track in the playlist." + (with-current-emms-playlist + ;; FIXME: This is rather inefficient. + (save-excursion + (let ((track-indices nil) + (donep nil)) + (condition-case nil + (progn + (emms-playlist-first) + (setq track-indices (cons (point) + track-indices))) + (error + (setq donep t))) + (while (not donep) + (condition-case nil + (progn + (emms-playlist-next) + (setq track-indices (cons (point) + track-indices))) + (error + (setq donep t)))) + (setq track-indices (vconcat track-indices)) + (emms-playlist-select (aref track-indices + (random (length track-indices)))))))) + (defun emms-playlist-select-first () "Select the first track in the playlist." (with-current-emms-playlist -- cgit v1.2.3