From 25d8e0cae97087f881bb7f34080fa017a684a3ca Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 12 Jan 2021 20:39:13 +0000 Subject: espotify: minad's suggestions --- media/espotify.org | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'media/espotify.org') diff --git a/media/espotify.org b/media/espotify.org index 223d202..5618ab6 100644 --- a/media/espotify.org +++ b/media/espotify.org @@ -275,6 +275,7 @@ Let's start with an umbrella customization group: (defun espotify--search-generator (type filter) (thread-first (consult--async-sink) (consult--async-refresh-timer) + (consult-async--map #'espotify--format-item) (espotify--async-search type filter) (consult--async-throttle) (consult--async-split))) @@ -289,27 +290,24 @@ Let's start with an umbrella customization group: #+begin_src emacs-lisp (defun espotify--async-search (next type filter) - (let (candidates) - (lambda (action) - (pcase action - ((or 'setup 'refresh) (funcall next action)) - ('destroy (setq candidates nil) (funcall next 'destroy)) - ((pred stringp) - (espotify-search-all - (lambda (x) - (setq candidates (mapcar 'espotify--format-item x)) - (funcall next candidates)) - action ;; when we receive a string as the action, - ;; it's the user input - type - filter)) - ('get candidates) - (_ (funcall next action)))))) + (lambda (action) + (pcase action + ((pred stringp) + (espotify-search-all + (lambda (x) + (funcall next 'flush) + (funcall next x)) + action ;; when we receive a string as the action, + ;; it's the user input + type + filter)) + (_ (funcall next action))))) #+end_src When processing the results, we format them as a displayable string, while hiding in a property the URI that will allow us to - play the item: + play the item (and pass the formatter to ~consult-async--map~, in + ~espotify--search-generator~ above): #+begin_src emacs-lisp (defun espotify--format-item (x) -- cgit v1.2.3