summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/media/espotify.org46
1 files changed, 25 insertions, 21 deletions
diff --git a/lib/media/espotify.org b/lib/media/espotify.org
index 98530a8..a566a94 100644
--- a/lib/media/espotify.org
+++ b/lib/media/espotify.org
@@ -313,8 +313,8 @@ Let's start with an umbrella customization group:
(defun espotify-consult-by (type &optional filter)
(let ((orderless-matching-styles '(orderless-literal)))
- (consult--read (format "Search %ss: " type)
- (espotify--search-generator type filter)
+ (consult--read (espotify--search-generator type filter)
+ :prompt (format "Search %ss: " type)
:lookup 'espotify--consult-lookup
:category 'espotify-search-item
:history 'espotify-consult-history
@@ -495,40 +495,47 @@ Let's start with an umbrella customization group:
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:
+ always look for an album to play. These actions need access to the
+ rich metadata attached to the candidate, and will therefore be
+ defined as regular one-argument functions, rather than interactive
+ commands (as is otherwise recommended for generic embark actions).
#+begin_src emacs-lisp
(require 'espotify-consult)
(require 'embark)
- (defvar espotify--current-item nil)
-
- (defun espotify--show-info (name)
+ (defun espotify--show-info (candidate)
"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))
+ (insert (propertize candidate 'face 'bold))
(newline)
- (when espotify--current-item
- (insert (pp-to-string espotify--current-item)))
+ (when-let (item (espotify--item candidate))
+ (insert (pp-to-string item)))
(newline)
(goto-char (point-min))
(read-only-mode 1))
- (defun espotify--play-album (ignored)
+ (defun espotify--play-album (candidate)
"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))))
+ (when-let (item (espotify--item candidate))
+ (if-let (album (if (string= "album" (alist-get 'type item ""))
+ item
+ (alist-get 'album item)))
+ (espotify-play-uri (alist-get 'uri album))
+ (error "No album for %s" (alist-get 'name item)))))
+
+ (defun espotify--yank-url (candidate)
+ "Add to kill ring the Spotify URL of this entry"
+ (when-let (item (espotify--item candidate))
+ (if-let (url (alist-get 'spotify (alist-get 'external_urls item)))
+ (kill-new url)
+ (message "No spotify URL for this candidate"))))
(embark-define-keymap espotify-item-keymap
"Actions for Spotify search results"
+ ("y" espotify--yank-url)
("a" espotify--play-album)
("h" espotify--show-info))
@@ -536,9 +543,6 @@ Let's start with an umbrella customization group:
(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