summary refs log tree commit diff stats
path: root/lisp/+elfeed.el
diff options
context:
space:
mode:
authorCase Duckworth2022-02-08 14:15:43 -0600
committerCase Duckworth2022-02-08 14:15:43 -0600
commit2a16bbd8db063ec2272a057262891328a267b129 (patch)
treeae29bfe99654f52d8cdc360cb0f0eba1d9d1fca7 /lisp/+elfeed.el
parentMake +tab-bar-{emms,bongo} work when those libraries aren't loaded (diff)
downloademacs-2a16bbd8db063ec2272a057262891328a267b129.tar.gz
emacs-2a16bbd8db063ec2272a057262891328a267b129.zip
Change logic in +elfeed
Diffstat (limited to 'lisp/+elfeed.el')
-rw-r--r--lisp/+elfeed.el133
1 files changed, 69 insertions, 64 deletions
diff --git a/lisp/+elfeed.el b/lisp/+elfeed.el index f669afd..8a0376d 100644 --- a/lisp/+elfeed.el +++ b/lisp/+elfeed.el
@@ -40,69 +40,70 @@
40 40
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 (unless +elfeed--update-running
44 (update-message-format "[Elfeed] Background update: %s")) 44 (let ((script (expand-file-name "~/.local/bin/elfeed-update.el"))
45 (message update-message-format "start") 45 (update-message-format "[Elfeed] Background update: %s"))
46 (setq +elfeed--update-running t) 46 (message update-message-format "start")
47 (elfeed-db-save) 47 (setq +elfeed--update-running t)
48 (advice-add 'elfeed :override #'+elfeed--update-message) 48 (elfeed-db-save)
49 (ignore-errors (kill-buffer "*elfeed-search*")) 49 (advice-add 'elfeed :override #'+elfeed--update-message)
50 (ignore-errors (kill-buffer "*elfeed-log*")) 50 (ignore-errors (kill-buffer "*elfeed-search*"))
51 (elfeed-db-unload) 51 (ignore-errors (kill-buffer "*elfeed-log*"))
52 (unless (file-exists-p script) 52 (elfeed-db-unload)
53 (make-directory (file-name-directory script) :parents) 53 (unless (file-exists-p script)
54 (with-temp-buffer 54 (make-directory (file-name-directory script) :parents)
55 (insert 55 (with-temp-buffer
56 (nconcat nil 56 (insert
57 "#!/usr/bin/env -S emacs --script" 57 (nconcat nil
58 "(setq lexical-binding t)" 58 "#!/usr/bin/env -S emacs --script"
59 ;; I have to load the necessary files 59 "(setq lexical-binding t)"
60 "(load (locate-user-emacs-file \"early-init\"))" 60 ;; I have to load the necessary files
61 "(straight-use-package 'elfeed)" 61 "(load (locate-user-emacs-file \"early-init\"))"
62 "(straight-use-package 'elfeed-org)" 62 "(straight-use-package 'elfeed)"
63 "(require 'elfeed)" 63 "(straight-use-package 'elfeed-org)"
64 "(require 'elfeed-org)" 64 "(require 'elfeed)"
65 ;; And set needed variables 65 "(require 'elfeed-org)"
66 (let ((copy-environment)) 66 ;; And set needed variables
67 (dolist (var '(rmh-elfeed-org-files 67 (let ((copy-environment))
68 elfeed-db-directory 68 (dolist (var '(rmh-elfeed-org-files
69 elfeed-curl-program-name 69 elfeed-db-directory
70 elfeed-use-curl 70 elfeed-curl-program-name
71 elfeed-curl-extra-arguments 71 elfeed-use-curl
72 elfeed-enclosure-default-dir)) 72 elfeed-curl-extra-arguments
73 (push (concat "(setq " (symbol-name var) 73 elfeed-enclosure-default-dir))
74 " '" (prin1-to-string (symbol-value var)) ")\n") 74 (push (concat "(setq " (symbol-name var)
75 copy-environment)) 75 " '" (prin1-to-string (symbol-value var)) ")\n")
76 (nreverse copy-environment)) 76 copy-environment))
77 ;; Overwrite log function to go to stdout 77 (nreverse copy-environment))
78 "(defun elfeed-log (level fmt &rest objects)" 78 ;; Overwrite log function to go to stdout
79 " (princ (format \"[%s] [%s]: %s\\n\"" 79 "(defun elfeed-log (level fmt &rest objects)"
80 " (format-time-string \"%F %T\")" 80 " (princ (format \"[%s] [%s]: %s\\n\""
81 " level" 81 " (format-time-string \"%F %T\")"
82 " (apply #'format fmt objects))))" 82 " level"
83 ;; Load elfeed 83 " (apply #'format fmt objects))))"
84 "(elfeed-org)" 84 ;; Load elfeed
85 "(elfeed-db-load)" 85 "(elfeed-org)"
86 "(elfeed)" 86 "(elfeed-db-load)"
87 ;; Update elfeed 87 "(elfeed)"
88 "(elfeed-update)" 88 ;; Update elfeed
89 ;; Wait to finish ... I think. 89 "(elfeed-update)"
90 "(while (> (elfeed-queue-count-total) 0)" 90 ;; Wait to finish ... I think.
91 " (sleep-for 5)" 91 "(while (> (elfeed-queue-count-total) 0)"
92 " (message \"%s\" (elfeed-queue-count-total))" 92 " (sleep-for 5)"
93 " (accept-process-output))" 93 " (message \"%s\" (elfeed-queue-count-total))"
94 ;; Save and garbage-collect 94 " (accept-process-output))"
95 "(elfeed-db-save)" 95 ;; Save and garbage-collect
96 "(elfeed-db-gc)")) 96 "(elfeed-db-save)"
97 (write-file script)) 97 "(elfeed-db-gc)"))
98 (chmod script #o777)) 98 (write-file script))
99 (set-process-sentinel (start-process-shell-command 99 (chmod script #o777))
100 "Elfeed" nil script) 100 (set-process-sentinel (start-process-shell-command
101 (lambda (a b) 101 "Elfeed" nil script)
102 (advice-remove 'elfeed #'+elfeed--update-message) 102 (lambda (a b)
103 (setq +elfeed--update-running nil) 103 (advice-remove 'elfeed #'+elfeed--update-message)
104 (message update-message-format 104 (setq +elfeed--update-running nil)
105 (string-trim b)))))) 105 (message update-message-format
106 (string-trim b)))))))
106 107
107(defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.") 108(defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.")
108(defvar +elfeed--update-first-time 6 "How long to wait for the first time.") 109(defvar +elfeed--update-first-time 6 "How long to wait for the first time.")
@@ -116,16 +117,20 @@
116 117
117(defun +elfeed--reinstate-update-timer () 118(defun +elfeed--reinstate-update-timer ()
118 "Reinstate `+elfeed--update-timer'." 119 "Reinstate `+elfeed--update-timer'."
120 ;; First, unload the db
121 (elfeed-db-save)
122 (elfeed-db-unload)
119 (setq +elfeed--update-timer 123 (setq +elfeed--update-timer
120 (run-at-time +elfeed--update-first-time 124 (run-at-time +elfeed--update-first-time
121 +elfeed--update-repeat 125 +elfeed--update-repeat
122 #'+elfeed-update-command))) 126 #'+elfeed-update-command)))
123 127
124(define-minor-mode +elfeed-update-async-mode 128(define-minor-mode +elfeed-update-async-mode
125 "Minor mode to update elfeed async-style every 15 minutes." 129 "Minor mode to update elfeed async-style."
126 :global t 130 :global t
127 (if +elfeed-update-async-mode 131 (if +elfeed-update-async-mode
128 (progn ; enable 132 (progn ; enable
133 (+elfeed--cancel-update-timer) ; first disable any hangers-on
129 (+elfeed--reinstate-update-timer) 134 (+elfeed--reinstate-update-timer)
130 (advice-add 'elfeed :before '+elfeed--cancel-update-timer) 135 (advice-add 'elfeed :before '+elfeed--cancel-update-timer)
131 (advice-add 'elfeed-search-quit-window :after '+elfeed--reinstate-update-timer)) 136 (advice-add 'elfeed-search-quit-window :after '+elfeed--reinstate-update-timer))