aboutsummaryrefslogtreecommitdiff
path: root/emms.el
diff options
context:
space:
mode:
authorforcer <forcer>2005-09-12 23:36:00 +0000
committerforcer <mwolson@gnu.org>2005-09-12 23:36:00 +0000
commitc94c41fd6b9618e4a6422266f9e712753a8c199c (patch)
tree721663c31507398b78f25a9ef378b2524149a567 /emms.el
parentb75e294ed74af4e6a893af7400604e9967f493eb (diff)
Added `emms-random[_\c3_]' (idea by twb)
darcs-hash:20050912233602-2189f-15c33eafc9d4c587065046a26762fa07359aee0d.gz
Diffstat (limited to 'emms.el')
-rw-r--r--emms.el34
1 files changed, 34 insertions, 0 deletions
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