annabunches.net/content/posts/2009-08-31-emacs-23-dbus-and-libnotify.md

2.7 KiB

excerpt_separator category layout title date author tags modified_time blogger_id blogger_orig_url
<br/> technology post emacs 23, dbus, and libnotify 2009-08-31T18:47:00.000-04:00 Anna Wiggins
emacs
programming
Technology
2013-10-22T11:19:50.826-04:00 tag:blogger.com,1999:blog-4209116010564764361.post-6878792725228849848 http://www.stringofbits.net/2009/08/emacs-23-dbus-and-libnotify.html

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.