diff options
author | William Xu <william.xwl@gmail.com> | 2007-07-05 16:02:00 +0000 |
---|---|---|
committer | William Xu <william.xwl@gmail.com> | 2007-07-05 16:02:00 +0000 |
commit | 3b6c9a35fafca4eaa9ad5896ffae782ed2348e10 (patch) | |
tree | 369efe1cb625e0d283db39a46bc2442eee45b81f | |
parent | 2662277d79bd1ac1f4b376f0f1486c8731017931 (diff) |
New file: emms-playlist-limit.el. And minor updates to emms-playlist-sort.
darcs-hash:20070705160221-cfa61-c16a2727863237aa851657d35705cd8cbfed3145.gz
-rw-r--r-- | emms-playlist-limit.el | 129 | ||||
-rw-r--r-- | emms-playlist-sort.el | 37 | ||||
-rw-r--r-- | emms-setup.el | 4 |
3 files changed, 150 insertions, 20 deletions
diff --git a/emms-playlist-limit.el b/emms-playlist-limit.el new file mode 100644 index 0000000..7e5609c --- /dev/null +++ b/emms-playlist-limit.el @@ -0,0 +1,129 @@ +;;; emms-playlist-limit.el --- limit playlist by various info + +;; Copyright (C) 2007 William Xu + +;; Author: William Xu <william.xwl@gmail.com> +;; Keywords: emms, limit + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program; if not, write to the Free Software +;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +;; 02110-1301 USA + +;;; Code: + +(require 'emms-playlist-mode) + +;;; User Interfacs + +;;;###autoload +(defun emms-playlist-limit (arg) + "Turn on emms limit if ARG is positive, off otherwise." + (interactive "p") + (if (and arg (> arg 0)) + (add-hook 'emms-playlist-source-inserted-hook + 'emms-playlist-limit-update-tracks) + (remove-hook 'emms-playlist-source-inserted-hook + 'emms-playlist-limit-update-tracks))) + +(define-key emms-playlist-mode-map (kbd "/ n") 'emms-playlist-limit-to-name) +(define-key emms-playlist-mode-map (kbd "/ a") 'emms-playlist-limit-to-info-artist) +(define-key emms-playlist-mode-map (kbd "/ t") 'emms-playlist-limit-to-info-title) +(define-key emms-playlist-mode-map (kbd "/ b") 'emms-playlist-limit-to-info-album) +(define-key emms-playlist-mode-map (kbd "/ y") 'emms-playlist-limit-to-info-year) +(define-key emms-playlist-mode-map (kbd "/ g") 'emms-playlist-limit-to-info-genre) +(define-key emms-playlist-mode-map (kbd "/ /") 'emms-playlist-limit-to-all) + +(defun emms-playlist-limit-to-info-artist (regexp) + "Limit to playlists that have artist that matches REGEXP." + (interactive "sLimit to artist (regexp): ") + (emms-playlist-limit-do 'info-artist regexp)) + +(defun emms-playlist-limit-to-info-album (regexp) + "Limit to playlists that have album that matches REGEXP." + (interactive "sLimit to album (regexp): ") + (emms-playlist-limit-do 'info-album regexp)) + +(defun emms-playlist-limit-to-info-title (regexp) + "Limit to playlists that have title that matches REGEXP." + (interactive "sLimit to title (regexp): ") + (emms-playlist-limit-do 'info-title regexp)) + +(defun emms-playlist-limit-to-info-year (regexp) + "Limit to playlists that have year that matches REGEXP." + (interactive "sLimit to year (regexp): ") + (emms-playlist-limit-do 'info-year regexp)) + +(defun emms-playlist-limit-to-info-genre (regexp) + "Limit to playlists that have genre that matches REGEXP." + (interactive "sLimit to genre (regexp): ") + (emms-playlist-limit-do 'info-genre regexp)) + +(defun emms-playlist-limit-to-name (regexp) + "Limit to playlists that have name that matches REGEXP." + (interactive "sLimit to name (regexp): ") + (emms-playlist-limit-do 'name regexp)) + +(defun emms-playlist-limit-to-all () + "Show all tracks again." + (interactive) + (emms-playlist-limit-do nil nil)) + + +;;; Low Level Functions + +(defvar emms-playlist-limit-tracks nil + "All tracks in playlist buffer.") + +(defun emms-playlist-limit-update-tracks () + "Update `emms-playlist-limit-tracks'." + (setq emms-playlist-limit-tracks + (append emms-playlist-limit-tracks + (emms-playlist-tracks-in-region + (point-min) (point-max))))) + +(defun emms-playlist-limit-do (name value) + "Limit by NAME with VALUE. +e.g., + (emms-playlist-limit-do 'info-artist \"Jane Zhang\") + +When NAME is nil, show all tracks again. + +See `emms-info-mp3find-arguments' for possible options." + (with-current-emms-playlist + (save-excursion + (emms-playlist-ensure-playlist-buffer) + (let ((curr (emms-playlist-current-selected-track)) + (tracks + (emms-playlist-tracks-in-region (point-min) (point-max)))) + (erase-buffer) + (run-hooks 'emms-playlist-cleared-hook) + (if name + (mapc (lambda (track) + (let ((track-value (emms-track-get track name))) + (when (and track-value (string-match value track-value)) + (emms-playlist-insert-track track)))) + tracks) + (mapc (lambda (track) + (emms-playlist-insert-track track)) + emms-playlist-limit-tracks)) + (let ((pos (text-property-any (point-min) (point-max) + 'emms-track curr))) + (if pos + (emms-playlist-select pos) + (emms-playlist-first))))))) + + +(provide 'emms-playlist-limit) + +;;; emms-playlist-limit.el ends here diff --git a/emms-playlist-sort.el b/emms-playlist-sort.el index 0600b0a..0af3fb3 100644 --- a/emms-playlist-sort.el +++ b/emms-playlist-sort.el @@ -124,25 +124,24 @@ increasingly." (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)))))))) + (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 (emms-string< a b) diff --git a/emms-setup.el b/emms-setup.el index 1ed1dd0..c642482 100644 --- a/emms-setup.el +++ b/emms-setup.el @@ -131,8 +131,10 @@ on the edge." (require 'emms-i18n) (require 'emms-tag-editor) (require 'emms-volume) + (require 'emms-playlist-limit) ;; setup - (add-hook 'emms-player-started-hook 'emms-last-played-update-current)) + (add-hook 'emms-player-started-hook 'emms-last-played-update-current) + (emms-playlist-limit 1)) ;;;###autoload |