aboutsummaryrefslogtreecommitdiff
path: root/emms-browser.el
diff options
context:
space:
mode:
authorDamien Elmes <emms@repose.cx>2006-06-08 10:52:00 +0000
committerDamien Elmes <emms@repose.cx>2006-06-08 10:52:00 +0000
commit01ba6d4850111dcc92d259ccaaff072458d40263 (patch)
tree95685bb61852b28b644af7943dd39debcfa12944 /emms-browser.el
parentfdd132b103b3b62e51d0bda64eb60d4c3d9fcfa1 (diff)
browser sorting, and bug fixes
- sort tracks when they're added to the playlist - fix a bug where we didn't uniquify the buffer - distinguish between files and urls - modify emms-playlist-sort to accept an optional region darcs-hash:20060608105253-4e3e3-d735756c02bcae5a7c2e8a9b97817cf393a58079.gz
Diffstat (limited to 'emms-browser.el')
-rw-r--r--emms-browser.el33
1 files changed, 27 insertions, 6 deletions
diff --git a/emms-browser.el b/emms-browser.el
index 181ec6a..888899c 100644
--- a/emms-browser.el
+++ b/emms-browser.el
@@ -83,6 +83,13 @@ The default is to compare case-insensitively."
:group 'emms-browser
:type 'symbol)
+(defcustom emms-browser-sort-function
+ 'emms-sort-natural-order-less-p
+ "How to sort tracks from the browser (nil for no sorting).
+This is used to sort tracks when they are added to the playlist."
+ :group 'emms-browser
+ :type 'function)
+
(defcustom emms-browser-show-display-hook nil
"Hooks to run when starting or switching to a browser buffer."
:group 'emms-browser
@@ -138,12 +145,12 @@ The default is to compare case-insensitively."
"Launch or switch to the EMMS Browser."
(interactive)
(if (or (null emms-browser-buffer)
- (not (buffer-live-p emms-browser-buffer)))
+ (not (buffer-live-p emms-browser-buffer)))
(progn
(setq emms-browser-buffer (emms-browser-new-buffer name))
(funcall emms-browser-default-browsing-function))
(when name
- (rename-buffer name)))
+ (rename-buffer name t)))
;; if the buffer is displayed, switch the window instead
(let ((wind (get-buffer-window emms-browser-buffer)))
(if wind
@@ -263,15 +270,29 @@ If called interactively, the new buffer is also selected."
(defun emms-browser-add-tracks ()
"Add all the tracks on the current line to the playlist."
(interactive)
- ;; display the bottom of the current playlist
(let ((tracks (emms-browser-tracks-at))
- (count 0))
+ (count 0)
+ old-max new-max type name)
(unless tracks
(error "No tracks on current line!"))
+ (with-current-emms-playlist
+ (setq old-max (point-max)))
+ ;; add each of the tracks
(dolist (track tracks)
- ;; FIXME: assumes 'file type
- (emms-add-file (emms-track-get track 'name))
+ (setq type (emms-track-get track 'type))
+ (setq name (emms-track-get track 'name))
+ (cond
+ ((eq type 'file)
+ (emms-add-file name))
+ ((eq type 'url)
+ (emms-add-url name)))
(setq count (1+ count)))
+ ;; sort
+ (when emms-browser-sort-function
+ (with-current-emms-playlist
+ (setq new-max (point-max)))
+ (emms-playlist-sort 'emms-sort-natural-order-less-p
+ old-max new-max))
(run-mode-hooks 'emms-browser-tracks-added-hook)
(message "Added %d tracks." count)))