diff options
Diffstat (limited to 'lisp/+elfeed.el')
-rw-r--r-- | lisp/+elfeed.el | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/lisp/+elfeed.el b/lisp/+elfeed.el index 9e5f787..ef93347 100644 --- a/lisp/+elfeed.el +++ b/lisp/+elfeed.el | |||
@@ -2,8 +2,6 @@ | |||
2 | 2 | ||
3 | ;;; Code: | 3 | ;;; Code: |
4 | 4 | ||
5 | (require 'elfeed) | ||
6 | |||
7 | ;; https://karthinks.com/software/lazy-elfeed/ | 5 | ;; https://karthinks.com/software/lazy-elfeed/ |
8 | (defun +elfeed-scroll-up-command (&optional arg) | 6 | (defun +elfeed-scroll-up-command (&optional arg) |
9 | "Scroll up or go to next feed item in Elfeed" | 7 | "Scroll up or go to next feed item in Elfeed" |
@@ -31,5 +29,78 @@ | |||
31 | (interactive) | 29 | (interactive) |
32 | (elfeed-show-visit t)) | 30 | (elfeed-show-visit t)) |
33 | 31 | ||
32 | ;;; Fetch feeds async | ||
33 | ;; https://github.com/skeeto/elfeed/issues/367 | ||
34 | |||
35 | (defun +elfeed--update-message () | ||
36 | (message "[Elfeed] Update in progress") | ||
37 | 'ignore) | ||
38 | |||
39 | (defvar +elfeed--update-running nil "Whether an update is currently running.") | ||
40 | |||
41 | (defun +elfeed-update-command () | ||
42 | (interactive) | ||
43 | (let ((script (expand-file-name "~/.local/bin/elfeed"))) | ||
44 | (message "[Elfeed] Updating in the background.") | ||
45 | (setq +elfeed--update-running t) | ||
46 | (elfeed-db-save) | ||
47 | (advice-add 'elfeed :override #'+elfeed--update-message) | ||
48 | (ignore-errors (kill-buffer "*elfeed-search*")) | ||
49 | (ignore-errors (kill-buffer "*elfeed-log*")) | ||
50 | (elfeed-db-unload) | ||
51 | (unless (file-exists-p script) | ||
52 | (make-directory (file-name-directory script) :parents) | ||
53 | (with-temp-buffer | ||
54 | (insert "(progn\n" | ||
55 | " (load (locate-user-emacs-file \"early-init\"))\n" | ||
56 | " (straight-use-package 'elfeed)\n" | ||
57 | " (require 'elfeed)\n" | ||
58 | " (elfeed)\n" | ||
59 | " (elfeed-update)\n" | ||
60 | " (while (> (elfeed-queue-count-total) 0)\n" | ||
61 | " (sleep-for 5)\n" | ||
62 | " (message \"%s\" (elfeed-queue-count-total))\n" | ||
63 | " (accept-process-output))\n" | ||
64 | " (elfeed-db-save-safe)\n" | ||
65 | " (elfeed-db-gc-safe))") | ||
66 | (write-file script))) | ||
67 | (set-process-sentinel (start-process-shell-command | ||
68 | "Elfeed" nil (concat "emacs --script " script)) | ||
69 | (lambda (a b) | ||
70 | (advice-remove 'elfeed #'+elfeed--update-message) | ||
71 | (setq +elfeed--update-running nil) | ||
72 | (message "[Elfeed] Background update %s." | ||
73 | (string-trim b)))))) | ||
74 | |||
75 | (defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.") | ||
76 | (defvar +elfeed--update-first-time 6 "How long to wait for the first time.") | ||
77 | (defvar +elfeed--update-repeat (* 60 15) "How long between updates.") | ||
78 | |||
79 | (defun +elfeed--cancel-update-timer () | ||
80 | "Cancel `+elfeed--update-timer'." | ||
81 | (unless +elfeed--update-running | ||
82 | (ignore-errors (cancel-timer +elfeed--update-timer)) | ||
83 | (setq +elfeed--update-timer nil))) | ||
84 | |||
85 | (defun +elfeed--reinstate-update-timer () | ||
86 | "Reinstate `+elfeed--update-timer'." | ||
87 | (setq +elfeed--update-timer | ||
88 | (run-at-time +elfeed--update-first-time | ||
89 | +elfeed--update-repeat | ||
90 | #'+elfeed-update-command))) | ||
91 | |||
92 | (define-minor-mode +elfeed-update-async-mode | ||
93 | "Minor mode to update elfeed async-style every 15 minutes." | ||
94 | :global t | ||
95 | (if +elfeed-update-async-mode | ||
96 | (progn ; enable | ||
97 | (+elfeed--reinstate-update-timer) | ||
98 | (advice-add 'elfeed :before '+elfeed--cancel-update-timer) | ||
99 | (advice-add 'elfeed-search-quit-window :after '+elfeed--reinstate-update-timer)) | ||
100 | (progn ; disable | ||
101 | (advice-remove 'elfeed '+elfeed--cancel-update-timer) | ||
102 | (advice-remove 'elfeed-search-quit-window '+elfeed--reinstate-update-timer) | ||
103 | (+elfeed--cancel-update-timer)))) | ||
104 | |||
34 | (provide '+elfeed) | 105 | (provide '+elfeed) |
35 | ;;; +elfeed.el ends here | 106 | ;;; +elfeed.el ends here |