Following on from a couple of previous posts on elfeed, the excellent feed reader for Emacs, I wanted to share some code to enable the starring and unstarring of articles for future reference.
This code is closely based on this article, so all credit should go in that direction. My only addition is to add the ability to unstar an article.
;; code to add and remove a starred tag to elfeed article ;; based on http://matt.hackinghistory.ca/2015/11/22/elfeed/ ;; add a star (defun bjm/elfeed-star () "Apply starred to all selected entries." (interactive ) (let* ((entries (elfeed-search-selected)) (tag (intern "starred"))) (cl-loop for entry in entries do (elfeed-tag entry tag)) (mapc #'elfeed-search-update-entry entries) (unless (use-region-p) (forward-line)))) ;; remove a start (defun bjm/elfeed-unstar () "Remove starred tag from all selected entries." (interactive ) (let* ((entries (elfeed-search-selected)) (tag (intern "starred"))) (cl-loop for entry in entries do (elfeed-untag entry tag)) (mapc #'elfeed-search-update-entry entries) (unless (use-region-p) (forward-line)))) ;; face for starred articles (defface elfeed-search-starred-title-face '((t :foreground "#f77")) "Marks a starred Elfeed entry.") (push '(starred elfeed-search-starred-title-face) elfeed-search-face-alist)
This code sets up the required functions to add and remove the “starred” tag from articles, and sets a face colour to indicate articles that have been starred.
I bind these to the keys “*” to add a star and “8” to remove the star (easy to remember):
;; add keybindings (eval-after-load 'elfeed-search '(define-key elfeed-search-mode-map (kbd "*") 'bjm/elfeed-star)) (eval-after-load 'elfeed-search '(define-key elfeed-search-mode-map (kbd "8") 'bjm/elfeed-unstar))
Now, entering the search filter “+starred” in elfeed will show the starred articles, and as described previously you can save a bookmark to that filter (I called mine “elfeed-starred”) and assign a key like “S” to jump directly to the starred articles:
;;shortcut to jump to starred bookmark (defun bjm/elfeed-show-starred () (interactive) (bookmark-jump "elfeed-starred")) (define-key elfeed-search-mode-map (kbd "S") 'bjm/elfeed-show-starred)
Update 2016-09-27
Commenter Galrog has a much simpler implementation. I’ve copied it here so the formatting is nicer:
(defalias 'elfeed-toggle-star (elfeed-expose #'elfeed-search-toggle-all 'star)) (eval-after-load 'elfeed-search '(define-key elfeed-search-mode-map (kbd "m") 'elfeed-toggle-star))