diff options
author | william.xwl <william.xwl> | 2006-04-14 11:45:00 +0000 |
---|---|---|
committer | william.xwl <mwolson@gnu.org> | 2006-04-14 11:45:00 +0000 |
commit | df33a9de0b079846589ade4322fff4ae3bda16ce (patch) | |
tree | c7e6ff8dae6e2aea5c4289eccd1764c8c637b806 /emms-playlist-sort.el | |
parent | 38424da232f995ee42b0262a1dc891042ea55acf (diff) |
Added `emms-playlist-sort-by-natural-order'. Thanks to Matthew Kennedy
<mkennedy@gentoo.org>.
darcs-hash:20060414114543-e8fe6-c2c4b3e74d65da96ad36eb70c2aefaa742a52c27.gz
Diffstat (limited to 'emms-playlist-sort.el')
-rw-r--r-- | emms-playlist-sort.el | 24 |
1 files changed, 24 insertions, 0 deletions
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 |