Inspired by tomterl on #emacs-circe
who posted this configuration snippet, and
Julien Danjou’s erc-desktop-notifications.
- Adds desktop notifications to Circe.
- Won’t send a notification unless the channel is in
tracking-buffers
, i.e. not currently visible. - Avoids getting spammed by one nickname if they are messaging you a lot.
After the first notification from some-user you will not get another
notification from them until
circe-notifications-wait-for
seconds have elapsed. - Optional list of nicknames or words which can trigger a notification.
- Optionally detects whether Emacs is focused by the window manager. For
example, if you’re reading some documentation in Firefox and Emacs is
hidden you may wish to receive notifications even for buffers that would be
visible in Emacs. This feature requires X11,
xdotool
andxorg-xprop
. - Works in OSX with
terminal-notifier
.
(autoload 'enable-circe-notifications "circe-notifications" nil t)
(eval-after-load "circe-notifications"
'(setq setq circe-notifications-watch-nicks
'("people" "you" "like" "to" "hear" "from")))
(add-hook 'circe-server-connected-hook 'enable-circe-notifications)
If you use X11 you may wish to (setq circe-notifications-check-window-focus
t)
, although this depends on xorg-xprop
and xdotool
.
If you like to use Emacs in a terminal emulator, it can detect that too provided
that you (setq circe-notifications-term-name "my-favourite-terminal")
and the
terminal sets WM_NAME
to something containing the string “emacs”.
(autoload 'enable-circe-notifications "circe-notifications" nil t)
(eval-after-load "circe-notifications"
'(setq circe-notifications-watch-nicks
'("people" "you" "like" "to" "hear" "from")
circe-notifications-backend "terminal-notifier"))
(add-hook 'circe-server-connected-hook 'enable-circe-notifications)
Some people asked me how to use this in OSX. You can use Eloy Durán’s
terminal-notifier
instead of dbus
. Get it here. Note that you won’t be
able to use any of those tools that rely on X11.
If you use the configuration above with something like ZNC you will endure a deluge of notifications upon buffer playback.
Short of patching a new RPL code into both ZNC and Circe specifically for this,
the only way to deal with it is to count occurrences of (string-equal command
"NOTICE")
and (string-equal host "znc.in")
for each network on ZNC and
(add-hook 'circe-receive-message-functions 'circe-notifications)
after that.
The number of notices depends on how many networks you are connecting to and how many lines are in ZNC’s MOTD. It’s a massive kludge but here’s how I do it.
;; Warning: this is very dumb
;;
;; ZNC's MOTD is 25 lines.
;; I have two networks defined in `circe-network-options'.
;; So wait to see 50 notices from ZNC before enabling notifications.
(defvar eqyiel-circe-znc-notices 0
"How many notices have we received from ZNC?")
(defvar eqyiel-circe-znc-motd-length 25
"How many lines are in ZNC's MOTD?")
(defun eqyiel-circe-znc-count-networks ()
"Return the number of networks in `circe-network-options' multiplied by
`eqyiel-circe-znc-motd-length', so we can know how many notices to expect before
enabling notifications."
(* eqyiel-circe-znc-motd-length (list-length circe-network-options)))
(defun eqyiel-circe-wait-for-znc (nick user host command args)
(if (> (eqyiel-circe-znc-count-networks) eqyiel-circe-znc-notices)
(when (and (string-equal host "znc.in")
(string-equal command "NOTICE"))
(setq eqyiel-circe-znc-notices (+ 1 eqyiel-circe-znc-notices))
(message "That's %d ..." eqyiel-circe-znc-notices))
(progn
(message "OK.")
(remove-hook 'circe-receive-message-functions 'eqyiel-circe-wait-for-znc)
(enable-circe-notifications))))
(defadvice circe-reconnect (before eqyiel-remove-circe-notifications)
(setq eqyiel-circe-znc-notices 0)
(remove-hook 'circe-receive-message-functions 'circe-notifications)
(add-hook 'circe-receive-message-functions 'eqyiel-circe-wait-for-znc))
(add-hook 'circe-receive-message-functions 'eqyiel-circe-wait-for-znc)
Alternatively, you can M-x enable-circe-notifications
after the buffer
playback is done.