summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+elfeed.el115
1 files changed, 58 insertions, 57 deletions
diff --git a/lisp/+elfeed.el b/lisp/+elfeed.el index b2a578b..82db471 100644 --- a/lisp/+elfeed.el +++ b/lisp/+elfeed.el
@@ -40,63 +40,64 @@
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")) 43 (let ((script (expand-file-name "~/.local/bin/elfeed-update.el"))
44 (update-message-format "[Elfeed] Updating in the background...%s")) 44 (update-message-format "[Elfeed] Updating in the background..."))
45 (message update-message-format "") 45 (with-temp-message update-message-format
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 ;; I have to load the necessary files 58 "(setq lexical-binding t)"
59 "(load (locate-user-emacs-file \"early-init\"))" 59 ;; I have to load the necessary files
60 "(straight-use-package 'elfeed)" 60 "(load (locate-user-emacs-file \"early-init\"))"
61 "(straight-use-package 'elfeed-org)" 61 "(straight-use-package 'elfeed)"
62 "(require 'elfeed)" 62 "(straight-use-package 'elfeed-org)"
63 "(require 'elfeed-org)" 63 "(require 'elfeed)"
64 ;; And set needed variables 64 "(require 'elfeed-org)"
65 `("(setq rmh-elfeed-org-files '(" 65 ;; And set needed variables
66 ,(mapconcat (lambda (el) 66 `("(setq rmh-elfeed-org-files '("
67 (format "\"%s\"" el)) 67 ,(mapconcat (lambda (el)
68 rmh-elfeed-org-files 68 (format "\"%s\"" el))
69 " ") 69 rmh-elfeed-org-files
70 "))") 70 " ")
71 ;; Overwrite log function to go to stdout 71 "))")
72 "(defun elfeed-log (level fmt &rest objects)" 72 ;; Overwrite log function to go to stdout
73 " (princ (format \"[%s] [%s]: %s\\n\"" 73 "(defun elfeed-log (level fmt &rest objects)"
74 " (format-time-string \"%F %T\")" 74 " (princ (format \"[%s] [%s]: %s\\n\""
75 " level" 75 " (format-time-string \"%F %T\")"
76 " (apply #'format fmt objects))))" 76 " level"
77 ;; Load elfeed 77 " (apply #'format fmt objects))))"
78 "(elfeed-org)" 78 ;; Load elfeed
79 "(elfeed-db-load)" 79 "(elfeed-org)"
80 "(elfeed)" 80 "(elfeed-db-load)"
81 ;; Update elfeed 81 "(elfeed)"
82 "(elfeed-update)" 82 ;; Update elfeed
83 ;; Wait to finish ... I think. 83 "(elfeed-update)"
84 "(while (> (elfeed-queue-count-total) 0)" 84 ;; Wait to finish ... I think.
85 " (sleep-for 5)" 85 "(while (> (elfeed-queue-count-total) 0)"
86 " (message \"%s\" (elfeed-queue-count-total))" 86 " (sleep-for 5)"
87 " (accept-process-output))" 87 " (message \"%s\" (elfeed-queue-count-total))"
88 ;; Save and garbage-collect 88 " (accept-process-output))"
89 "(elfeed-db-save)" 89 ;; Save and garbage-collect
90 "(elfeed-db-gc)")) 90 "(elfeed-db-save)"
91 (write-file script)) 91 "(elfeed-db-gc)"))
92 (chmod script #o777)) 92 (write-file script))
93 (set-process-sentinel (start-process-shell-command 93 (chmod script #o777))
94 "Elfeed" nil script) 94 (set-process-sentinel (start-process-shell-command
95 (lambda (a b) 95 "Elfeed" nil script)
96 (advice-remove 'elfeed #'+elfeed--update-message) 96 (lambda (a b)
97 (setq +elfeed--update-running nil) 97 (advice-remove 'elfeed #'+elfeed--update-message)
98 (message update-message-format 98 (setq +elfeed--update-running nil)
99 (string-trim b)))))) 99 (message update-message-format
100 (string-trim b)))))))
100 101
101(defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.") 102(defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.")
102(defvar +elfeed--update-first-time 6 "How long to wait for the first time.") 103(defvar +elfeed--update-first-time 6 "How long to wait for the first time.")