aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emms-metaplaylist-mode.el12
-rw-r--r--emms-playlist-mode.el41
-rw-r--r--emms.el25
3 files changed, 66 insertions, 12 deletions
diff --git a/emms-metaplaylist-mode.el b/emms-metaplaylist-mode.el
index 92a10b6..ecaa083 100644
--- a/emms-metaplaylist-mode.el
+++ b/emms-metaplaylist-mode.el
@@ -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 --git a/emms-playlist-mode.el b/emms-playlist-mode.el
index ff29a22..b35e9b3 100644
--- a/emms-playlist-mode.el
+++ b/emms-playlist-mode.el
@@ -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
;;; --------------------------------------------------------
@@ -117,10 +125,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'.")
@@ -167,6 +176,24 @@ FUN should be a function."
(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.
@@ -396,6 +423,18 @@ of the saved playlist inside."
(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
;;; --------------------------------------------------------
diff --git a/emms.el b/emms.el
index db71528..886c45d 100644
--- a/emms.el
+++ b/emms.el
@@ -542,6 +542,31 @@ If called interactively, the new buffer is also selected."
(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."