blob: 076b6f1f31a7b8df5bc596c11ae91ad5b923c853 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
;;; elfeed-config --- Settings and Enhancements to the Elfeed RSS Feed Reader -*- lexical-binding: t; -*-
;; author Craig Jennings <c@cjennings.net>
;;; Commentary:
;;; Code:
;; ------------------------------- Elfeed Config -------------------------------
(use-package elfeed
:bind
(:map elfeed-show-mode-map
("w" . eww-open-in-new-buffer))
(:map elfeed-search-mode-map
("w" . cj/elfeed-eww-open) ;; opens in eww
("b" . cj/elfeed-browser-open) ;; opens in external browser
("d" . cj/elfeed-youtube-dl) ;; async download with yt-dlp and tsp
("p" . cj/play-with-mpv) ;; async play with mpv
("v" . cj/play-with-mpv) ;; async play with mpv
("R" . cj/elfeed-mark-all-as-read) ;; capital marks all as read, since upper case marks one as read
("U" . cj/elfeed-mark-all-as-unread)) ;; capital marks all as unread, since lower case marks one as unread
:config
(setq elfeed-db-directory (concat user-emacs-directory ".elfeed-db"))
(setq-default elfeed-search-title-max-width 150)
(setq-default elfeed-search-title-min-width 80)
(setq-default elfeed-search-filter "+mustread +unread"))
;; ---------------------------- Elfeed Org Feed List ---------------------------
(use-package elfeed-org
:defer .5
:after elfeed
:config
(setq rmh-elfeed-org-files
(list (concat user-emacs-directory "assets/elfeed-feeds.org")))
(elfeed-org))
;; ------------------------------ Elfeed Dashboard -----------------------------
(use-package elfeed-dashboard
:defer .5
:bind
("M-R" . elfeed-dashboard)
:config
(setq elfeed-dashboard-file (concat user-emacs-directory "assets/elfeed-dashboard.org"))
;; update feed counts on elfeed-quit
(advice-add 'elfeed-search-quit-window :after #'elfeed-dashboard-update-links))
;; ------------------------------ Elfeed Functions -----------------------------
(defun cj/elfeed-open ()
"Open Elfeed, update all feeds, then move to the first entry."
(interactive)
(elfeed)
(elfeed-update)
(elfeed-search-update--force))
;; -------------------------- Elfeed Filter Functions --------------------------
(defun cj/elfeed-mark-all-as-read ()
"Temove the 'unread' tag from all elfeed entries visible in the elfeed search buffer."
(interactive)
(mark-whole-buffer)
(elfeed-search-untag-all-unread))
(defun cj/elfeed-mark-all-as-unread ()
"Add the 'unread' tag from all elfeed entries visible in the elfeed search buffer."
(interactive)
(mark-whole-buffer)
(elfeed-search-tag-all 'unread))
(defun cj/elfeed-set-filter-and-update(filterstring)
"Set the Elfeed filter to 'FILTERSTRING' and update the the buffer."
(interactive "P")
(setq elfeed-search-filter filterstring)
(elfeed-search-update--force)
(elfeed-search-first-entry))
;; -------------------------- Elfeed Browser Functions -------------------------
(defun cj/elfeed-eww-open (&optional use-generic-p)
"Open currently selected entry with EWW."
(interactive "P")
(let ((entries (elfeed-search-selected)))
(cl-loop for entry in entries
do (elfeed-untag entry 'unread)
when (elfeed-entry-link entry)
do
(add-hook 'eww-after-render-hook #'cj/eww-readable-nonce)
(eww-browse-url it))
(mapc #'elfeed-search-update-entry entries)
(unless (use-region-p) (forward-line))))
;; hook for cj/elfeed-eww-open to open entry in eww readable mode
;; https://emacs.stackexchange.com/questions/36284/how-to-open-eww-in-readable-mode/47757
(defun cj/eww-readable-nonce ()
"Once-off call to eww-readable after EWW is done rendering."
(unwind-protect
(progn
(eww-readable)
(goto-char (point-min)))
(remove-hook 'eww-after-render-hook #'cj/eww-readable-nonce)))
(defun cj/elfeed-browser-open (&optional use-generic-p)
"Open the currently selected entry with default browser."
(interactive "P")
(let ((entries (elfeed-search-selected)))
(cl-loop for entry in entries
do (elfeed-untag entry 'unread)
when (elfeed-entry-link entry)
do (browse-url-default-browser it))
(mapc #'elfeed-search-update-entry entries)
(unless (use-region-p) (forward-line))))
;; --------------------- Elfeed Plan And Download Functions --------------------
(defun cj/elfeed-youtube-dl (&optional use-generic-p)
"Youtube-DL link."
(interactive "P")
(let ((entries (elfeed-search-selected)))
(cl-loop for entry in entries
do (elfeed-untag entry 'unread)
when (elfeed-entry-link entry)
do (cj/yt-dl-it it))
(mapc #'elfeed-search-update-entry entries)
(unless (use-region-p) (forward-line))))
(defun cj/yt-dl-it (url)
"Downloads the URL in an async shell."
(let ((default-directory videos-dir))
(save-window-excursion
(async-shell-command (format "tsp yt-dlp --add-metadata -ic -o '%%(channel)s-%%(title)s.%%(ext)s' '%s'" url)))))
(defun cj/play-with-mpv (&optional use-generic-p)
"MPV link."
(interactive "P")
(let ((entries (elfeed-search-selected)))
(cl-loop for entry in entries
do (elfeed-untag entry 'unread)
when (elfeed-entry-link entry)
do (cj/mpv-play-it it))
(mapc #'elfeed-search-update-entry entries)
(unless (use-region-p) (forward-line))))
(defun cj/mpv-play-it (url)
"Play the URL with mpv in an async shell."
(async-shell-command (format "mpv '%s'" url)))
(provide 'elfeed-config)
;;; elfeed-config.el ends here
|