Open danielkrajnik opened 1 year ago
That's a good question. I had never thought of it.
My first idea would be to update elfeed-notifier--update-hook
:
(defun elfeed-notifier--update-hook (&rest _)
"Hook that is run every time the elfeed db changes.
It takes `elfeed-notifier-query' filter and query the db with it to get
the number."
(let* ((filter (elfeed-search-parse-filter elfeed-notifier-query))
(func (byte-compile (elfeed-search-compile-filter filter)))
(count 0))
(with-elfeed-db-visit (entry feed)
(when (funcall func entry feed count)
(setf count (1+ count))))
(setq elfeed-notifier-alert-mode-line
(funcall elfeed-notifier-modeline-formatter count))))
The last part
(setq elfeed-notifier-alert-mode-line
(funcall elfeed-notifier-modeline-formatter count))
is where we update the global variable elfeed-notifier-alert-mode-line
with the number of unread elfeed entries. You could call the function that trigger the notification there
Thank you, I resorted to adding a hook in elfeed itself for now - it seemed to work although it stops working when I try to parse the entry (and I don't know how to debug it other than waiting for new articles each time).
If I won't get this to work in the end I will try the elfeed-notifier-alert-mode-line
.
(add-hook 'elfeed-new-entry-hook
(lambda (entry)
(alert (prin1-to-string (elfeed-deref (elfeed-entry-content entry)))
:title (prin1-to-string (elfeed-entry-feed-id entry))
:severity 'high
)
))
and I don't know how to debug it other than waiting for new articles each time
Ah I see, may be you can:
extract your lambda function in a named function, this way you will be able to refer to it in a (remove-hook)
call
try to use with-elfeed-db-visit
The doc says
Visit each entry in the database from newest to oldest.
Use ‘elfeed-db-return’ to exit early and optionally return data.
(with-elfeed-db-visit (entry feed)
(my-function entry)
This way you can grab one entry, and try to pass it to your function. Then you can use elisp/emacs debugging mechanism (check (elisp) Instrumenting ). I'm not an expert in elisp debugging, but I often use C-u eval-defun
, it will make your function stop at each step of your function and you can inspect the current state
Thanks, I will try that, but another issue is that the hook doesn't always fire at all - it seems to work only every fifth time or so. I've developed it a bit further, but it's hard to tell what exactly may be causing elfeed to ignore it even when manually running elfeed-update
with new feed entries appearing:
(add-hook 'elfeed-new-entry-hook
(lambda (entry)
(alert (prin1-to-string (elfeed-deref (elfeed-entry-content entry)))
:title (concat
(prin1-to-string (elfeed-entry-tags entry)) " - "
(prin1-to-string (elfeed-entry-feed-id entry)) " - "
(prin1-to-string (elfeed-entry-title entry))
)
:severity 'high
)
))
Hi, I've forked the repo and trying to add
(alert)
function to alert the user with a desktop notification when new articles become available. Could you please let me know where in the code it can be added?Sorry if it's a bit blunt question, but I can't trace the logic flow without breaking it.