From efc08126f7119569112b336f0cd73eefdf9737b5 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 18 Jan 2022 17:18:06 -0600 Subject: Um --- lisp/+elfeed.el | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'lisp/+elfeed.el') 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 @@ ;;; Code: -(require 'elfeed) - ;; https://karthinks.com/software/lazy-elfeed/ (defun +elfeed-scroll-up-command (&optional arg) "Scroll up or go to next feed item in Elfeed" @@ -31,5 +29,78 @@ (interactive) (elfeed-show-visit t)) +;;; Fetch feeds async +;; https://github.com/skeeto/elfeed/issues/367 + +(defun +elfeed--update-message () + (message "[Elfeed] Update in progress") + 'ignore) + +(defvar +elfeed--update-running nil "Whether an update is currently running.") + +(defun +elfeed-update-command () + (interactive) + (let ((script (expand-file-name "~/.local/bin/elfeed"))) + (message "[Elfeed] Updating in the background.") + (setq +elfeed--update-running t) + (elfeed-db-save) + (advice-add 'elfeed :override #'+elfeed--update-message) + (ignore-errors (kill-buffer "*elfeed-search*")) + (ignore-errors (kill-buffer "*elfeed-log*")) + (elfeed-db-unload) + (unless (file-exists-p script) + (make-directory (file-name-directory script) :parents) + (with-temp-buffer + (insert "(progn\n" + " (load (locate-user-emacs-file \"early-init\"))\n" + " (straight-use-package 'elfeed)\n" + " (require 'elfeed)\n" + " (elfeed)\n" + " (elfeed-update)\n" + " (while (> (elfeed-queue-count-total) 0)\n" + " (sleep-for 5)\n" + " (message \"%s\" (elfeed-queue-count-total))\n" + " (accept-process-output))\n" + " (elfeed-db-save-safe)\n" + " (elfeed-db-gc-safe))") + (write-file script))) + (set-process-sentinel (start-process-shell-command + "Elfeed" nil (concat "emacs --script " script)) + (lambda (a b) + (advice-remove 'elfeed #'+elfeed--update-message) + (setq +elfeed--update-running nil) + (message "[Elfeed] Background update %s." + (string-trim b)))))) + +(defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.") +(defvar +elfeed--update-first-time 6 "How long to wait for the first time.") +(defvar +elfeed--update-repeat (* 60 15) "How long between updates.") + +(defun +elfeed--cancel-update-timer () + "Cancel `+elfeed--update-timer'." + (unless +elfeed--update-running + (ignore-errors (cancel-timer +elfeed--update-timer)) + (setq +elfeed--update-timer nil))) + +(defun +elfeed--reinstate-update-timer () + "Reinstate `+elfeed--update-timer'." + (setq +elfeed--update-timer + (run-at-time +elfeed--update-first-time + +elfeed--update-repeat + #'+elfeed-update-command))) + +(define-minor-mode +elfeed-update-async-mode + "Minor mode to update elfeed async-style every 15 minutes." + :global t + (if +elfeed-update-async-mode + (progn ; enable + (+elfeed--reinstate-update-timer) + (advice-add 'elfeed :before '+elfeed--cancel-update-timer) + (advice-add 'elfeed-search-quit-window :after '+elfeed--reinstate-update-timer)) + (progn ; disable + (advice-remove 'elfeed '+elfeed--cancel-update-timer) + (advice-remove 'elfeed-search-quit-window '+elfeed--reinstate-update-timer) + (+elfeed--cancel-update-timer)))) + (provide '+elfeed) ;;; +elfeed.el ends here -- cgit 1.4.1-21-gabe81