aboutsummaryrefslogtreecommitdiff
path: root/emms.el
diff options
context:
space:
mode:
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.