From fe75d2aac6312c97b4463b7bf86e459b25228dc4 Mon Sep 17 00:00:00 2001 From: "william.xwl" Date: Tue, 13 Dec 2005 13:15:00 +0000 Subject: Added `emms-playlist-sort-by-score'. darcs-hash:20051213131558-e8fe6-ee2bc9a6c1d608ede136b8ee814a56a2f21ccb55.gz --- emms-playlist-sort.el | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/emms-playlist-sort.el b/emms-playlist-sort.el index 6e7288d..ac8258c 100644 --- a/emms-playlist-sort.el +++ b/emms-playlist-sort.el @@ -31,12 +31,14 @@ ;;; Code: +(require 'emms-score) + ;;; sort macro (defmacro define-emms-playlist-sort (attribute) "Macro for defining emms playlist sort functions." `(defun ,(intern (format "emms-playlist-sort-by-%s" attribute)) () - ,(format "Sort emms playlist by %s." attribute) + ,(format "Sort emms playlist by %s, increasingly." attribute) (interactive) (emms-playlist-sort (lambda (a b) @@ -50,6 +52,14 @@ (define-emms-playlist-sort info-year) (define-emms-playlist-sort info-note) +(defun emms-playlist-sort-by-score () + "Sort emms playlist by score, decreasingly." + (interactive) + (emms-playlist-sort + (lambda (a b) + (> (emms-score-get-score (emms-track-get a 'name)) + (emms-score-get-score (emms-track-get b 'name)))))) + ;; FIXME: Should better avoid relying on setting before loading. (defcustom emms-playlist-sort-prefix "S" "*Prefix key sequence for `emms-playlist-sort-map'. @@ -66,9 +76,10 @@ You should set this variable before loading this file." (define-key map (kbd "o") 'emms-playlist-sort-by-info-note) map)) -(define-key emms-playlist-mode-map - emms-playlist-sort-prefix - emms-playlist-sort-map) +(eval-after-load "emms-playlist-sort.el" + (define-key emms-playlist-mode-map + emms-playlist-sort-prefix + emms-playlist-sort-map)) (defun emms-playlist-sort (predicate) "Sort the whole playlist buffer by PREDICATE." @@ -91,7 +102,6 @@ You should set this variable before loading this file." (emms-playlist-select pos) (emms-playlist-first))))))) - (provide 'emms-playlist-sort) ;;; emms-playlist-sort.el ends here -- cgit v1.2.3