diff options
author | Damien Elmes <emms@repose.cx> | 2006-06-18 12:25:00 +0000 |
---|---|---|
committer | Damien Elmes <emms@repose.cx> | 2006-06-18 12:25:00 +0000 |
commit | 8b5e7ce79e8b3f79d9c351ae756cac9be4fdf81a (patch) | |
tree | 871949247c41833055de0f5e82edca769fd8b517 | |
parent | f5c591cdd5ca4351f7ec5070206ba237506e8638 (diff) |
browser: bugfixes, sort/display by year
- fix a bug with add-and-play on a single file
- display album year if available
- sort albums first by year
- add c-1, c-2 etc keybindings to quickly browse by artist, album,
etc. (conflicts with standard keybindings - assumption is that
digit-argument is probably not very useful in the browser mode)
darcs-hash:20060618122507-4e3e3-d961861072a8a07e2f67b391c6f59b7ea1a79ac9.gz
-rw-r--r-- | emms-browser.el | 67 |
1 files changed, 56 insertions, 11 deletions
diff --git a/emms-browser.el b/emms-browser.el index 4e988bd..9b7c9db 100644 --- a/emms-browser.el +++ b/emms-browser.el @@ -126,6 +126,13 @@ Use nil for no sorting." :group 'emms-browser :type 'function) +(defcustom emms-browser-album-sort-function + 'emms-browser-sort-by-year-or-name + "*How to sort artists/albums/etc. in the browser. +Use nil for no sorting." + :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 @@ -168,6 +175,10 @@ Use nil for no sorting." (define-key map (kbd "2") 'emms-browser-expand-to-level-2) (define-key map (kbd "3") 'emms-browser-expand-to-level-3) (define-key map (kbd "4") 'emms-browser-expand-to-level-4) + (define-key map (kbd "C-1") 'emms-browse-by-artist) + (define-key map (kbd "C-2") 'emms-browse-by-album) + (define-key map (kbd "C-3") 'emms-browse-by-genre) + (define-key map (kbd "C-4") 'emms-browse-by-year) map) "Keymap for `emms-browser-mode'.") @@ -353,12 +364,12 @@ example function is `emms-browse-by-artist'." (define-hash-table-test 'case-fold 'case-fold-string= 'case-fold-string-hash) -(defun emms-browser-insert-top-level-entry (entry tracks type) +(defun emms-browser-insert-top-level-entry (name tracks type) "Insert a single top level entry into the buffer." (emms-browser-ensure-browser-buffer) (emms-with-inhibit-read-only-t (insert (emms-propertize - entry + name 'emms-browser-bdata (emms-browser-make-bdata-tree type 1 tracks) @@ -418,14 +429,21 @@ This uses `emms-browser-make-name-function'" (funcall emms-browser-make-name-function entry type)) (defun emms-browser-make-name-standard (entry type) - "Add track numbers to track names. -Apart from tracks, names are displayed without modification." + "The standard way of formating names in the browser. +Individual tracks are in the form 'tracknum. artist - title' +Albums are in the form '(year) album'." (let ((key (car entry)) - (track (cadr entry))) - (if (eq type 'info-title) - (concat (emms-browser-track-number track) - (emms-track-get track 'info-title)) - key))) + (track (cadr entry))) ;; only the first track + (cond + ((eq type 'info-title) + (concat (emms-browser-track-number track) + (emms-track-get track 'info-artist) + " - " + (emms-track-get track 'info-title))) + ((eq type 'info-album) + (concat (emms-browser-year-number track) + key)) + (t key)))) (defun emms-browser-track-number (track) "Return a string representation of a track number. @@ -440,6 +458,15 @@ return an empty string." tracknum) ". ")))) +(defun emms-browser-year-number (track) + "Return a string representation of a track's year. +This will be in the form '(1998) '." + (let ((year (emms-track-get track 'info-year))) + (if (or (not (stringp year)) (string= year "0")) + "" + (concat + "(" year ") ")))) + (defun emms-browser-make-bdata (data name type level) "Return a browser data item from ALIST. DATA should be a list of DB items, or a list of tracks. @@ -530,16 +557,32 @@ Uses `emms-browser-alpha-sort-function'." emms-browser-alpha-sort-function)) alist)) +(defun emms-browser-sort-by-year-or-name (alist) + "Sort based on year or name." + (sort alist (emms-browser-sort-cadr + 'emms-browser-sort-by-year-or-name-p))) + +(defun emms-browser-sort-by-year-or-name-p (a b) + ;; FIXME: this is a bit of a hack + (let ((a-desc (concat + (emms-browser-year-number a) + (emms-track-get a 'info-album "misc"))) + (b-desc (concat + (emms-browser-year-number b) + (emms-track-get b 'info-album "misc")))) + (string< a-desc b-desc))) + (defun emms-browser-sort-alist (alist type) "Sort ALIST using the sorting function for TYPE." (let ((sort-func (cond ((or - (eq type 'info-album) (eq type 'info-artist) (eq type 'info-year) (eq type 'info-genre)) 'emms-browser-sort-by-name) + ((eq type 'info-album) + emms-browser-album-sort-function) ((eq type 'info-title) 'emms-browser-sort-by-track) (t (message "Can't sort unknown mapping!"))))) @@ -724,7 +767,9 @@ LEVEL is used to control indentation." (emms-browser-add-tracks) (with-current-emms-playlist (goto-char old-pos) - (emms-playlist-next) + ;; if we're sitting on a group name, move forward + (unless (emms-playlist-track-at (point)) + (emms-playlist-next)) (emms-playlist-select (point))) ;; FIXME: is there a better way of doing this? (emms-stop) |