emacs 23, dbus, and libnotify

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.

Screenshot of libnotify popup showing a compiler error

Screenshot of libnotify popup showing a compiler error

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.

Advertisement

1 Comment »

  1. Cool ! Exactly what I was looking for.

    I researched how to add an icon. On Gnome platforms you can use any file present in:

    /usr/share/pixmaps
    or
    ~/.icons

    then specify its name as the 7th argument of the dbus-call-method call.

RSS feed for comments on this post · TrackBack URI

Leave a Comment

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 134 other followers