-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
scimax-elfeed.el
205 lines (180 loc) · 6.18 KB
/
scimax-elfeed.el
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
;;; scimax-elfeed.el --- scimax configuration for elfeed
;;; Commentary:
;; This just sets up elfeed for scimax. It sets some default feeds and
;; categories, and some new org-mode integration and keybindings.
(require 'elfeed)
;;; Code:
(cl-loop for feed in '(("http://planetpython.org/rss20.xml" python)
("http://planet.scipy.org/rss20.xml" python)
("http://planet.emacsen.org/atom.xml" emacs)
;; Stackoverflow questions on emacs
("http://emacs.stackexchange.com/feeds" emacs))
do
(add-to-list 'elfeed-feeds feed t))
(defface python-elfeed-entry
'((t :background "Darkseagreen1"))
"Marks a python Elfeed entry."
:group 'scimax-elfeed)
(defface emacs-elfeed-entry
'((t :background "Lightblue1"))
"Marks a python Elfeed entry."
:group 'scimax-elfeed)
(push '(python python-elfeed-entry)
elfeed-search-face-alist)
(push '(emacs emacs-elfeed-entry)
elfeed-search-face-alist)
(setq elfeed-search-title-max-width 150)
(setq elfeed-search-trailing-width 30)
;; A snippet for periodic update for feeds (3 mins since Emacs start, then every
;; half hour)
(run-at-time 180 1800 (lambda () (unless elfeed-waiting (elfeed-update))))
(defun email-elfeed-entry ()
"Capture the elfeed entry and put it in an email."
(interactive)
(let* ((title (elfeed-entry-title elfeed-show-entry))
(url (elfeed-entry-link elfeed-show-entry))
(content (elfeed-entry-content elfeed-show-entry))
(entry-id (elfeed-entry-id elfeed-show-entry))
(entry-link (elfeed-entry-link elfeed-show-entry))
(entry-id-str (concat (car entry-id)
"|"
(cdr entry-id)
"|"
url)))
(compose-mail)
(message-goto-subject)
(insert title)
(message-goto-body)
(insert (format "You may find this interesting:
%s\n\n" url))
(insert (elfeed-deref content))
(message-goto-body)
(while (re-search-forward "<br>" nil t)
(replace-match "\n\n"))
(message-goto-body)
(while (re-search-forward "<.*?>" nil t)
(replace-match ""))
(message-goto-body)
(fill-region (point) (point-max))
(message-goto-to)
(ivy-contacts nil)))
(defun doi-utils-add-entry-from-elfeed-entry ()
"Add elfeed entry to bibtex."
(interactive)
(require 'org-ref)
(let* ((title (elfeed-entry-title elfeed-show-entry))
(url (elfeed-entry-link elfeed-show-entry))
(content (elfeed-deref (elfeed-entry-content elfeed-show-entry)))
(entry-id (elfeed-entry-id elfeed-show-entry))
(entry-link (elfeed-entry-link elfeed-show-entry))
(entry-id-str (concat (car entry-id)
"|"
(cdr entry-id)
"|"
url)))
(if (string-match "DOI: \\(.*\\)$" content)
(doi-add-bibtex-entry (match-string 1 content)
(ido-completing-read
"Bibfile: "
(append (f-entries "." (lambda (f)
(and (not (string-match "#" f))
(f-ext? f "bib"))))
org-ref-default-bibliography)))
(let ((dois (org-ref-url-scrape-dois url)))
(cond
;; One doi found. Assume it is what we want.
((= 1 (length dois))
(doi-utils-add-bibtex-entry-from-doi
(car dois)
(ido-completing-read
"Bibfile: "
(append (f-entries "." (lambda (f)
(and (not (string-match "#" f))
(f-ext? f "bib"))))
org-ref-default-bibliography)))
action)
;; Multiple DOIs found
((> (length dois) 1)
(ivy-read "Select a DOI" (let ((dois '()))
(with-current-buffer (url-retrieve-synchronously url)
(loop for doi-pattern in org-ref-doi-regexps
do
(goto-char (point-min))
(while (re-search-forward doi-pattern nil t)
(pushnew
;; Cut off the doi, sometimes
;; false matches are long.
(cons (format "%40s | %s"
(substring
(match-string 1)
0 (min
(length (match-string 1))
40))
doi-pattern)
(match-string 1))
dois
:test #'equal)))
(reverse dois)))
:action
(lambda (candidate)
(let ((bibfile (completing-read
"Bibfile: "
(append (f-entries "." (lambda (f)
(and (not (string-match "#" f))
(f-ext? f "bib"))))
org-ref-default-bibliography))))
(doi-utils-add-bibtex-entry-from-doi
(cdr candidate)
bibfile)
;; this removes two blank lines before each entry.
(bibtex-beginning-of-entry)
(delete-char -2))))))))))
(define-key elfeed-show-mode-map (kbd "e") 'email-elfeed-entry)
(define-key elfeed-show-mode-map (kbd "c") (lambda () (interactive) (org-capture nil "e")))
(define-key elfeed-show-mode-map (kbd "d") 'doi-utils-add-entry-from-elfeed-entry)
;; help me alternate fingers in marking entries as read
(define-key elfeed-search-mode-map (kbd "f") 'elfeed-search-untag-all-unread)
(define-key elfeed-search-mode-map (kbd "j") 'elfeed-search-untag-all-unread)
(define-key elfeed-search-mode-map (kbd "o") 'elfeed-search-show-entry)
;; * store links to elfeed entries
;; These are copied from org-elfeed
(defun org-elfeed-open (path)
"Open an elfeed link to PATH."
(cond
((string-match "^entry-id:\\(.+\\)" path)
(let* ((entry-id-str (substring-no-properties (match-string 1 path)))
(parts (split-string entry-id-str "|"))
(feed-id-str (car parts))
(entry-part-str (cadr parts))
(entry-id (cons feed-id-str entry-part-str))
(entry (elfeed-db-get-entry entry-id)))
(elfeed-show-entry entry)))
(t (error "%s %s" "elfeed: Unrecognised link type - " path))))
(defun org-elfeed-store-link ()
"Store a link to an elfeed entry."
(interactive)
(cond
((eq major-mode 'elfeed-show-mode)
(let* ((title (elfeed-entry-title elfeed-show-entry))
(url (elfeed-entry-link elfeed-show-entry))
(entry-id (elfeed-entry-id elfeed-show-entry))
(entry-id-str (concat (car entry-id)
"|"
(cdr entry-id)
"|"
url))
(org-link (concat "elfeed:entry-id:" entry-id-str)))
(org-link-store-props
:description title
:type "elfeed"
:link org-link
:url url
:entry-id entry-id)
org-link))
(t nil)))
(org-link-set-parameters
"elfeed"
:follow 'org-elfeed-open
:store 'org-elfeed-store-link)
(provide 'scimax-elfeed)
;;; scimax-elfeed.el ends here