A new major version of emacs is out, and it includes dbus support. This is great, because it means we can do things like this:


(require 'dbus)
(defun send-desktop-notification (summary body timeout)
"call notification-daemon method METHOD with ARGS over dbus"
(dbus-call-method
:session ; use the session (not system) bus
"org.freedesktop.Notifications" ; service name
"/org/freedesktop/Notifications" ; path name
"org.freedesktop.Notifications" "Notify" ; Method
"emacs"
0
""
summary
body
'(:array)
'(:array :signature "{sv}")
':int32 timeout))

(defun pw/compile-notify (buffer message)
(send-desktop-notification "emacs compile" message 0))

(setq compilation-finish-function 'pw/compile-notify)


Add this to your .emacs file and you will receive a libnotify popup when M-x compile completes. It will even give you the exit message, so you know whether the compile was successful.

So now you can let that long compile run, and work on something else. emacs will let you know when the compile finishes.

As written above, the notifications will stay on your screen until you dismiss them (by clicking on them). If you would like them to vanish after a preset time limit, change the 0 in the call to send-desktop-notification. Set it to the number of milliseconds the popup should remain on the screen.

[caption id="attachment_173" align="alignright" width="300" caption="Screenshot of libnotify popup showing a compiler error"]Screenshot of libnotify popup showing a compiler error[/caption]

This is just the tip of the iceberg, of course. Any application that presents a dbus interface can be interacted with from emacs, which means that emacs can also integrate itself with the Linux desktop in other interesting ways.