Tassilo’s Blog

The personal blog of Tassilo Horn

Integrating Emacs’ org-mode with the Awesome window manager

with 11 comments

I’ve switched to another tiling window manager called awesome and it’s really like its name suggests. It’s more a window manager framework that can be programmed in lua to create a window manager that does exactly what you want it to do.

Awesome has a lua library called naughty for displaying notifications. Now my idea was that whenever my mouse pointer enters the region of the textbox widget that shows the current date and time in a wibox, a popup should show the agenda for this week and dispose automatically when I move the mouse away.

Ok, so here’s the code on the emacs side. It assures that the file /tmp/org-agenda.txt always contains a plain-text export of the current org agenda. It’s created once on emacs startup and after each change to any org agenda file it’ll be updated.

;; update agenda file after changes to org files
(defun th-org-mode-init ()
  (add-hook 'after-save-hook 'th-org-update-agenda-file t t))

(add-hook 'org-mode-hook 'th-org-mode-init)

;; that's the export function
(defun th-org-update-agenda-file (&optional force)
  (interactive)
  (save-excursion
    (save-window-excursion
      (let ((file "/tmp/org-agenda.txt"))
        (org-agenda-list)
        (org-write-agenda file)))))

;; do it once at startup
(th-org-update-agenda-file t)

And here’s the lua code on the awesome side:

-- the current agenda popup
org_agenda_pupup = nil

-- do some highlighting and show the popup
function show_org_agenda ()
   local fd = io.open("/tmp/org-agenda.txt", "r")
   if not fd then
      return
   end
   local text = fd:read("*a")
   fd:close()
   -- highlight week agenda line
   text = text:gsub("(Week%-agenda[ ]+%(W%d%d?%):)", "%1")
   -- highlight dates
   text = text:gsub("(%w+[ ]+%d%d? %w+ %d%d%d%d[^n]*)", "%1")
   -- highlight times
   text = text:gsub("(%d%d?:%d%d)", "%1")
   -- highlight tags
   text = text:gsub("(:[^ ]+:)([ ]*n)", "%1%2")
   -- highlight TODOs
   text = text:gsub("(TODO) ", "%1 ")
   -- highlight categories
   text = text:gsub("([ ]+%w+:) ", "%1 ")
   org_agenda_pupup = naughty.notify(
      { text     = text,
        timeout  = 999999999,
        width    = 600,
        position = "bottom_right",
        screen   = mouse.screen })
end

-- dispose the popup
function dispose_org_agenda ()
   if org_agenda_pupup ~= nil then
      naughty.destroy(org_agenda_pupup)
      org_agenda_pupup = nil
   end
end

mydatebox = widget({ type = "textbox", align = "right" }) -- shows the date
mydatebox.mouse_enter = show_org_agenda
mydatebox.mouse_leave = dispose_org_agenda

-- after that the mydatebox is added to some wibox, of course...

And that’s how it looks like.

The Org Agenda in an Awesome/Naughty popup

The Org Agenda in an Awesome/Naughty popup

Written by Tassilo Horn

March 4, 2009 at 8:06 pm

Posted in Emacs, GNU/Linux, awesome

Tagged with , ,

11 Responses

Subscribe to comments with RSS.

  1. Totally awesome looking. It’s inspired me to check out Awesome, even! :)

    Thanks for sharing.

  2. Just FYI,
    Check out dwm, which is where awesome branched from here; http://www.suckless.org/dwm/

    It’s just a super simple version of awesome with a reduced footprint, and instead of lua you modify the underlying source in C. I’ve found the biggest benefit of awesome/dwm to be the window tagging. Now one window can appear in multiple “workspaces” in different configurations (Example irc/chat window).

    Alan Busby

    March 5, 2009 at 1:51 am

    • Hi Alan,
      I used DWM some time ago, but I’m not too much into C, so configuring everything in a simple dynamic language like lua is more comfortable to me.

      With regards to tags instead of usual workspaces: yeah, it’s much more flexible, but till now I didn’t exploit the benefits. Most probably it’s out of habit, or because I use 2 big screens so that everything related to a task usually fits. Anyway, I think I have to use tagging some more and eventually adapt myself.

      Tassilo Horn

      March 5, 2009 at 7:40 am

  3. Tassillo, for the exploitation of tags in Awesome you can read the nice post of Gunnar Wolf at

    http://gwolf.org/node/1850

    where he explains very clearly the difference between tags and workspaces.

    Giovanni Ridolfi

    March 5, 2009 at 9:00 am

  4. Hi Giovanni,
    I know what distinguishes tags from workspaces and what I could do differently with them. It’s just that I haven’t used them extensively yet, most probably out of habit…

    Tassilo Horn

    March 5, 2009 at 9:16 am

  5. Which other tiled window managers did you use before?
    Alan mentioned dwm, but there is also wmii.
    You can script it in python or ruby, its advantage IMO is its file system.
    Any way, It was a nice post, I’ll try to adapt it to wmii if possible.

    Reynaldo

    March 6, 2009 at 1:11 am

    • I used stumpwm (which is great and I love lisp, but it didn’t play well with some apps I need at work, like skype and some java apps). I also tried DWM but didn’t like the custumizing in C feature. I used Xmonad as well, which is very nifty, too.

      I like awesome a bit better than the others, because it’s very easy to customize and it has powerful widgets. And I could adapt to lua very quickly.

      Tassilo Horn

      March 6, 2009 at 6:28 am

  6. I tried to replicate what you created, and I think I’m missing something on the awesome side, namely at the bottom of your config you have:

    – after that the mydatebox is added to some wibox, of course…

    I think this is the part that I must be missing, I’ve got a pretty stock config which has the date/time displayed in the upper right, with this block:

    – Hook called every second
    awful.hooks.timer.register(1, function ()
    mytextbox.text = os.date(“%a %b %d %H:%M”)
    end)

    Do I modify that somehow to use naughty?

    Thanks!

    micah

    March 6, 2009 at 3:03 am

    • Hi Micah,

      no, you don’t need any modifications. Your problem is that my textbox is named mydatebox, not mytextbox (I use several boxes).

      In your config you would need to set

      mytextbox.mouse_enter = show_org_agenda
      mytextbox.mouse_leave = dispose_org_agenda

      instead of the same with mydatebox.

      I use more than one textbox here, so that each one fulfills its own task. mydatebox shows the date and time, and pointing on it shows the agenda. Another textbox shows logging informations (disk space, battery, etc.).

      Tassilo Horn

      March 6, 2009 at 6:34 am

  7. What do you use for a mod key for awesome? I don’t have a “windows” key, and am unwilling to release the left-alt key for it, since I use emacs and I need that meta! =)

    Michael Campbell

    July 25, 2009 at 4:30 pm

    • I use the super key (which is the windows symbol here). If I hadn’t one, it would be troubled. Maybe using some “historic” key which nobody uses today is a workaround: Print, Pause,…

      Tassilo

      July 26, 2009 at 3:31 pm


Leave a Reply