aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorforcer <forcer>2005-09-18 13:48:00 +0000
committerforcer <mwolson@gnu.org>2005-09-18 13:48:00 +0000
commitd0efdf999ea41be893b19228b6d0e1c72b9d00d1 (patch)
tree546336c44d8111f2ef54936597ab2b41456e63f9
parent90cc6addbe21ee379366536fc5ece6cf942fb63a (diff)
Big renaming for current buffer/current playlist distinction.
All playlist functions which work on the current playlist now are named `emms-playlist-current-...'. Other functions named `emms-playlist-...' work on the current buffer. This affects the following functions: emms-playlist-clear => emms-playlist-current-clear emms-playlist-selected-track => emms-playlist-current-selected-track emms-playlist-select-next => emms-playlist-current-select-next emms-playlist-select-previous => emms-playlist-current-select-previous emms-playlist-select-random => emms-playlist-current-select-random emms-playlist-select-first => emms-playlist-current-select-first emms-playlist-select-last => emms-playlist-current-select-last emms-playlist-insert-source => emms-playlist-current-insert-source darcs-hash:20050918134805-2189f-2f7c0f1b4828e5438f15906b7a15959b28c97760.gz
-rw-r--r--emms.el369
1 files changed, 215 insertions, 154 deletions
diff --git a/emms.el b/emms.el
index 19e19e4..419c454 100644
--- a/emms.el
+++ b/emms.el
@@ -209,7 +209,7 @@ seconds the player did seek."
"Start playing the current track in the EMMS playlist."
(interactive)
(unless emms-player-playing-p
- (emms-player-start (emms-playlist-selected-track))))
+ (emms-player-start (emms-playlist-current-selected-track))))
(defun emms-stop ()
"Stop any current EMMS playback."
@@ -224,7 +224,7 @@ so use `emms-next-noerror' in that case."
(interactive)
(when emms-player-playing-p
(emms-stop))
- (emms-playlist-select-next)
+ (emms-playlist-current-select-next)
(emms-start))
(defun emms-next-noerror ()
@@ -240,7 +240,7 @@ This is a good function to put in `emms-player-finished-hook'."
(emms-start))
((condition-case nil
(progn
- (emms-playlist-select-next)
+ (emms-playlist-current-select-next)
t)
(error nil))
(emms-start))
@@ -252,7 +252,7 @@ This is a good function to put in `emms-player-finished-hook'."
(interactive)
(when emms-player-playing-p
(emms-stop))
- (emms-playlist-select-previous)
+ (emms-playlist-current-select-previous)
(emms-start))
(defun emms-random ()
@@ -295,8 +295,9 @@ If INSERTP is non-nil, insert the description into the current buffer instead.
This function uses `emms-show-format' to format the current track."
(interactive "P")
(let ((string (if emms-player-playing-p
- (format emms-show-format (emms-track-description
- (emms-playlist-selected-track)))
+ (format emms-show-format
+ (emms-track-description
+ (emms-playlist-current-selected-track)))
"Nothing playing right now")))
(if insertp
(insert string)
@@ -412,9 +413,25 @@ Otherwise, return the type and the name with a colon in between."
"Non-nil when the current buffer is an EMMS playlist.")
(make-variable-buffer-local 'emms-playlist-buffer-p)
+(defun emms-playlist-ensure-playlist-buffer ()
+ "Throw an error if we're on in a playlist-buffer."
+ (when (not emms-playlist-buffer-p)
+ (error "Not an EMMS playlist buffer")))
+
+(defmacro with-current-emms-playlist (&rest body)
+ "Run BODY with the current buffer being the current playlist buffer."
+ `(progn
+ (when (or (not emms-playlist-buffer)
+ (not (buffer-live-p emms-playlist-buffer)))
+ (emms-playlist-current-clear))
+ (with-current-buffer emms-playlist-buffer
+ ,@body)))
+(put 'with-current-emms-playlist 'lisp-indent-function 0)
+
(defun emms-playlist-set-playlist-buffer (&optional buffer)
"Set the current playlist buffer."
(interactive "bNew playlist buffer: ")
+ (emms-playlist-ensure-playlist-buffer)
(setq emms-playlist-buffer (or (get-buffer buffer)
(current-buffer))))
@@ -434,100 +451,36 @@ If called interactively, the new buffer is also selected."
(switch-to-buffer buf))
buf))
-(defun emms-playlist-clear ()
+(defun emms-playlist-current-clear ()
"Clear the current playlist.
-If no playlist exists, a new one is generated."
+If no current playlist exists, a new one is generated."
(if (or (not emms-playlist-buffer)
(not (buffer-live-p emms-playlist-buffer)))
(setq emms-playlist-buffer (emms-playlist-new))
(with-current-buffer emms-playlist-buffer
- (let ((inhibit-read-only t))
+ (emms-playlist-clear))))
+
+(defun emms-playlist-clear ()
+ "Clear the current buffer.
+If no playlist exists, a new one is generated."
+ (emms-playlist-ensure-playlist-buffer)
+ (let ((inhibit-read-only t))
(widen)
(delete-region (point-min)
(point-max)))
- (run-hooks 'emms-playlist-cleared-hook))))
-
-(defmacro with-current-emms-playlist (&rest body)
- "Run BODY with the current buffer being the current playlist buffer."
- `(progn
- (when (or (not emms-playlist-buffer)
- (not (buffer-live-p emms-playlist-buffer)))
- (emms-playlist-clear))
- (with-current-buffer emms-playlist-buffer
- ,@body)))
-(put 'with-current-emms-playlist 'lisp-indent-function 0)
-
-;;; Saving playlists.
-
-(defun emms-playlist-save (playlist filename)
- "Save a playlist in the native EMMS format."
- (interactive "bPlaylist buffer name: \nFFile to save playlist as: ")
- (let ((tracklist '()))
- (condition-case nil
- (with-current-buffer playlist
- (save-excursion
- (emms-playlist-first)
- (while (emms-playlist-track-at)
- (setq tracklist (cons (emms-playlist-track-at)
- tracklist))
- (emms-playlist-next))))
- (error nil))
- (setq tracklist (nreverse tracklist))
- ;; tracklist complete, let's write it !
- (with-current-buffer (find-file-noselect filename)
- (erase-buffer)
- (prin1 tracklist (current-buffer))
- (insert "\n")
- (save-buffer)
- (kill-buffer (current-buffer)))))
-
-(defun emms-playlist-save-active (filename)
- "Save the active EMMS playlist in native format."
- (interactive "FFile to save playlist as: ")
- (emms-playlist-save emms-playlist-buffer filename))
-
-(defun emms-playlist-save-as-m3u (playlist filename)
- "Save a playlist in .m3u format."
- (interactive "bPlaylist buffer name: \nFFile to save playlist as: ")
- (let ((tracklist '()))
- (condition-case nil
- (with-current-buffer playlist
- (save-excursion
- (emms-playlist-first)
- (while (emms-playlist-track-at)
- (setq tracklist (cons (emms-playlist-track-at)
- tracklist))
- (emms-playlist-next))))
- (error nil))
- (setq tracklist (nreverse tracklist))
- ;; tracklist complete, let's write it !
- (with-current-buffer (find-file-noselect filename)
- (erase-buffer)
- (insert "#EXTM3U\n")
- (mapc (lambda (track)
- (let ((info (emms-info-get track)))
- (insert "#EXTINF:")
- (insert (emms-info-playing-time info) ",")
- (insert (emms-info-artist info) " - " (emms-info-title info) "\n")
- (insert (emms-track-get track 'name) "\n")))
- tracklist)
- (save-buffer)
- (kill-buffer (current-buffer)))))
-
-(defun emms-playlist-save-active-as-m3u (filename)
- "Save the active EMMS playlist in m3u format."
- (interactive "FFile to save playlist as: ")
- (emms-playlist-save-as-m3u emms-playlist-buffer filename))
+ (run-hooks 'emms-playlist-cleared-hook))
;;; Point movement within the playlist buffer.
(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)
(get-text-property (or pos (point))
'emms-track))
(defun emms-playlist-next ()
"Move to the next track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
(let ((next (next-single-property-change (point)
'emms-track)))
(when (not next)
@@ -541,6 +494,7 @@ If no playlist exists, a new one is generated."
(defun emms-playlist-previous ()
"Move to the previous track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
(let ((prev (previous-single-property-change (point)
'emms-track)))
(when (not prev)
@@ -555,6 +509,7 @@ If no playlist exists, a new one is generated."
(defun emms-playlist-first ()
"Move to the first track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
(let ((first (condition-case nil
(save-excursion
(goto-char (point-min))
@@ -569,6 +524,7 @@ If no playlist exists, a new one is generated."
(defun emms-playlist-last ()
"Move to the last track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
(let ((last (condition-case nil
(save-excursion
(goto-char (point-max))
@@ -582,17 +538,24 @@ If no playlist exists, a new one is generated."
(defun emms-playlist-delete-track ()
"Delete the track at point."
+ (emms-playlist-ensure-playlist-buffer)
(funcall emms-playlist-delete-track-function))
;;; Track selection
(defun emms-playlist-selected-track ()
"Return the currently selected track."
+ (emms-playlist-ensure-playlist-buffer)
+ (when emms-playlist-selected-marker
+ (emms-playlist-track-at emms-playlist-selected-marker)))
+
+(defun emms-playlist-current-selected-track ()
+ "Return the currently selected track in the current playlist."
(with-current-emms-playlist
- (when emms-playlist-selected-marker
- (emms-playlist-track-at emms-playlist-selected-marker))))
+ (emms-playlist-selected-track)))
(defun emms-playlist-select (pos)
"Select the track at POS."
+ (emms-playlist-ensure-playlist-buffer)
(when (not (emms-playlist-track-at pos))
(error "No track at position %s" pos))
(when (not emms-playlist-selected-marker)
@@ -601,103 +564,136 @@ If no playlist exists, a new one is generated."
(run-hooks 'emms-playlist-selection-changed-hook))
(defun emms-playlist-select-next ()
- "Select the next track in the playlist."
+ "Select the next track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
+ (save-excursion
+ (goto-char (if (and emms-playlist-selected-marker
+ (marker-position emms-playlist-selected-marker))
+ emms-playlist-selected-marker
+ (point-min)))
+ (condition-case nil
+ (progn
+ (if emms-repeat-playlist
+ (condition-case nil
+ (emms-playlist-next)
+ (error
+ (emms-playlist-first)))
+ (emms-playlist-next))
+ (emms-playlist-select (point)))
+ (error
+ (error "No next track in playlist")))))
+
+(defun emms-playlist-current-select-next ()
+ "Select the next track in the current playlist."
(with-current-emms-playlist
- (save-excursion
- (goto-char (if (and emms-playlist-selected-marker
- (marker-position emms-playlist-selected-marker))
- emms-playlist-selected-marker
- (point-min)))
- (condition-case nil
- (progn
- (if emms-repeat-playlist
- (condition-case nil
- (emms-playlist-next)
- (error
- (emms-playlist-first)))
- (emms-playlist-next))
- (emms-playlist-select (point)))
- (error
- (error "No next track in playlist"))))))
+ (emms-playlist-select-next)))
(defun emms-playlist-select-previous ()
- "Select the previous track in the playlist."
+ "Select the previous track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
+ (save-excursion
+ (goto-char (if (and emms-playlist-selected-marker
+ (marker-position emms-playlist-selected-marker))
+ emms-playlist-selected-marker
+ (point-max)))
+ (condition-case nil
+ (progn
+ (if emms-repeat-playlist
+ (condition-case nil
+ (emms-playlist-previous)
+ (error
+ (emms-playlist-last)))
+ (emms-playlist-previous))
+ (emms-playlist-select (point)))
+ (error
+ (error "No previous track in playlist")))))
+
+(defun emms-playlist-current-select-previous ()
+ "Select the previous track in the current playlist."
(with-current-emms-playlist
- (save-excursion
- (goto-char (if (and emms-playlist-selected-marker
- (marker-position emms-playlist-selected-marker))
- emms-playlist-selected-marker
- (point-max)))
+ (emms-playlist-select-previous)))
+
+(defun emms-playlist-select-random ()
+ "Select a random track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
+ ;; FIXME: This is rather inefficient.
+ (save-excursion
+ (let ((track-indices nil)
+ (donep nil))
(condition-case nil
(progn
- (if emms-repeat-playlist
- (condition-case nil
- (emms-playlist-previous)
- (error
- (emms-playlist-last)))
- (emms-playlist-previous))
- (emms-playlist-select (point)))
+ (emms-playlist-first)
+ (setq track-indices (cons (point)
+ track-indices)))
(error
- (error "No previous track in playlist"))))))
-
-(defun emms-playlist-select-random ()
- "Select a random track in the playlist."
- (with-current-emms-playlist
- ;; FIXME: This is rather inefficient.
- (save-excursion
- (let ((track-indices nil)
- (donep nil))
+ (setq donep t)))
+ (while (not donep)
(condition-case nil
(progn
- (emms-playlist-first)
+ (emms-playlist-next)
(setq track-indices (cons (point)
track-indices)))
(error
- (setq donep t)))
- (while (not donep)
- (condition-case nil
- (progn
- (emms-playlist-next)
- (setq track-indices (cons (point)
- track-indices)))
- (error
- (setq donep t))))
- (setq track-indices (vconcat track-indices))
- (emms-playlist-select (aref track-indices
- (random (length track-indices))))))))
+ (setq donep t))))
+ (setq track-indices (vconcat track-indices))
+ (emms-playlist-select (aref track-indices
+ (random (length track-indices)))))))
+
+(defun emms-playlist-current-select-random ()
+ "Select a random track in the current playlist."
+ (with-current-emms-playlist
+ (emms-playlist-select-random)))
(defun emms-playlist-select-first ()
- "Select the first track in the playlist."
+ "Select the first track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
+ (save-excursion
+ (emms-playlist-first)
+ (emms-playlist-select (point))))
+
+(defun emms-playlist-current-select-first ()
+ "Select the first track in the current playlist."
(with-current-emms-playlist
- (save-excursion
- (emms-playlist-first)
- (emms-playlist-select (point)))))
+ (emms-playlist-select-first)))
(defun emms-playlist-select-last ()
- "Select the last track in the playlist."
+ "Select the last track in the current buffer."
+ (emms-playlist-ensure-playlist-buffer)
+ (save-excursion
+ (emms-playlist-last)
+ (emms-playlist-select (point))))
+
+(defun emms-playlist-current-select-last ()
+ "Select the last track in the current playlist."
(with-current-emms-playlist
- (save-excursion
- (emms-playlist-last)
- (emms-playlist-select (point)))))
+ (emms-playlist-select-last)))
;;; Playlist manipulation
(defun emms-playlist-insert-track (track)
"Insert TRACK at the current position into the playlist.
This uses `emms-playlist-insert-track-function'."
+ (emms-playlist-ensure-playlist-buffer)
(let ((inhibit-read-only t))
(funcall emms-playlist-insert-track-function track)))
(defun emms-playlist-insert-source (source &rest args)
"Insert tracks from SOURCE, supplying ARGS as arguments."
+ (emms-playlist-ensure-playlist-buffer)
+ (save-restriction
+ (narrow-to-region (point)
+ (point))
+ (apply source args)
+ (run-hooks 'emms-playlist-source-inserted-hook)))
+
+(defun emms-playlist-current-insert-source (source &rest args)
+ "Insert tracks from SOURCE in the current playlist.
+This is supplying ARGS as arguments to the source."
(with-current-emms-playlist
- (save-restriction
- (narrow-to-region (point)
- (point))
- (apply source args)
- (run-hooks 'emms-playlist-source-inserted-hook))))
+ (apply 'emms-playlist-insert-source source args)))
(defun emms-playlist-tracks-in-region (beg end)
"Return all tracks between BEG and END."
+ (emms-playlist-ensure-playlist-buffer)
(let ((tracks nil)
(donep nil))
(save-restriction
@@ -718,12 +714,14 @@ This uses `emms-playlist-insert-track-function'."
;;; Simple playlist buffer
(defun emms-playlist-simple-insert-track (track)
"Insert the description of TRACK at point."
+ (emms-playlist-ensure-playlist-buffer)
(insert (propertize (emms-track-description track)
'emms-track track)
"\n"))
(defun emms-playlist-simple-delete-track ()
"Delete the track at point."
+ (emms-playlist-ensure-playlist-buffer)
(when (not (emms-playlist-track-at (point)))
(error "No track at point"))
(let ((region (emms-property-region (point) 'emms-track)))
@@ -732,6 +730,7 @@ This uses `emms-playlist-insert-track-function'."
(defun emms-playlist-simple-shuffle ()
"Shuffle the whole playlist buffer."
+ (emms-playlist-ensure-playlist-buffer)
(let ((current nil))
(widen)
(when emms-player-playing-p
@@ -756,6 +755,7 @@ This uses `emms-playlist-insert-track-function'."
(defun emms-playlist-simple-sort ()
"Sort the whole playlist buffer."
+ (emms-playlist-ensure-playlist-buffer)
(widen)
(let ((current (emms-playlist-selected-track))
(tracks (emms-playlist-tracks-in-region (point-min)
@@ -806,6 +806,67 @@ This uses `emms-playlist-insert-track-function'."
(setq i (- i 1))))
vector)
+;;; Saving playlists.
+
+(defun emms-playlist-save (playlist filename)
+ "Save a playlist in the native EMMS format."
+ (interactive "bPlaylist buffer name: \nFFile to save playlist as: ")
+ (let ((tracklist '()))
+ (condition-case nil
+ (with-current-buffer playlist
+ (save-excursion
+ (emms-playlist-first)
+ (while (emms-playlist-track-at)
+ (setq tracklist (cons (emms-playlist-track-at)
+ tracklist))
+ (emms-playlist-next))))
+ (error nil))
+ (setq tracklist (nreverse tracklist))
+ ;; tracklist complete, let's write it !
+ (with-current-buffer (find-file-noselect filename)
+ (erase-buffer)
+ (prin1 tracklist (current-buffer))
+ (insert "\n")
+ (save-buffer)
+ (kill-buffer (current-buffer)))))
+
+(defun emms-playlist-save-active (filename)
+ "Save the active EMMS playlist in native format."
+ (interactive "FFile to save playlist as: ")
+ (emms-playlist-save emms-playlist-buffer filename))
+
+(defun emms-playlist-save-as-m3u (playlist filename)
+ "Save a playlist in .m3u format."
+ (interactive "bPlaylist buffer name: \nFFile to save playlist as: ")
+ (let ((tracklist '()))
+ (condition-case nil
+ (with-current-buffer playlist
+ (save-excursion
+ (emms-playlist-first)
+ (while (emms-playlist-track-at)
+ (setq tracklist (cons (emms-playlist-track-at)
+ tracklist))
+ (emms-playlist-next))))
+ (error nil))
+ (setq tracklist (nreverse tracklist))
+ ;; tracklist complete, let's write it !
+ (with-current-buffer (find-file-noselect filename)
+ (erase-buffer)
+ (insert "#EXTM3U\n")
+ (mapc (lambda (track)
+ (let ((info (emms-info-get track)))
+ (insert "#EXTINF:")
+ (insert (emms-info-playing-time info) ",")
+ (insert (emms-info-artist info) " - " (emms-info-title info) "\n")
+ (insert (emms-track-get track 'name) "\n")))
+ tracklist)
+ (save-buffer)
+ (kill-buffer (current-buffer)))))
+
+(defun emms-playlist-save-active-as-m3u (filename)
+ "Save the active EMMS playlist in m3u format."
+ (interactive "FFile to save playlist as: ")
+ (emms-playlist-save-as-m3u emms-playlist-buffer filename))
@@ -863,9 +924,9 @@ See emms-source-file.el for some examples."
(defun emms-source-play (source &rest args)
"Play the tracks of SOURCE, after first clearing the EMMS playlist."
(emms-stop)
- (emms-playlist-clear)
- (apply 'emms-playlist-insert-source source args)
- (emms-playlist-select-first)
+ (emms-playlist-current-clear)
+ (apply 'emms-playlist-current-insert-source source args)
+ (emms-playlist-current-select-first)
(emms-start))
(defun emms-source-add (source &rest args)
@@ -873,7 +934,7 @@ See emms-source-file.el for some examples."
(with-current-emms-playlist
(save-excursion
(goto-char (point-max))
- (apply 'emms-playlist-insert-source source args))
+ (apply 'emms-playlist-current-insert-source source args))
(when (or (not emms-playlist-selected-marker)
(not (marker-position emms-playlist-selected-marker)))
(emms-playlist-select-first))))
@@ -882,7 +943,7 @@ See emms-source-file.el for some examples."
"Insert the tracks from SOURCE in the current buffer."
(if (not emms-playlist-buffer-p)
(error "Not in an EMMS playlist buffer")
- (apply emms-playlist-insert-source source args)))
+ (apply 'emms-playlist-current-insert-source source args)))
;;; User-defined playlists
;;; FIXME: Shuffle is bogus here! (because of narrowing)