From abf24e71c784111a65f56dc6613c020495c49927 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Apr 2022 13:53:11 -0500 Subject: Enable +elfeed-update-command to run only sometimes --- init.el | 13 +++++++++++-- lisp/+elfeed.el | 17 ++++++++++++++--- 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'." (:hook #'reading-mode) (:option +elfeed--update-repeat (* 60 30) ; 1/2 hour +elfeed--update-first-time 60)) - (+elfeed-update-async-mode -1) ; It really messes with stuff for work - ) + (+elfeed-update-async-mode +1) + (add-hook '+elfeed-update-proceed-hook (defun non-work-hours? () + "Return nil if during work hours, t otherwise." + (let* ((now (current-time)) + (now* (decode-time now)) + (work-start* (append '(0 0 8) (cdddr now*))) ; 8:00 AM + (work-end* (append '(0 0 18) (cdddr now*))) ; 6:00 PM + (work-start (encode-time work-start*)) + (work-end (encode-time work-end*))) + (or (time-less-p now work-start) + (time-less-p work-end now)))))) (setup (:straight elfeed-org) (: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." (defvar +elfeed--update-first-time 6 "How long to wait for the first time.") (defvar +elfeed--update-repeat (* 60 15) "How long between updates.") +(defcustom +elfeed-update-proceed-hook nil + "Predicates to query before running `+elfeed-update-command'. +Each hook is passed no arguments." + :type 'hook) + +(defun +elfeed-update-command-wrapper () + "Run `+elfeed-update-command', but only sometimes. +If any of the predicates in `+elfeed-update-proceed-hook' return +nil, don't run `+elfeed-update-command'. If they all return +non-nil, proceed." + (when (run-hook-with-args-until-failure '+elfeed-update-proceed-hook) + (+elfeed-update-command))) + (defun +elfeed--cancel-update-timer () "Cancel `+elfeed--update-timer'." (unless +elfeed--update-running @@ -142,12 +155,10 @@ If multiple items are selected, don't advance." (defun +elfeed--reinstate-update-timer () "Reinstate `+elfeed--update-timer'." ;; First, unload the db - (elfeed-db-save) - (elfeed-db-unload) (setq +elfeed--update-timer (run-at-time +elfeed--update-first-time +elfeed--update-repeat - #'+elfeed-update-command))) + #'+elfeed-update-command-wrapper))) (define-minor-mode +elfeed-update-async-mode "Minor mode to update elfeed async-style." -- cgit 1.4.1-21-gabe81