summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-01-12 20:41:10 +0000
committerjao <jao@gnu.org>2021-01-12 20:41:10 +0000
commitc1bb6c356ec74ca065976557c264b16a224f18a0 (patch)
treea29280664c871ce68e164c73f524b684ce0a9f98
parent67c6cc870cef3aed05c2a0da43ff46f35764f346 (diff)
downloadelibs-c1bb6c356ec74ca065976557c264b16a224f18a0.tar.gz
elibs-c1bb6c356ec74ca065976557c264b16a224f18a0.tar.bz2
espotify: playing with embark actions
-rw-r--r--media/espotify.org52
1 files changed, 52 insertions, 0 deletions
diff --git a/media/espotify.org b/media/espotify.org
index 52ef9db..7b22cc0 100644
--- a/media/espotify.org
+++ b/media/espotify.org
@@ -390,6 +390,58 @@ Let's start with an umbrella customization group:
'(espotify-search-item . espotify-marginalia-annotate))
#+end_src
+* Embark actions
+
+ In addition to the default action (play the URI in the selected
+ candidate), we can use embark to define other operations. For
+ instance, we could print the full item alist in its own buffer, or
+ always look for an album to play:
+
+ #+begin_src emacs-lisp
+
+ (defvar espotify--current-item nil)
+
+ (defun espotify--show-info (name)
+ "Show low-level info (an alist) about selection."
+ (interactive "s")
+ (pop-to-buffer (get-buffer-create "*espotify info*"))
+ (read-only-mode -1)
+ (delete-region (point-min) (point-max))
+ (insert (propertize name 'face 'bold))
+ (newline)
+ (when espotify--current-item (insert (pp-to-string espotify--current-item)))
+ (newline)
+ (goto-char (point-min))
+ (read-only-mode 1))
+
+ (defun espotify--play-album (ignored)
+ "Play album associated with selected item."
+ (interactive "i")
+ (if-let (album (if (string= "album"
+ (alist-get 'type espotify--current-item ""))
+ espotify--current-item
+ (alist-get 'album espotify--current-item)))
+ (espotify-play-uri (alist-get 'uri album))
+ (error "No album for %s" (alist-get 'nmae espotify--current-item))))
+
+ (with-eval-after-load "embark"
+ (embark-define-keymap espotify-item-keymap
+ "Actions for Spotify search results"
+ ("a" espotify--play-album)
+ ("h" espotify--show-info))
+
+ (defun espotify--annotate-item (cand)
+ (setq espotify--current-item (espotify--item cand))
+ (cons 'espotify-search-item cand))
+
+ (add-to-list 'embark-transformer-alist
+ '(espotify-search-item . espotify--annotate-item))
+
+ (add-to-list 'embark-keymap-alist
+ '(espotify-search-item . espotify-item-keymap)))
+ #+end_src
+
+
* Post-amble :noexport:
#+begin_src emacs-lisp