Using Electric Indent with Org Mode

Recently I've been using electric indent mode to handle automatic indentation. It's very useful when writing code, as it indents blocks automatically when the enter key is pressed. But some of that behaviour isn't desirable when using other modes, such as org mode.

One thing I like about org-mode is the keyboard shortcuts for inserting new headlines and todo items. For example, ALT+ENTER will create a new headline beneath the current line at the correct depth.

Unfortunately, when using electric indent the headlines are indented:

Emacs org-mode with electric indentation

Thankfully the solution is relatively simple. The following code in your emacs intialization will disable electric indentation when working with org files.

(add-hook 'electric-indent-functions
	  (lambda (x) (when (eq 'org-mode major-mode) 'no-indent)))

So now you'll get the expected behaviour:

Emacs org-mode with electric indentation

Beeminder for Emacs

This is one of those strange things that really came out of nothing. This morning @bmndr tweeted the following:

It really struck a chord with me. All of my income comes from freelancing, so it's pretty important for me to be as productive as possible.

Most of my work these days is done in Emacs, and I use it for managing my various projects and todo lists. I've also been using Beeminder for the last few years to keep me on the straight and narrow.

At the end Clarissa mentions that it would nice if moving a task from TODO to DONE in Emacs could notify Beeminder. This is something I've wanted for a while, but my lisp skills are limited at best.

Thankfully Sacha Chua posted a great comment with some code that started me on the right track, and after a couple of hours of research I managed to come up with something that works.

beeminder.el is a simple extension for Emacs that adds some limited Beeminder functionality, such as fetching goals or adding data. It also integrates with org-mode, and can be configured so that closing a TODO item will add a data point to a Beeminder goal.

And it all came from just one tweet. Weird.

Project page: beeminder.el

2013 Postmortem

2013 was a bit of a mixed bag for me. Overall it was very successful, but I feel it was as balanced as I would have liked. I certainly did much better from a business standpoint, but as a result my personal projects suffered.

What went right

  • Increased my earnings – Probably my biggest win of 2013. I don't really like talking about money, but my 2013 earnings were higher than 2011 and 2012 combined.

    Sadly there's no secret formula here, I just spent a lot more time working. One thing that really helped was to set a "minimum hours billed" goal on Beeminder, which kept me moving forward on days where I'd rather not work.

  • Pushed myself – I took on some more advanced projects this year, which let me really stretch myself technically. Not only did I get to create some cool stuff, but I learnt a lot of new skills along the way.
  • Rebuilt site – This is something I'd wanted to do for a long time, and finally got around to it in September. Along with switching the backend from WordPress to Jekyll, I added a lot more content (probably more in 4 months than the 4 previous years).

    Overall I'm quite pleased with how this went, even if the actual conversion took a lot longer than I would have liked.

What went wrong

  • Let my fitness slide – I've never been particularly sporty, but I definitely noticed a drop in my overall fitness levels in 2013.
  • Didn't make any games – I try to take part in game jams at least once a year, but 2013 just didn't go right for me. I entered Ludum Dare 27, but ended up dropping out on the Saturday as I just felt burnt out from work.
  • Didn't set any goals – I didn't set any concrete goals at the start of 2013, which is probably why I feel like the year passed without me achieving anything.
  • Spent too much time unfocused – Working from home means I don't have to worry about commuting or only having a certain amount of time to get things done. As a consequence, it means work tends to stretch out over the day, and I'll often be working on things piecemeal throughout the day.

Goals for 2014

  • Get back to time boxing – I really don't like how my work hours have spilt into the rest of the day. Time boxing is something that's helped in the past, and I'd like to start using it again in 2014.
  • Improve my fitness – This is a combination of eating less junk and doing more exercise. I generally walk the dog a few miles each day, but I'd like to improve my strength and aerobic fitness.
  • Take part in the One Game a Month challenge – Even if they're only small toys, I really want to get back to making games.
  • Spend more time on personal projects – I have a huge list of personal projects, and I'd like to at least make a dent in it this year.

Here's hoping 2014 is even better!

From WordPress to Jekyll

When I first started this blog in 2006 I built it using WordPress. It's a good, solid platform with a whole bunch of useful extensions, and it's not too difficult to get it set up quickly.

The last year or so though I started adding more to the front of the site, such as resources, guides and the personal development blog list. It wouldn't have been too difficult to build these in WordPress, but it wasn't something I was particularly interested in doing. Most of my freelance work involves WordPress, so perhaps after working with it all day that's why I wasn't too excited by it.

In the end I decided to try out Jekyll. It took a bit of getting used to, but it quickly grew on me. Not only is the site much, much faster now, but I find it easier to add new stuff without worrying about creating custom plugins or templates.

Site Speed - Before and After
Figure 1: See if you can guess when the site switched to Jekyll…

Although the speed of static pages is a huge plus, for me Jekyll's strongest feature is the custom post meta. Each file has a short YAML header, and any extra data can then be accessed in templates. This made it much easier to build the resources section, and as it's plaintext it doesn't take long to add new data.

Rebuilding the site

Of course, it wouldn't be me if I didn't try and do something far more complex than necessary. The standard Jekyll layout is pretty bare-bones, and I didn't really like how pages and posts were organized. I also wanted to be able to write my posts in org-mode, which meant I needed an extra build step to do all the conversion.

My current layout looks like this:

  • _staging - This is where site files are copied to before being processed by org and built by Jekyll. Also contains a cache directory to speed up rebuilds.
  • assets - Images, styles and Javascript goes here.
  • config - Contains jekyll, emacs and other configs required to build the site
  • content - All site content lives here.
    • comments
    • pages
    • posts
  • data - Data used when generating things goes here. Mostly the bits database.
  • plugins - Jekyll & Phing plugins live here
  • scripts - Bits generation scripts live here, along with other bits of code for generating the blog list.
  • templates - Any templates live here
    • bits
    • layouts
    • partials

I use phing to manage the build process, which goes something like this:

  • Copy assets, content and templates to the _staging directory
  • Use emacs to convert org-files to html
  • Copy files to the correct place (such as moving content/posts to _posts) and rename them for nicer permalinks
  • Build stylesheet using sass
  • Build using jekyll
  • Run some cleanup filters & insert analytics code

This all goes into _staging/_to_deploy, which is then deployed to the live site using rsync. There's certainly room for improvement, but so far it's been extremely quick.


Like WordPress, Jekyll can be extended using plugins. Jekyll plugins can be used to generate additional pages from data (such as archives), or add new filters & tags to template system.

I used the following plugins (some with a little modification):

  • ancestors.rb - This adds support for accessing a page or post's ancestors. It's used to generate the breadcrumbs at the top.
  • archive_page.rb - A plugin I wrote to generate the archives page. The appearance is base on the "smart archives" plugin for WordPress.
  • category_generator.rb - Generates category pages. They're not quite as nice as WordPress's (no pagination), but they get the job done. After viewing my site stats it didn't seem worth adding "proper" category archives as virtually nobody uses them.
  • sitemap_generator.rb - Creates the sitemap used by the site.
  • static_comments.rb - Adds support for comments. Comments work in pretty much the same way as posts. Each post has a directory for comments, and each comment lives in its own file.


There were a couple of problems I ran into during the conversion:

  • I changed the permalink structure from "/blog/year/month/slug/" to just "/blog/slug/", which meant any links to old posts would no longer work.
  • Jekyll doesn't generate category or date archive pages by default, and the pages that are generated don't support pagination. Not a huge problem, but some of the most popular pages on the site were pages in the date archives.

Thankfully both of these were solvable with a little bit of nginx code:

Redirect permalinks

# Redirects old date-based slugs to just plain article
location ~ "^/blog/(\d{4})/(\d{2})/(.*)/?$" {
    return 301 /blog/$3;

Redirect date archives

# Redirect year archives to archives page
location ~ "^/blog/(\d{4})/?$" {
    return 301 /blog/archives/#archive-$1;

# Redirect month archives to archives page
location ~ "^/blog/(\d{4})/(\d{2})/?$" {
    return 301 /blog/archives/#archive-$1-$2;

The result

It's more complicated than it needs to be, but overall I'm pretty please with how the move went.

Originally site generation was quite slow (2-3 minutes), so now I cache all generated content so it only needs rebuilding if something changes. That took the build time to around 15 seconds, which is plenty quick enough for my needs.

The only issue I've had so far is the site has pretty much dropped off Google. It didn't get a huge amount of traffic before, but Google Webmaster shows it has gone from about daily search 1,000 impressions to under 50. I'm pretty sure it's due to the change in permalink structure, but I'm hoping things will get better in time.

New Emacs Guide - Emacs as a PHP Editor

I've updated the guides section with a new guide: How to set up Emacs as a PHP Editor. There are some bits I'd like to add, such as how to manage PHP projects, but it still contains some good information. I also added some new Emacs snippets to the source code section of the site.

Whilst writing the guide I came across some new extensions I really like (such as web-mode), so I've also updated the Emacs Extensions Guide.