diff options
author | Damien Elmes <emms@repose.cx> | 2006-06-23 14:28:00 +0000 |
---|---|---|
committer | Damien Elmes <emms@repose.cx> | 2006-06-23 14:28:00 +0000 |
commit | 32aa5c2203d7f63bf88c6853f2e2f42788eb3890 (patch) | |
tree | 037d1d0d4c6f1e0fea5bd0b6a115e22147abbb35 | |
parent | 4a174ab71e24c4459fdd015194041bf05f4b1ea1 (diff) |
browser: preliminary browsing support
darcs-hash:20060623142837-4e3e3-7397b81dc867876785cf43357bf18c8973e6b010.gz
-rw-r--r-- | emms-browser.el | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/emms-browser.el b/emms-browser.el index 5714352..7b5d737 100644 --- a/emms-browser.el +++ b/emms-browser.el @@ -163,6 +163,7 @@ Use nil for no sorting." (set-keymap-parent map text-mode-map) (define-key map (kbd "q") 'emms-browser-bury-buffer) (define-key map (kbd "/") 'emms-isearch-buffer) + (define-key map (kbd "s") 'emms-browser-search) (define-key map (kbd "?") 'describe-mode) (define-key map (kbd "C-/") 'emms-playlist-mode-undo) (define-key map (kbd "SPC") 'emms-browser-toggle-subitems) @@ -1027,5 +1028,63 @@ Returns the playlist window." ;; linked buffer (bury-buffer other-buf))) +;; -------------------------------------------------- +;; Searching +;; -------------------------------------------------- + + +(defun emms-browser-filter-cache (search-list) + "Return a list of tracks that match SEARCH-LIST. +SEARCH-LIST is a list of cons pairs, in the form: + + ((field1 field2) string) + +If string matches any of the fields in a cons pair, it will be +included." + + (let (tracks) + (maphash (lambda (k track) + (when (emms-browser-matches-p track search-list) + (push track tracks))) + emms-cache-db) + tracks)) + +(defun emms-browser-matches-p (track search-list) + (let (no-match matched) + (dolist (item search-list) + (setq matched nil) + (dolist (field (car item)) + (when (string-match (cadr item) + (emms-track-get track field "")) + (setq matched t))) + (unless matched + (setq no-match t))) + (not no-match))) + +(emms-browser-filter-cache '(((info-title) "requiem"))) + +(defun emms-browser-search-buffer-go () + (switch-to-buffer + (get-buffer-create "*emms-browser-search*")) + (emms-browser-mode)) + +(defun emms-browser-search (str) + (interactive "MSearch for: ") + (emms-browser-search-buffer-go) + (emms-browser-render-search + (emms-browser-filter-cache + (list (list '(info-artist info-title info-album) + str)))) + (emms-browser-expand-all) + (goto-char (point-min))) + +(defun emms-browser-render-search (tracks) + (let ((entries + (emms-browser-make-sorted-alist 'info-artist tracks))) + (dolist (entry entries) + (emms-browser-insert-top-level-entry (car entry) + (cdr entry) + 'info-artist)))) + (provide 'emms-browser) ;;; emms-browser.el ends here |