aboutsummaryrefslogtreecommitdiff
path: root/emms-playlist-sort.el
diff options
context:
space:
mode:
authorWilliam Xu <william.xwl@gmail.com>2006-12-25 05:45:00 +0000
committerWilliam Xu <william.xwl@gmail.com>2006-12-25 05:45:00 +0000
commit1a233b4d1611446ed6c89025b5dfce46fdf58e30 (patch)
tree36dd637898f00252869a4c9821220668ce78bb59 /emms-playlist-sort.el
parent4176ebe3d723201d3c3e0459fc94fe7331549519 (diff)
emms-playlist-sort.el: Reorganize codes && add `emms-playlist-sort-by-list'.
darcs-hash:20061225054559-cfa61-8735b162cb04410687f89dc778115cd4a0d516ca.gz
Diffstat (limited to 'emms-playlist-sort.el')
-rw-r--r--emms-playlist-sort.el65
1 files changed, 53 insertions, 12 deletions
diff --git a/emms-playlist-sort.el b/emms-playlist-sort.el
index 9f7285c..4cfea2b 100644
--- a/emms-playlist-sort.el
+++ b/emms-playlist-sort.el
@@ -33,8 +33,33 @@
(require 'emms-score)
-;;; sort macro
+;;; Customizations
+(defgroup emms-playlist-sort nil
+ "Sorting Emacs Multimedia System playlists."
+ :prefix "emms-playlist-sort-"
+ :group 'emms)
+
+;; FIXME, Should better avoid relying on setting before loading
+(defcustom emms-playlist-sort-prefix "S"
+ "Prefix key sequence for `emms-playlist-sort-map'.
+If you want to customize it, you must set this variable before
+loading `emms-playlist-sort'."
+ :type 'string
+ :group 'emms-playlist-sort)
+
+(defcustom emms-playlist-sort-list '(info-artist info-album)
+ "Sorting list used by `emms-playlist-sort-by-list'.
+Currently it understands the following fields: name info-artist
+info-title info-album info-genre info-playing-time
+info-tracknumber."
+ :type 'symbol
+ :group 'emms-playlist-sort)
+
+
+;;; Interfaces
+
+;; sort macro
(defmacro define-emms-playlist-sort (attribute)
"Macro for defining emms playlist sort functions."
`(defun ,(intern (format "emms-playlist-sort-by-%s" attribute)) ()
@@ -66,17 +91,12 @@ 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-"
- :group 'emms)
-
-;; FIXME: Should better avoid relying on setting before loading.
-(defcustom emms-playlist-sort-prefix "S"
- "*Prefix key sequence for `emms-playlist-sort-map'.
-You should set this variable before loading this file."
- :type 'string
- :group 'emms-playlist-sort)
+(defun emms-playlist-sort-by-list ()
+ "Sort emms playlist by `emms-playlist-sort-list'.
+The sort will be carried out until comparsion succeeds,
+increasingly."
+ (interactive)
+ (emms-playlist-sort 'emms-playlist-sort-by-list-p))
(defvar emms-playlist-sort-map
(let ((map (make-sparse-keymap)))
@@ -87,6 +107,7 @@ You should set this variable before loading this file."
(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)
+ (define-key map (kbd "l") 'emms-playlist-sort-by-list)
map))
(eval-after-load "emms-playlist-mode"
@@ -95,6 +116,9 @@ You should set this variable before loading this file."
emms-playlist-sort-prefix
emms-playlist-sort-map)))
+
+;;; Low Level
+
(defun emms-playlist-sort (predicate &optional start end)
"Sort the playlist buffer by PREDICATE.
If START and END are not provided, the whole buffer will be sorted."
@@ -135,6 +159,23 @@ ie. by album name and then by track number."
(string-to-number (or (emms-track-get b 'info-tracknumber)
"0"))))))
+(defun emms-playlist-sort-by-list-p (a b)
+ (catch 'return
+ (dolist (info emms-playlist-sort-list)
+ (case info
+ ((name info-artist info-title info-album info-genre)
+ (when (string< (emms-track-get a info)
+ (emms-track-get b info))
+ (throw 'return t)))
+ ((info-playing-time)
+ (when (< (emms-track-get a info)
+ (emms-track-get b info))
+ (throw 'return t)))
+ ((info-tracknumber)
+ (when (< (string-to-number (or (emms-track-get a info) "0"))
+ (string-to-number (or (emms-track-get b info) "0")))
+ (throw 'return t)))))))
+
(provide 'emms-playlist-sort)
;;; emms-playlist-sort.el ends here