From df33a9de0b079846589ade4322fff4ae3bda16ce Mon Sep 17 00:00:00 2001 From: "william.xwl" Date: Fri, 14 Apr 2006 11:45:00 +0000 Subject: Added `emms-playlist-sort-by-natural-order'. Thanks to Matthew Kennedy . darcs-hash:20060414114543-e8fe6-c2c4b3e74d65da96ad36eb70c2aefaa742a52c27.gz --- emms-playlist-sort.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/emms-playlist-sort.el b/emms-playlist-sort.el index 8956623..7e01488 100644 --- a/emms-playlist-sort.el +++ b/emms-playlist-sort.el @@ -59,6 +59,12 @@ (> (emms-score-get-score (emms-track-get a 'name)) (emms-score-get-score (emms-track-get b 'name)))))) +(defun emms-playlist-sort-by-natural-order () + "Sort emms playlist by natural order. +See `emms-sort-natural-order-less-p'." + (interactive) + (emms-playlist-sort 'emms-sort-natural-order-less-p)) + (defgroup emms-playlist-sort nil "*Sorting Emacs Multimedia System playlists." :prefix "emms-playlist-sort-" @@ -79,6 +85,7 @@ You should set this variable before loading this file." (define-key map (kbd "b") 'emms-playlist-sort-by-info-album) (define-key map (kbd "y") 'emms-playlist-sort-by-info-year) (define-key map (kbd "o") 'emms-playlist-sort-by-info-note) + (define-key map (kbd "N") 'emms-playlist-sort-by-natural-order) map)) (eval-after-load "emms-playlist-mode" @@ -108,6 +115,23 @@ You should set this variable before loading this file." (emms-playlist-select pos) (emms-playlist-first))))))) +(defun emms-string> (a b) + (not (or (string< a b) + (string= a b)))) + +(defun emms-sort-natural-order-less-p (a b) + "Sort two tracks by natural order. +This is the order in which albums where intended to be played. +ie. by album name and then by track number." + (or (emms-string> (emms-track-get a 'info-album) + (emms-track-get b 'info-album)) + (and (string= (emms-track-get a 'info-album) + (emms-track-get b 'info-album)) + (< (string-to-number (or (emms-track-get a 'info-tracknumber) + "0")) + (string-to-number (or (emms-track-get b 'info-tracknumber) + "0")))))) + (provide 'emms-playlist-sort) ;;; emms-playlist-sort.el ends here -- cgit v1.2.3