aboutsummaryrefslogtreecommitdiff
path: root/emms.el
diff options
context:
space:
mode:
authorYe Wenbin <wenbinye@gmail.com>2006-12-07 06:35:00 +0000
committerYe Wenbin <wenbinye@gmail.com>2006-12-07 06:35:00 +0000
commitea35b0637aff4d1f61dac2d25b6556a4d939e6b4 (patch)
tree6fb4ef53684159f72de480d88a2950673b199794 /emms.el
parentd87cd1c3112c9e916fc71fd41721726709cae7c0 (diff)
emms-i18n changes, add playlist navigate command, uniq playlist command
darcs-hash:20061207063510-94065-7726a0fc26d04c70038d5576a0a1451e7e71e368.gz
Diffstat (limited to 'emms.el')
-rw-r--r--emms.el42
1 files changed, 42 insertions, 0 deletions
diff --git a/emms.el b/emms.el
index 8ed1de9..89c57ba 100644
--- a/emms.el
+++ b/emms.el
@@ -110,6 +110,11 @@ songs, increase this number."
:type 'function
:group 'emms)
+(defcustom emms-playlist-uniq-function 'emms-playlist-simple-uniq
+ "*The function to use for make track uniq in the playlist."
+ :type 'function
+ :group 'emms)
+
(defcustom emms-sort-lessp-function 'emms-sort-track-name-less-p
"*Function for comparing two EMMS tracks.
The function should return non-nil if and only if the first track
@@ -416,6 +421,14 @@ This uses `emms-playlist-sort-function'."
(save-excursion
(funcall emms-playlist-sort-function))))
+(defun emms-uniq ()
+ "Uniq the current playlist.
+This uses `emms-playlist-uniq-function'."
+ (interactive)
+ (with-current-emms-playlist
+ (save-excursion
+ (funcall emms-playlist-uniq-function))))
+
(defun emms-toggle-repeat-playlist ()
"Toggle whether emms repeats the playlist after it is done.
See `emms-repeat-playlist'."
@@ -1091,6 +1104,35 @@ ignore this."
(emms-playlist-select pos)
(emms-playlist-first)))))
+(defun emms-uniq-list (list stringfy)
+ "Compare stringfied element of list, and remove duplicate elements."
+ (let ((hash (make-hash-table :test 'equal))
+ str)
+ (remove-if (lambda (elm)
+ (setq str (funcall stringfy elm))
+ (if (gethash str hash) t
+ (puthash str t hash) nil)) list)))
+
+(defun emms-playlist-simple-uniq ()
+ "Remove duplicate tracks"
+ (emms-playlist-ensure-playlist-buffer)
+ (widen)
+ (let ((inhibit-read-only t)
+ (current (emms-playlist-selected-track))
+ (tracks (emms-playlist-tracks-in-region (point-min)
+ (point-max))))
+ (delete-region (point-min) (point-max))
+ (run-hooks 'emms-playlist-cleared-hook)
+ (mapc 'emms-playlist-insert-track
+ (nreverse
+ (emms-uniq-list tracks 'emms-track-name)))
+ (let ((pos (text-property-any (point-min)
+ (point-max)
+ 'emms-track current)))
+ (if pos
+ (emms-playlist-select pos)
+ (emms-playlist-first)))))
+
;;; Helper functions
(defun emms-property-region (pos prop)
"Return a pair of the beginning and end of the property PROP at POS.