From 01ba6d4850111dcc92d259ccaaff072458d40263 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 8 Jun 2006 10:52:00 +0000 Subject: 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 --- emms-playlist-sort.el | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'emms-playlist-sort.el') diff --git a/emms-playlist-sort.el b/emms-playlist-sort.el index 7e01488..3b5dce5 100644 --- a/emms-playlist-sort.el +++ b/emms-playlist-sort.el @@ -94,26 +94,28 @@ You should set this variable before loading this file." emms-playlist-sort-prefix emms-playlist-sort-map))) -(defun emms-playlist-sort (predicate) - "Sort the whole playlist buffer by PREDICATE." - (with-current-emms-playlist - (save-excursion - (emms-playlist-ensure-playlist-buffer) - (widen) - (let ((current (emms-playlist-selected-track)) - (tracks (emms-playlist-tracks-in-region (point-min) - (point-max)))) - (delete-region (point-min) - (point-max)) - (run-hooks 'emms-playlist-cleared-hook) - (mapc 'emms-playlist-insert-track - (sort tracks predicate)) - (let ((pos (text-property-any (point-min) - (point-max) - 'emms-track current))) - (if pos - (emms-playlist-select pos) - (emms-playlist-first))))))) +(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." + (let ((run-cleared-hook nil)) + (unless start (setq start (point-min))) + (unless end (setq end (point-max))) + (with-current-emms-playlist + (save-excursion + (emms-playlist-ensure-playlist-buffer) + (widen) + (let ((current (emms-playlist-selected-track)) + (tracks + (emms-playlist-tracks-in-region start end))) + (delete-region start end) + (run-hooks 'emms-playlist-cleared-hook) + (mapc 'emms-playlist-insert-track + (sort tracks predicate)) + (let ((pos (text-property-any start end + 'emms-track current))) + (if pos + (emms-playlist-select pos) + (emms-playlist-first)))))))) (defun emms-string> (a b) (not (or (string< a b) -- cgit v1.2.3