Ian Dunn
2016-04-14 12:08:36 UTC
I've created two interactive functions for EMMS that I think other people may find useful. Both of them are included in this email at the bottom, as well as a helper function for one of them.
The first is 'emms-add-file-from-cache', which, as it sounds, adds a file from the EMMS cache database to the
current EMMS playlist. The second is a function to interactively select and play one of the tracks in the current EMMS playlist.
Both of these functions use 'when-let' from subr-x, so I don't know if that creates a compatibility issue. If it does, I'd be happy to quickly fix them.
I hope other people will find these as useful as I do.
--
Ian Dunn
;;;###autoload
(defun emms-add-file-from-cache ()
"Interactively add a file from EMMS cache."
;; Marked as interactive-only because ‘completing-read’ is used, forcing
;; interaction with the user.
(declare (interactive-only t))
(interactive)
(when-let (file-name (completing-read "File: " emms-cache-db))
(emms-add-file file-name)))
(defun emms--collect-playlist-tracks (&optional playlist-buffer)
"Collect a hash table of tracks from PLAYLIST-BUFFER.
The returned hash table will have the track descriptions as the key,
and the point in the playlist buffer as the value.
If PLAYLIST-BUFFER is not specified, then it will default to the
current EMMS playlist."
(let ((l (make-hash-table :test #'equal)))
(with-current-buffer (or playlist-buffer emms-playlist-buffer)
(goto-char (point-min))
(emms-walk-tracks
(puthash (emms-info-track-description (emms-playlist-track-at)) (point) l)))
l))
;;;###autoload
(defun emms-select-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)
(let ((l (emms--collect-playlist-tracks emms-playlist-buffer)))
(when-let (key (completing-read "Track: " l))
(with-current-emms-playlist
(goto-char (gethash key l))
(emms-playlist-mode-play-smart)))))
The first is 'emms-add-file-from-cache', which, as it sounds, adds a file from the EMMS cache database to the
current EMMS playlist. The second is a function to interactively select and play one of the tracks in the current EMMS playlist.
Both of these functions use 'when-let' from subr-x, so I don't know if that creates a compatibility issue. If it does, I'd be happy to quickly fix them.
I hope other people will find these as useful as I do.
--
Ian Dunn
;;;###autoload
(defun emms-add-file-from-cache ()
"Interactively add a file from EMMS cache."
;; Marked as interactive-only because ‘completing-read’ is used, forcing
;; interaction with the user.
(declare (interactive-only t))
(interactive)
(when-let (file-name (completing-read "File: " emms-cache-db))
(emms-add-file file-name)))
(defun emms--collect-playlist-tracks (&optional playlist-buffer)
"Collect a hash table of tracks from PLAYLIST-BUFFER.
The returned hash table will have the track descriptions as the key,
and the point in the playlist buffer as the value.
If PLAYLIST-BUFFER is not specified, then it will default to the
current EMMS playlist."
(let ((l (make-hash-table :test #'equal)))
(with-current-buffer (or playlist-buffer emms-playlist-buffer)
(goto-char (point-min))
(emms-walk-tracks
(puthash (emms-info-track-description (emms-playlist-track-at)) (point) l)))
l))
;;;###autoload
(defun emms-select-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)
(let ((l (emms--collect-playlist-tracks emms-playlist-buffer)))
(when-let (key (completing-read "Track: " l))
(with-current-emms-playlist
(goto-char (gethash key l))
(emms-playlist-mode-play-smart)))))