Skip to content

Instantly share code, notes, and snippets.

@viiru-
Last active November 18, 2023 10:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viiru-/685134a1781816e83df68520a4862599 to your computer and use it in GitHub Desktop.
Save viiru-/685134a1781816e83df68520a4862599 to your computer and use it in GitHub Desktop.
Ement tracking.el integration
(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)
@mokrates
Copy link

mokrates commented Sep 16, 2023

tracking.el can be obtained from melpa by itself without installing circe.

@alphapapa
Copy link

@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.

@viiru-
Copy link
Author

viiru- commented Oct 15, 2023

@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..

@alphapapa
Copy link

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.

@viiru-
Copy link
Author

viiru- commented Oct 16, 2023

Seems to work exactly the same with the function attached via ement-event-hook. I have updated the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment