summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-02-06 22:16:26 -0600
committerCase Duckworth2022-02-06 22:16:26 -0600
commit57c91fea2fbaca9062263219ee82492477ab1eae (patch)
treeb920587b62b6a07f964bbf3f9fe9d9af583161be
parentAdd +browse-url-other-window (diff)
downloademacs-57c91fea2fbaca9062263219ee82492477ab1eae.tar.gz
emacs-57c91fea2fbaca9062263219ee82492477ab1eae.zip
Correct elfeed-async script
-rw-r--r--lisp/+elfeed.el119
1 files changed, 62 insertions, 57 deletions
diff --git a/lisp/+elfeed.el b/lisp/+elfeed.el index 82db471..f669afd 100644 --- a/lisp/+elfeed.el +++ b/lisp/+elfeed.el
@@ -41,63 +41,68 @@
41(defun +elfeed-update-command () 41(defun +elfeed-update-command ()
42 (interactive) 42 (interactive)
43 (let ((script (expand-file-name "~/.local/bin/elfeed-update.el")) 43 (let ((script (expand-file-name "~/.local/bin/elfeed-update.el"))
44 (update-message-format "[Elfeed] Updating in the background...")) 44 (update-message-format "[Elfeed] Background update: %s"))
45 (with-temp-message update-message-format 45 (message update-message-format "start")
46 (setq +elfeed--update-running t) 46 (setq +elfeed--update-running t)
47 (elfeed-db-save) 47 (elfeed-db-save)
48 (advice-add 'elfeed :override #'+elfeed--update-message) 48 (advice-add 'elfeed :override #'+elfeed--update-message)
49 (ignore-errors (kill-buffer "*elfeed-search*")) 49 (ignore-errors (kill-buffer "*elfeed-search*"))
50 (ignore-errors (kill-buffer "*elfeed-log*")) 50 (ignore-errors (kill-buffer "*elfeed-log*"))
51 (elfeed-db-unload) 51 (elfeed-db-unload)
52 (unless (file-exists-p script) 52 (unless (file-exists-p script)
53 (make-directory (file-name-directory script) :parents) 53 (make-directory (file-name-directory script) :parents)
54 (with-temp-buffer 54 (with-temp-buffer
55 (insert 55 (insert
56 (nconcat nil 56 (nconcat nil
57 "#!/usr/bin/env -S emacs --script" 57 "#!/usr/bin/env -S emacs --script"
58 "(setq lexical-binding t)" 58 "(setq lexical-binding t)"
59 ;; I have to load the necessary files 59 ;; I have to load the necessary files
60 "(load (locate-user-emacs-file \"early-init\"))" 60 "(load (locate-user-emacs-file \"early-init\"))"
61 "(straight-use-package 'elfeed)" 61 "(straight-use-package 'elfeed)"
62 "(straight-use-package 'elfeed-org)" 62 "(straight-use-package 'elfeed-org)"
63 "(require 'elfeed)" 63 "(require 'elfeed)"
64 "(require 'elfeed-org)" 64 "(require 'elfeed-org)"
65 ;; And set needed variables 65 ;; And set needed variables
66 `("(setq rmh-elfeed-org-files '(" 66 (let ((copy-environment))
67 ,(mapconcat (lambda (el) 67 (dolist (var '(rmh-elfeed-org-files
68 (format "\"%s\"" el)) 68 elfeed-db-directory
69 rmh-elfeed-org-files 69 elfeed-curl-program-name
70 " ") 70 elfeed-use-curl
71 "))") 71 elfeed-curl-extra-arguments
72 ;; Overwrite log function to go to stdout 72 elfeed-enclosure-default-dir))
73 "(defun elfeed-log (level fmt &rest objects)" 73 (push (concat "(setq " (symbol-name var)
74 " (princ (format \"[%s] [%s]: %s\\n\"" 74 " '" (prin1-to-string (symbol-value var)) ")\n")
75 " (format-time-string \"%F %T\")" 75 copy-environment))
76 " level" 76 (nreverse copy-environment))
77 " (apply #'format fmt objects))))" 77 ;; Overwrite log function to go to stdout
78 ;; Load elfeed 78 "(defun elfeed-log (level fmt &rest objects)"
79 "(elfeed-org)" 79 " (princ (format \"[%s] [%s]: %s\\n\""
80 "(elfeed-db-load)" 80 " (format-time-string \"%F %T\")"
81 "(elfeed)" 81 " level"
82 ;; Update elfeed 82 " (apply #'format fmt objects))))"
83 "(elfeed-update)" 83 ;; Load elfeed
84 ;; Wait to finish ... I think. 84 "(elfeed-org)"
85 "(while (> (elfeed-queue-count-total) 0)" 85 "(elfeed-db-load)"
86 " (sleep-for 5)" 86 "(elfeed)"
87 " (message \"%s\" (elfeed-queue-count-total))" 87 ;; Update elfeed
88 " (accept-process-output))" 88 "(elfeed-update)"
89 ;; Save and garbage-collect 89 ;; Wait to finish ... I think.
90 "(elfeed-db-save)" 90 "(while (> (elfeed-queue-count-total) 0)"
91 "(elfeed-db-gc)")) 91 " (sleep-for 5)"
92 (write-file script)) 92 " (message \"%s\" (elfeed-queue-count-total))"
93 (chmod script #o777)) 93 " (accept-process-output))"
94 (set-process-sentinel (start-process-shell-command 94 ;; Save and garbage-collect
95 "Elfeed" nil script) 95 "(elfeed-db-save)"
96 (lambda (a b) 96 "(elfeed-db-gc)"))
97 (advice-remove 'elfeed #'+elfeed--update-message) 97 (write-file script))
98 (setq +elfeed--update-running nil) 98 (chmod script #o777))
99 (message update-message-format 99 (set-process-sentinel (start-process-shell-command
100 (string-trim b))))))) 100 "Elfeed" nil script)
101 (lambda (a b)
102 (advice-remove 'elfeed #'+elfeed--update-message)
103 (setq +elfeed--update-running nil)
104 (message update-message-format
105 (string-trim b))))))
101 106
102(defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.") 107(defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.")
103(defvar +elfeed--update-first-time 6 "How long to wait for the first time.") 108(defvar +elfeed--update-first-time 6 "How long to wait for the first time.")