Michael Olson <[EMAIL PROTECTED]> writes: > With this, I'm noticing some (good) overlap between my custom setup > and emms-metaplaylist-mode. So I've got a couple of ideas that > aren't specific to emms-metaplaylist-mode, but would share a couple > of functions with it. > > [snip] > > What do you think? I've got code to do most of this already.
Here's a trial patch that works for me. Let me know what you think of it.
pgp3Tgd62yTOd.pgp
Description: PGP signature
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 "<mouse-2>") '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
;;; --------------------------------------------------------
-- Michael Olson -- FSF Associate Member #652 -- http://www.mwolson.org/ Interests: Emacs Lisp, text markup, protocols -- Muse, Planner, ERC, EMMS /` |\ | | | IRC: mwolson on freenode.net: #hcoop, #muse, #PurdueLUG |_] | \| |_| Jabber: mwolson_at_hcoop.net
_______________________________________________ Emms-help mailing list [email protected] http://lists.gnu.org/mailman/listinfo/emms-help
