aboutsummaryrefslogtreecommitdiff
path: root/emms-playlist-sort.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-playlist-sort.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-playlist-sort.el')
-rw-r--r--emms-playlist-sort.el42
1 files changed, 22 insertions, 20 deletions
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)