2017-06-08 11:47:56 +02:00
|
|
|
;;; app/rss/autoload.el -*- lexical-binding: t; -*-
|
2017-03-06 22:01:37 -05:00
|
|
|
|
2020-12-15 15:42:30 -08:00
|
|
|
(defvar +rss--wconf nil)
|
|
|
|
|
2017-03-06 22:01:37 -05:00
|
|
|
;;;###autoload
|
2020-12-15 15:42:30 -08:00
|
|
|
(defun =rss ()
|
|
|
|
"Activate (or switch to) `elfeed' in its workspace."
|
|
|
|
(interactive)
|
2022-08-12 20:29:19 +02:00
|
|
|
(if (modulep! :ui workspaces)
|
2020-12-15 15:42:30 -08:00
|
|
|
(progn
|
2022-01-30 11:43:07 -08:00
|
|
|
(+workspace-switch +rss-workspace-name t)
|
2022-08-31 14:40:54 -04:00
|
|
|
(unless (memq (buffer-local-value 'major-mode
|
|
|
|
(window-buffer
|
|
|
|
(selected-window)))
|
|
|
|
'(elfeed-show-mode
|
|
|
|
elfeed-search-mode))
|
|
|
|
(doom/switch-to-scratch-buffer)
|
|
|
|
(elfeed))
|
2020-12-15 15:42:30 -08:00
|
|
|
(+workspace/display))
|
|
|
|
(setq +rss--wconf (current-window-configuration))
|
|
|
|
(delete-other-windows)
|
|
|
|
(switch-to-buffer (doom-fallback-buffer))
|
|
|
|
(elfeed)))
|
2017-03-06 22:01:37 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +rss/delete-pane ()
|
|
|
|
"Delete the *elfeed-entry* split pane."
|
|
|
|
(interactive)
|
2018-06-02 17:42:57 +02:00
|
|
|
(let* ((buf (get-buffer "*elfeed-entry*"))
|
|
|
|
(window (get-buffer-window buf)))
|
|
|
|
(delete-window window)
|
|
|
|
(when (buffer-live-p buf)
|
|
|
|
(kill-buffer buf))))
|
2017-03-06 22:01:37 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +rss/open (entry)
|
|
|
|
"Display the currently selected item in a buffer."
|
|
|
|
(interactive (list (elfeed-search-selected :ignore-region)))
|
|
|
|
(when (elfeed-entry-p entry)
|
|
|
|
(elfeed-untag entry 'unread)
|
|
|
|
(elfeed-search-update-entry entry)
|
|
|
|
(elfeed-show-entry entry)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +rss/next ()
|
|
|
|
"Show the next item in the elfeed-search buffer."
|
|
|
|
(interactive)
|
|
|
|
(funcall elfeed-show-entry-delete)
|
|
|
|
(with-current-buffer (elfeed-search-buffer)
|
|
|
|
(forward-line)
|
|
|
|
(call-interactively '+rss/open)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +rss/previous ()
|
|
|
|
"Show the previous item in the elfeed-search buffer."
|
|
|
|
(interactive)
|
|
|
|
(funcall elfeed-show-entry-delete)
|
|
|
|
(with-current-buffer (elfeed-search-buffer)
|
|
|
|
(forward-line -1)
|
|
|
|
(call-interactively '+rss/open)))
|
2017-04-05 15:05:40 -04:00
|
|
|
|
2021-09-27 01:21:51 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun +rss/copy-link ()
|
|
|
|
"Copy current link to clipboard."
|
|
|
|
(interactive)
|
|
|
|
(let ((link (elfeed-entry-link elfeed-show-entry)))
|
|
|
|
(when link
|
|
|
|
(kill-new link)
|
|
|
|
(message "Copied %s to clipboard" link))))
|
2018-06-29 15:08:06 +02:00
|
|
|
;;
|
|
|
|
;; Hooks
|
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-23 12:30:47 +02:00
|
|
|
(defun +rss-elfeed-wrap-h ()
|
2018-06-29 15:08:06 +02:00
|
|
|
"Enhances an elfeed entry's readability by wrapping it to a width of
|
2019-04-02 12:52:00 -04:00
|
|
|
`fill-column'."
|
2018-06-29 15:08:06 +02:00
|
|
|
(let ((inhibit-read-only t)
|
|
|
|
(inhibit-modification-hooks t))
|
|
|
|
(setq-local truncate-lines nil)
|
2019-04-02 12:52:00 -04:00
|
|
|
(setq-local shr-use-fonts nil)
|
2018-06-29 15:08:06 +02:00
|
|
|
(setq-local shr-width 85)
|
|
|
|
(set-buffer-modified-p nil)))
|
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-23 12:30:47 +02:00
|
|
|
(defun +rss-cleanup-h ()
|
2018-06-29 15:08:06 +02:00
|
|
|
"Clean up after an elfeed session. Kills all elfeed and elfeed-org files."
|
|
|
|
(interactive)
|
2019-03-29 03:52:24 -04:00
|
|
|
;; `delete-file-projectile-remove-from-cache' slows down `elfeed-db-compact'
|
|
|
|
;; tremendously, so we disable the projectile cache:
|
|
|
|
(let (projectile-enable-caching)
|
|
|
|
(elfeed-db-compact))
|
2018-06-29 15:08:06 +02:00
|
|
|
(let ((buf (previous-buffer)))
|
|
|
|
(when (or (null buf) (not (doom-real-buffer-p buf)))
|
|
|
|
(switch-to-buffer (doom-fallback-buffer))))
|
|
|
|
(let ((search-buffers (doom-buffers-in-mode 'elfeed-search-mode))
|
|
|
|
(show-buffers (doom-buffers-in-mode 'elfeed-show-mode))
|
|
|
|
kill-buffer-query-functions)
|
2020-03-01 12:19:44 -05:00
|
|
|
(dolist (file (bound-and-true-p rmh-elfeed-org-files))
|
2019-06-25 21:38:16 +02:00
|
|
|
(when-let (buf (get-file-buffer (expand-file-name file org-directory)))
|
2018-06-29 15:08:06 +02:00
|
|
|
(kill-buffer buf)))
|
|
|
|
(dolist (b search-buffers)
|
|
|
|
(with-current-buffer b
|
2019-07-23 12:30:47 +02:00
|
|
|
(remove-hook 'kill-buffer-hook #'+rss-cleanup-h :local)
|
2018-06-29 15:08:06 +02:00
|
|
|
(kill-buffer b)))
|
2020-12-15 15:42:30 -08:00
|
|
|
(mapc #'kill-buffer show-buffers))
|
2022-08-12 20:29:19 +02:00
|
|
|
(if (and (modulep! :ui workspaces)
|
2022-07-04 21:51:46 +02:00
|
|
|
(+workspace-exists-p +rss-workspace-name))
|
2022-01-30 11:43:07 -08:00
|
|
|
(+workspace/delete +rss-workspace-name)
|
2020-12-15 15:42:30 -08:00
|
|
|
(when (window-configuration-p +rss--wconf)
|
|
|
|
(set-window-configuration +rss--wconf))
|
2022-07-04 21:51:46 +02:00
|
|
|
(setq +rss--wconf nil)
|
|
|
|
(previous-buffer)))
|
2018-06-29 15:08:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Functions
|
|
|
|
|
2017-04-05 15:05:40 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun +rss-dead-feeds (&optional years)
|
|
|
|
"Return a list of feeds that haven't posted anything in YEARS."
|
|
|
|
(let* ((years (or years 1.0))
|
|
|
|
(living-feeds (make-hash-table :test 'equal))
|
|
|
|
(seconds (* years 365.0 24 60 60))
|
|
|
|
(threshold (- (float-time) seconds)))
|
|
|
|
(with-elfeed-db-visit (entry feed)
|
|
|
|
(let ((date (elfeed-entry-date entry)))
|
|
|
|
(when (> date threshold)
|
|
|
|
(setf (gethash (elfeed-feed-url feed) living-feeds) t))))
|
|
|
|
(cl-loop for url in (elfeed-feed-list)
|
|
|
|
unless (gethash url living-feeds)
|
|
|
|
collect url)))
|
2018-06-29 15:08:06 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-23 12:30:47 +02:00
|
|
|
(defun +rss-put-sliced-image-fn (spec alt &optional flags)
|
2018-06-29 15:08:06 +02:00
|
|
|
"TODO"
|
2020-04-29 21:08:17 -04:00
|
|
|
(letf! (defun insert-image (image &optional alt _area _slice)
|
|
|
|
(let ((height (cdr (image-size image t))))
|
|
|
|
(insert-sliced-image image alt nil (max 1 (/ height 20.0)) 1)))
|
2018-06-29 15:08:06 +02:00
|
|
|
(shr-put-image spec alt flags)))
|
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-23 12:30:47 +02:00
|
|
|
(defun +rss-render-image-tag-without-underline-fn (dom &optional url)
|
2018-06-29 15:08:06 +02:00
|
|
|
"TODO"
|
|
|
|
(let ((start (point)))
|
|
|
|
(shr-tag-img dom url)
|
|
|
|
;; And remove underlines in case images are links, otherwise we get an
|
|
|
|
;; underline beneath every slice.
|
|
|
|
(put-text-property start (point) 'face '(:underline nil))))
|