aboutsummaryrefslogtreecommitdiff
path: root/emms-playlist-sort.el
diff options
context:
space:
mode:
Diffstat (limited to 'emms-playlist-sort.el')
-rw-r--r--emms-playlist-sort.el24
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