emms-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emms-help] More sort functions?


From: William Xu
Subject: [emms-help] More sort functions?
Date: Wed, 05 Oct 2005 17:02:02 +0800
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

How about adding more playlist sort functions? Such as, sort by title,
artist, name, year, etc. In a word, i'd like a similar sort interface as
in `ibuffer'.

;; sort by title
(emms-sort-do (lambda (a b)
                (string< (emms-track-get a 'info-title)
                         (emms-track-get b 'info-title))))

;; sort by artist
(emms-sort-do (lambda (a b)
                (string< (emms-track-get a 'info-artist)
                         (emms-track-get b 'info-artist))))

(defun emms-sort-do (predicate)
  "Sort the whole playlist buffer by PREDICATE."
  (interactive)
  (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)))))))

Also, i'm trying to write sort of `(define-emms-source advanced-find
(dir attribute regex))', which allows me to find files matched by artist
or title, etc. But i met some difficulties in retrieving files' info,
since they were `later-do'. Any hints?

-- 
William




reply via email to

[Prev in Thread] Current Thread [Next in Thread]