Emacs Org Mode, Part 1

How to use emacs Org-mode to plan your life?

What is org-mode

Emacs was designed as an editor when development started way back then. The editor part is still excellent after you have collected the features you want and configured them to your taste. Later, when Carsten Dominik wanted to keep track of his tasks he decided to upgrade outline mode to something more advanced. In the process he also invented a markup language. The result was org-mode, since then, many features have been added but the markup is still simple. This is the most ingenious part offered by org-mode. The features that are not obvious when you start using org-mode, except for scheduling there are also ways to collect ideas, ways to link to other files and ways to execute code inside an org-mode buffer.

Org-mode started out as a way to have an outline in your documents but has now evolved into something much bigger. In it’s current incarnation, you can use it to plan your life, your projects and to calculate your budget. As if that was not enough, you can integrate Org-mode into your regular tasks when using Emacs. The function for this is called capture. To make capture work you make the capture run on a key chord that is global to Emacs. What you capture, you can configure yourself. This configuration includes a template style system that you can use as a form and fill in the details of what you are capturing. This is just the beginning.

How do you schedule in org-mode

When you write an Org-mode file, you will add sections. Each sections is part of the outline of your document, each section can also be a task. You can then schedule the task and with the correct setup, add the task to your agenda. Tasks can also depend on each other using next as the state of the task. To add a task you create a headline and fill in the text to describe it, next you hit C-RET to create a new headline. The new headline will appear below your current one. To make it a task, hit S-<right> (Shift and right arrow keys), the headline is now in TODO mode. Hit S-<right> again and the task is DONE.

The procedure to schedule is also simple but there are a few things that are less than obvious when you start out. First, schedule your tasks. Hit M-<RET> (Alt key and return) and then ‘s’, a calendar will show up where you can choose a date. To move around hold the shift key down and use the arrow keys. Sometimes you want to do things on a regular basis, in org-mode there is a feature for this to. After you have scheduled a task you can go to the date and add, inside the ‘<‘ and ‘>’, +1d for once a day, +1w for once a week and +1m for monthly.

One problem that may happen is that you set scheduled tasks and when you check your agenda, it is empty. To make sure you have all the tasks tracked you need to register the file to your agenda. The simplest and most common way to do this is to open the file and hit the key-cord C-c [. When you have done that the mini buffer will show the text: ‘File moved to front of agenda file list’. If you add a task to the current file, it will show up in the agenda. You can also add files in your init.el file. The format is a short Lisp function as seen below.

(org-agenda-files (quote ("~/todo.org")
(quote ("~/Agenda.org")
(quote ("~/Project-file.org"))

Note that any tasks that are not scheduled will always show up in today’s list. When you are in the agenda you can go directly to your task in the corresponding file. You can also put links in your planning file to the document, project etc. To follow such a link while in an org file, use M-RET l, you will end up in the corresponding file. The links can also go to an array of other resources.

Linking your plans to your documents

The links, you can create by hitting ‘M-<RET> i l’, this results in a long list with prefixes, you need to choose one so the script can continue. After having chosen, you fill in the target and hit enter again and your link is ready. The other resources that are defined out of the box are plentiful and you can link even to the web. With this system, you can link not only to documents but also any web resources or even other applications.

How to capture ideas in org-mode

The capture function is activated and bound to a special key-binding, usually C-c c. When you activate it you get a list of types of things that you want to capture. You choose an item from that list and fill in the form. The standard form is for a task, use t to create one. A buffer opens with a heading, marked as TODO and the cursor next to it. Below is the date and further down is the text on point, this is the text where you started. You need to fill in the text of the task.

You can change the date by moving the cursor to the part you want to change, hold down shift and changing the value with the arrow keys. It is also possible to add hours. To have all your captures where you want them you need to set the default file to put them in. You do this in your init.el file that you can see a sample of below. There is a standard list of things you can capture but you can configure your own, one example is in the code below.

;; Define the default file for notes
(setq org-default-notes-file (concat org-directory "~/Org/notes.org"))
(define-key global-map "\C-cc" 'org-capture)
;; Define a template for journal entry.
(setq org-capture-templates
(("j" "Journal" entry (file+datetree "~/Org/Journal.org")
"* %?\nEntered on %U\n  %i\n  %a"))
("t" "Todo" entry (file+headline "~/Org/Agenda.org" "Tasks")
"* TODO %?\n  %i\n  %a"))

The journal entry gives you a template where you have can enter your journal text. It goes in the ~/Org/Journal.org file and the text at point is included next to a timestamp. To accomplish this, you have put %? to indicate an input, %U to set a timestamp, %i to add what is at point and %a to add an annotation.

This is the basics about using org-mode, there are many more uses that needs many more articles to cover.

About the author

Mats Tage Axelsson

I am a freelance writer for Linux magazines. I enjoy finding out what is possible under Linux and how we can all chip in to improve it. I also cover renewable energy and the new way the grid operates. You can find more of my writing on my blog.