diff options
Diffstat (limited to 'media')
| -rw-r--r-- | media/espotify.org | 52 | 
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  | 
