-
-
Save viiru-/685134a1781816e83df68520a4862599 to your computer and use it in GitHub Desktop.
(cl-defun viiru/ement-notify-track (event room session &key (buffer-name "*Ement Notifications*")) | |
(with-demoted-errors "viiru/ement-notify-track-if-buffer: %S" | |
(when (ement-notify--event-message-p event room session) | |
(let ((buffer (if (ement-notify--room-buffer-live-p event room session) | |
(map-elt (ement-room-local room) 'buffer) | |
(when (ement-notify--room-unread-p event room session) | |
(get-buffer buffer-name)))) | |
(faces (if (ement-notify--room-unread-p event room session) | |
'(ement-room-list-direct) | |
'(default)))) | |
(when buffer | |
(tracking-add-buffer buffer faces)))))) | |
(add-hook 'ement-event-hook #'viiru/ement-notify-track) |
@viiru- Can we add something like this to the Ement documentation, or to a wiki page? Also, I think it can be done by adding a function to the appropriate hook rather than using advice.
@alphapapa Sure. What would be the appropriate hook? There are hooks for the notification predicates, but this doesn't really fit that does it (it's not a predicate, it's something to do if the predicate matches)?
I should probably use (when (run-hook-with-args-until-success 'ement-notify-mention-predicates event room session) instead of (if (ement-notify--room-unread-p event room session), though, to make the coloring configurable..
Probably ement-event-hook
. Just be sure to use, e.g. as you did here, with-demoted-errors
or ignore-errors
, so that any errors encountered don't interrupt the processing of events and thereby prevent further syncing.
Seems to work exactly the same with the function attached via ement-event-hook. I have updated the gist.
tracking.el can be obtained from melpa by itself without installing circe.