diff options
| author | Damien Elmes <emms@repose.cx> | 2006-06-08 10:52:00 +0000 | 
|---|---|---|
| committer | Damien Elmes <emms@repose.cx> | 2006-06-08 10:52:00 +0000 | 
| commit | 01ba6d4850111dcc92d259ccaaff072458d40263 (patch) | |
| tree | 95685bb61852b28b644af7943dd39debcfa12944 | |
| parent | fdd132b103b3b62e51d0bda64eb60d4c3d9fcfa1 (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
| -rw-r--r-- | emms-browser.el | 33 | ||||
| -rw-r--r-- | emms-playlist-sort.el | 42 | 
2 files changed, 49 insertions, 26 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))) 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)  | 
