From 40a6acaf56f5525c683942665b9231085412cda9 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 21 Jan 2022 09:29:49 -0600 Subject: Being working on +elfeed-update-async --- lisp/+elfeed.el | 55 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'lisp/+elfeed.el') diff --git a/lisp/+elfeed.el b/lisp/+elfeed.el index ef93347..4a874c3 100644 --- a/lisp/+elfeed.el +++ b/lisp/+elfeed.el @@ -40,7 +40,7 @@ (defun +elfeed-update-command () (interactive) - (let ((script (expand-file-name "~/.local/bin/elfeed"))) + (let ((script (expand-file-name "~/.local/bin/elfeed-update.el"))) (message "[Elfeed] Updating in the background.") (setq +elfeed--update-running t) (elfeed-db-save) @@ -51,21 +51,46 @@ (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))) + (insert + (nconcat nil + "#!/usr/bin/env -S emacs --script" + ;; I have to load the necessary files + "(load (locate-user-emacs-file \"early-init\"))" + "(straight-use-package 'elfeed)" + "(straight-use-package 'elfeed-org)" + "(require 'elfeed)" + "(require 'elfeed-org)" + ;; And set needed variables + `("(setq rmh-elfeed-org-files '(" + ,(mapconcat (lambda (el) + (format "\"%s\"" el)) + rmh-elfeed-org-files + " ") + "))") + ;; Overwrite log function to go to stdout + "(defun elfeed-log (level fmt &rest objects)" + " (princ (format \"[%s] [%s]: %s\\n\"" + " (format-time-string \"%F %T\")" + " level" + " (apply #'format fmt objects))))" + ;; Load elfeed + "(elfeed-org)" + "(elfeed-db-load)" + "(elfeed)" + ;; Update elfeed + "(elfeed-update)" + ;; Wait to finish ... I think. + "(while (> (elfeed-queue-count-total) 0)" + " (sleep-for 5)" + " (message \"%s\" (elfeed-queue-count-total))" + " (accept-process-output))" + ;; Save and garbage-collect + "(elfeed-db-save)" + "(elfeed-db-gc)")) + (write-file script)) + (chmod script #o777)) (set-process-sentinel (start-process-shell-command - "Elfeed" nil (concat "emacs --script " script)) + "Elfeed" nil script) (lambda (a b) (advice-remove 'elfeed #'+elfeed--update-message) (setq +elfeed--update-running nil) -- cgit 1.4.1-21-gabe81