Rework +elfeed/dispatch-entry

Provide a set of possible actions for the user to choose.  Currently
supported actions are:
- yank URL
- open in EWW
- open in empv
This commit is contained in:
2025-02-17 22:23:27 +00:00
parent 08a092bdd5
commit aca2bcba5a

View File

@@ -3728,19 +3728,29 @@ to elfeed for loading the system.
(with-eval-after-load "evil-collection" (with-eval-after-load "evil-collection"
(evil-collection-elfeed-setup)) (evil-collection-elfeed-setup))
(advice-add 'elfeed-search-show-entry :after #'+elfeed/dispatch-entry) (defvar +elfeed/dispatch-options
'(("Yank URL" .
(lambda (url)
(kill-new url)
(message "elfeed: Yanked %s" url)))
("Open via EWW" . eww)
("Play via EMPV" .
(lambda (url)
(if (member 'empv features)
;; FIXME: Using internal macro
(empv--with-video-enabled
(empv-play-or-enqueue url))
(message "elfeed: EMPV is not available")))))
"Options available on entering an elfeed post.")
(defun +elfeed/dispatch-entry (entry) (defun +elfeed/dispatch-entry (entry)
"Process each type of entry differently. "Provide some extra options once you've clicked on an article."
e.g., you may want to open HN entries in eww." (let ((choice (completing-read "Choose action: " (mapcar #'car +elfeed/dispatch-options)))
(let ((url (elfeed-entry-link entry))) (url (elfeed-entry-link entry)))
(pcase url (if-let ((option (cdr (assoc choice +elfeed/dispatch-options #'string=))))
((pred (string-match-p "https\\:\\/\\/www.youtube.com\\/watch")) (funcall option url))))
(if (member 'empv features)
;; FIXME: This is an internal macro (advice-add 'elfeed-search-show-entry :after #'+elfeed/dispatch-entry))
(empv--with-video-enabled
(empv-play-or-enqueue url))))
(_ (eww url))))))
#+end_src #+end_src
*** Elfeed-org *** Elfeed-org
#+begin_src emacs-lisp #+begin_src emacs-lisp