Discussion:
[emms-help] [PATCH] Play/pause dwim, tries to pause/play music
Alejandro Erickson
2016-06-22 22:34:59 UTC
Permalink
(emms-play-pause-dwim) first tries (emms-pause). If an error is
encountered it tries to play the first item in the current playlist.
Failing that it plays something random from the emms browser. If it
fails again, it emits a message.
---
lisp/emms.el | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)

diff --git a/lisp/emms.el b/lisp/emms.el
index 2d282bb..5a037ed 100644
--- a/lisp/emms.el
+++ b/lisp/emms.el
@@ -434,6 +434,43 @@ If player hasn't started, then start it now."
(emms-player-pause)
(emms-start)))

+(defun emms-play-pause-dwim ()
+ "Try to (un)pause, or play from playlist, or play a random track from the music library."
+ (interactive)
+ (let ((res nil))
+ (ignore-errors
+ (emms-pause)
+ (setq res t)
+ )
+ (unless res
+ (let ((res nil))
+ (ignore-errors
+ (emms-playlist-mode-go)
+ (goto-line 1)
+ (emms-playlist-mode-play-smart)
+ (emms-playlist-mode-bury-buffer)
+ (setq res t)
+ )
+ (unless res
+ (let ((res nil))
+ (ignore-errors
+ (emms-browser)
+ (emms-browse-by-album)
+ (emms-browser-goto-random)
+ (emms-browser-add-tracks-and-play)
+ (emms-browser-bury-buffer)
+ (setq res t)
+ )
+ (unless res
+ (message "Failed to play music. Populate your EMMS library or playlist.")
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+
(defun emms-seek (seconds)
"Seek the current player SECONDS seconds.
This can be a floating point number for sub-second fractions.
--
2.8.3
Yoni Rabkin
2016-06-24 21:34:52 UTC
Permalink
Whatever the issue is, a lot of `ignore-errors' is not the solution
since the user needs the output from those errors to figure out exactly
what's going on.

I'm sure that there is a different way of expressing the same idea.
--
"Cut your own wood and it will warm you twice"
Loading...