summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-04-02 13:53:11 -0500
committerCase Duckworth2022-04-02 13:53:39 -0500
commitabf24e71c784111a65f56dc6613c020495c49927 (patch)
tree67b5b1c80617d4514e1e6ffcf49d7f96d9b10592
parentChange default mpv viewer to cache (diff)
downloademacs-abf24e71c784111a65f56dc6613c020495c49927.tar.gz
emacs-abf24e71c784111a65f56dc6613c020495c49927.zip
Enable +elfeed-update-command to run only sometimes
-rw-r--r--init.el13
-rw-r--r--lisp/+elfeed.el17
2 files changed, 25 insertions, 5 deletions
diff --git a/init.el b/init.el index 8e92143..3c1d975 100644 --- a/init.el +++ b/init.el
@@ -1394,8 +1394,17 @@ See also `crux-reopen-as-root-mode'."
1394 (:hook #'reading-mode) 1394 (:hook #'reading-mode)
1395 (:option +elfeed--update-repeat (* 60 30) ; 1/2 hour 1395 (:option +elfeed--update-repeat (* 60 30) ; 1/2 hour
1396 +elfeed--update-first-time 60)) 1396 +elfeed--update-first-time 60))
1397 (+elfeed-update-async-mode -1) ; It really messes with stuff for work 1397 (+elfeed-update-async-mode +1)
1398 ) 1398 (add-hook '+elfeed-update-proceed-hook (defun non-work-hours? ()
1399 "Return nil if during work hours, t otherwise."
1400 (let* ((now (current-time))
1401 (now* (decode-time now))
1402 (work-start* (append '(0 0 8) (cdddr now*))) ; 8:00 AM
1403 (work-end* (append '(0 0 18) (cdddr now*))) ; 6:00 PM
1404 (work-start (encode-time work-start*))
1405 (work-end (encode-time work-end*)))
1406 (or (time-less-p now work-start)
1407 (time-less-p work-end now))))))
1399 1408
1400(setup (:straight elfeed-org) 1409(setup (:straight elfeed-org)
1401 (:also-load +org-capture) 1410 (:also-load +org-capture)
diff --git a/lisp/+elfeed.el b/lisp/+elfeed.el index 7f9e193..c0b74f0 100644 --- a/lisp/+elfeed.el +++ b/lisp/+elfeed.el
@@ -133,6 +133,19 @@ If multiple items are selected, don't advance."
133(defvar +elfeed--update-first-time 6 "How long to wait for the first time.") 133(defvar +elfeed--update-first-time 6 "How long to wait for the first time.")
134(defvar +elfeed--update-repeat (* 60 15) "How long between updates.") 134(defvar +elfeed--update-repeat (* 60 15) "How long between updates.")
135 135
136(defcustom +elfeed-update-proceed-hook nil
137 "Predicates to query before running `+elfeed-update-command'.
138Each hook is passed no arguments."
139 :type 'hook)
140
141(defun +elfeed-update-command-wrapper ()
142 "Run `+elfeed-update-command', but only sometimes.
143If any of the predicates in `+elfeed-update-proceed-hook' return
144nil, don't run `+elfeed-update-command'. If they all return
145non-nil, proceed."
146 (when (run-hook-with-args-until-failure '+elfeed-update-proceed-hook)
147 (+elfeed-update-command)))
148
136(defun +elfeed--cancel-update-timer () 149(defun +elfeed--cancel-update-timer ()
137 "Cancel `+elfeed--update-timer'." 150 "Cancel `+elfeed--update-timer'."
138 (unless +elfeed--update-running 151 (unless +elfeed--update-running
@@ -142,12 +155,10 @@ If multiple items are selected, don't advance."
142(defun +elfeed--reinstate-update-timer () 155(defun +elfeed--reinstate-update-timer ()
143 "Reinstate `+elfeed--update-timer'." 156 "Reinstate `+elfeed--update-timer'."
144 ;; First, unload the db 157 ;; First, unload the db
145 (elfeed-db-save)
146 (elfeed-db-unload)
147 (setq +elfeed--update-timer 158 (setq +elfeed--update-timer
148 (run-at-time +elfeed--update-first-time 159 (run-at-time +elfeed--update-first-time
149 +elfeed--update-repeat 160 +elfeed--update-repeat
150 #'+elfeed-update-command))) 161 #'+elfeed-update-command-wrapper)))
151 162
152(define-minor-mode +elfeed-update-async-mode 163(define-minor-mode +elfeed-update-async-mode
153 "Minor mode to update elfeed async-style." 164 "Minor mode to update elfeed async-style."