diff -rN -u old-emms2/emms.el new-emms2/emms.el --- old-emms2/emms.el 2006-04-21 21:09:37.000000000 -0400 +++ new-emms2/emms.el 2006-04-21 21:09:37.000000000 -0400 @@ -542,6 +542,31 @@ (switch-to-buffer buf)) buf)) +(defun emms-playlist-buffer-list () + "Return a list of EMMS playlist buffers. +The first element will be the most recently-created playlist, and +so on." + (let ((lis nil)) + (mapc (lambda (buf) + (with-current-buffer buf + (when emms-playlist-buffer-p + (setq lis (cons buf lis))))) + (buffer-list)) + (nreverse lis))) + +(defun emms-playlist-current-kill () + "Kill the current EMMS playlist buffer and switch to the next one." + (interactive) + (let ((new (cadr (emms-playlist-buffer-list)))) + (if new + (progn + (when (buffer-live-p emms-playlist-buffer) + (kill-buffer emms-playlist-buffer)) + (setq emms-playlist-buffer new) + (switch-to-buffer emms-playlist-buffer)) + (with-current-buffer emms-playlist-buffer + (bury-buffer))))) + (defun emms-playlist-current-clear () "Clear the current playlist. If no current playlist exists, a new one is generated." @@ -563,7 +588,7 @@ (point-max))) (run-hooks 'emms-playlist-cleared-hook)) -(defmacro with-widened-buffer (&rest body) +(defmacro emms-with-widened-buffer (&rest body) `(save-restriction (widen) ,@body)) @@ -572,7 +597,7 @@ (defun emms-playlist-track-at (&optional pos) "Return the track at POS (point if not given), or nil if none." (emms-playlist-ensure-playlist-buffer) - (with-widened-buffer + (emms-with-widened-buffer (get-text-property (or pos (point)) 'emms-track))) diff -rN -u old-emms2/emms-metaplaylist-mode.el new-emms2/emms-metaplaylist-mode.el --- old-emms2/emms-metaplaylist-mode.el 2006-04-21 21:09:37.000000000 -0400 +++ new-emms2/emms-metaplaylist-mode.el 2006-04-21 21:09:37.000000000 -0400 @@ -97,23 +97,13 @@ (buffer-substring (point-at-bol) (point-at-eol)))) -(defun get-emms-playlist-buffers () - "Return a list of EMMS playlist buffers." - (let ((lis nil)) - (mapc (lambda (buf) - (with-current-buffer buf - (when emms-playlist-buffer-p - (setq lis (cons buf lis))))) - (buffer-list)) - lis)) - ;; Since there will never be a significantly large amount of playlist ;; buffers co-existing at once, we allow ourselves not to keep ;; state. We regenerate the playlists buffer anew on demand. (defun emms-metaplaylist-mode-create () "Create or recreate the meta-playlist buffer." (let ((name emms-metaplaylist-mode-buffer-name) - (playlists (get-emms-playlist-buffers))) + (playlists (emms-playlist-buffer-list))) (if playlists (progn (condition-case nil diff -rN -u old-emms2/emms-playlist-mode.el new-emms2/emms-playlist-mode.el --- old-emms2/emms-playlist-mode.el 2006-04-21 21:09:37.000000000 -0400 +++ new-emms2/emms-playlist-mode.el 2006-04-21 21:09:37.000000000 -0400 @@ -38,6 +38,7 @@ (condition-case nil (require 'overlay) (error nil))) +(require 'emms-source-playlist) (defvar emms-playlist-mode-hook nil "Emms playlist mode hook.") @@ -66,6 +67,13 @@ :prefix "emms-playlist-mode-" :group 'emms) +(defcustom emms-playlist-mode-open-playlists nil + "*Determine whether to open playlists in a new EMMS buffer on RET. +This is useful if you have a master playlist buffer that is +composed of other playlists." + :type 'boolean + :group 'emms-playlist-mode) + ;;; -------------------------------------------------------- ;;; Faces ;;; -------------------------------------------------------- @@ -113,10 +121,11 @@ (define-key map (kbd "f") 'emms-show) (define-key map (kbd "c") 'emms-playlist-mode-center-current) (define-key map (kbd "q") 'bury-buffer) + (define-key map (kbd "k") 'emms-playlist-current-kill) (define-key map (kbd "?") 'describe-mode) (define-key map (kbd "r") 'emms-random) (define-key map (kbd "") 'emms-playlist-mode-play-current-track) - (define-key map (kbd "RET") 'emms-playlist-mode-play-current-track) + (define-key map (kbd "RET") 'emms-playlist-mode-play-dtrt) map) "Keymap for `emms-playlist-mode'.") @@ -163,6 +172,24 @@ (emms-stop)) (emms-start)) +(defun emms-playlist-mode-play-dtrt () + "Determine the best operation to take on the current track. + +If on a playlist, and `emms-playlist-mode-open-playlists' is +non-nil, load the playlist at point into a new buffer. + +Otherwise play the track immediately." + (interactive) + (if (not emms-playlist-mode-open-playlists) + (emms-playlist-mode-play-current-track) + (let* ((track (emms-playlist-track-at)) + (name (emms-track-get track 'name)) + (type (emms-track-get track 'type))) + (if (or (eq type 'playlist) + (string-match "\\.\\(m3u\\|pls\\)\\'" name)) + (emms-playlist-mode-load-playlist) + (emms-playlist-mode-play-current-track))))) + (defun emms-playlist-mode-switch-buffer () "Switch to the playlist buffer and then switch back if called again. @@ -392,6 +419,18 @@ (emms-playlist-select (point)) (switch-to-buffer (current-buffer))))) +(defun emms-playlist-mode-load-playlist () + "Load the playlist into a new EMMS buffer. +This preserves the current EMMS buffer." + (interactive) + (let* ((track (emms-playlist-track-at)) + (name (emms-track-get track 'name)) + (type (emms-track-get track 'type))) + (emms-playlist-select (point)) + (run-hooks 'emms-player-stopped-hook) + (switch-to-buffer (setq emms-playlist-buffer (emms-playlist-new))) + (emms-add-playlist name))) + ;;; -------------------------------------------------------- ;;; Local functions ;;; --------------------------------------------------------