Integrating Emacs’ org-mode with the Awesome window manager

Posted: March 4, 2009 in awesome, Emacs, GNU/Linux
Tags: , ,

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?%):)", "<span style="text-decoration: underline;">%1</span>")
   -- 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) ", "<strong>%1</strong> ")
   -- 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

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

    Thanks for sharing.

  2. Alan Busby says:

    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).

    • Tassilo Horn says:

      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.

  3. Giovanni Ridolfi says:

    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.

  4. Tassilo Horn says:

    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…

  5. Reynaldo says:

    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.

    • Tassilo Horn says:

      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.

  6. micah says:

    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!

    • Tassilo Horn says:

      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.).

  7. Michael Campbell says:

    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! =)

    • Tassilo says:

      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,…

    • Azure says:

      I just use xmodmap to turn my Caps Lock into the Super key:

      remove lock = Caps_Lock
      remove control = Control_R
      clear mod1
      clear mod3
      clear mod4
      clear mod5
      keysym Caps_Lock = Super_L
      keysym Control_R = Hyper_R
      keysym Alt_L = Meta_L
      keysym Print = Multi_key

      add mod1 = Meta_L
      add mod3 = Alt_L
      add mod4 = Hyper_R
      add mod5 = Super_L

  8. overdrive says:

    Every time that I join in your blog is awesome! congratulations for this post!! :-)

    Borja Tarraso

  9. steelman says:

    I had to replace

    mytextbox.mouse_enter = show_org_agenda

    (and mouse_leave of course)

    with

    mytextbox:add_signal(“mouse::enter”, show_org_agenda)

    To make it work with my awesome 3.4.3. I still don’t know how did you do highligting (and monospaced font).

  10. steelman says:

    I think you should have escaped the tagging in the lua code with html entities like < > (ampersand-“lt”-semicolon). Neither “pre” nor “code” tag prohibits html tags from being parsed.

  11. azer says:

    Hi Tassilo, I’ve modified the lua code to make it work with Awesome3.4. Here it is: http://gist.github.com/410732

Leave a Reply

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

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 )

Google+ photo

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

Connecting to %s