From c1bb6c356ec74ca065976557c264b16a224f18a0 Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 12 Jan 2021 20:41:10 +0000 Subject: espotify: playing with embark actions --- media/espotify.org | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'media') 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 -- cgit v1.2.3