[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [emms-help] Two new EMMS functions
From: |
Ian Dunn |
Subject: |
Re: [emms-help] Two new EMMS functions |
Date: |
Sat, 23 Apr 2016 11:57:34 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
After looking over some EMMS internals, I realized that EMMS uses text
properties for each track. I'm not sure if this is what you were trying to
tell me before, but it was what I ultimately took away from this.
First, I've got a pair of functions to select and play a given track.
(defun emms-find-track-in-playlist-buffer (track &optional playlist-buffer)
"Find EMMS track TRACK in PLAYLIST-BUFFER.
The current EMMS playlist buffer is used if PLAYLIST-BUFFER is nil."
(with-current-buffer (or playlist-buffer emms-playlist-buffer)
(text-property-any (point-min) (point-max) 'emms-track track)))
(defun emms-player-play-track (track)
"Select and play EMMS track TRACK. in the current playlist."
(with-current-emms-playlist
(when-let (pt (emms-find-track-in-playlist-buffer track))
(when emms-player-playing-p
(emms-stop))
(emms-playlist-select pt)
(emms-player-start track))))
I think these two functions will lessen the confusion I experienced for
other people attempting to work with EMMS.
Now, the simplified version of emms-play-playlist-track:
;;;###autoload
(defun emms-play-playlist-track ()
"Select a track in the current playlist."
;; Marked as interactive-only because ‘completing-read’ is used, forcing
;; interaction with the user.
(declare (interactive-only t))
(interactive)
(with-current-emms-playlist
(when-let ((trk (completing-read "Track: " (split-string (buffer-string)
"[\n\r]" t))))
(emms-player-play-track (get-text-property 0 'emms-track trk)))))
I offer these functions, along with emms-add-file-from-cache, to EMMS for
its own use. I often use helm or ivy for completion, and at the very least,
these functions work well with ivy (my current preference). I don't think
these functions belong in either package, but in EMMS itself, as they don't
depend on either completion method. If I'm not mistaken, they will also work
well with ido (But I haven't verified this, so I'm assuming).
--
Ian Dunn