Org my life

org-mode is an amazing tool, you can use it to write documents, make spreadsheets, track to-do list, generate agendas, etc. If you use Emacs a lot, you don't want to miss this unicorn.

I mainly use it as my notebook, and GTD tool.

This post is about how I configured it to be my single daily use GTD tool.

Customized Task

I use 5 different states of my task item. WAITING and CANCELED are abnormal cases, when switching to these states, note of reason should be added, as well as time-stamp, if task is done, it switches to DONE state, with a time-stamp, but no note needed.

1
2
3
(setq org-todo-keywords
(quote ((sequence "TODO(t)" "STARTED(s)" "WAITING(w@/!)"
"|" "DONE(d!/!)" "CANCELLED(c@/!)"))))

What are the meaning of the single characters such as "t", "s", "w"?

They're the shortcuts to switch task state, C-c C-t and type "s", task is started, type "d", task done.

1
2
;; Enable task switching shortcuts
(setq org-use-fast-todo-selection t)

To make states look clear, I set some colors for each state.

1
2
3
4
5
6
(setq org-todo-keyword-faces
(quote (("TODO" :foreground "red" :weight bold)
("STARTED" :foreground "blue" :weight bold)
("DONE" :foreground "forest green" :weight bold)
("WAITING" :foreground "orange" :weight bold)
("CANCELLED" :foreground "forest green" :weight bold))))

Sometimes, tasks contain sub-tasks, it looks messy if I mark the task done, but some sub-tasks are in other states. I prefer task will be automatically mark as done only if all sub-tasks are done.

1
2
3
4
5
6
;; Parent can't be marked as done unless all children are done
(setq org-enforce-todo-dependencies t)
(defun org-summary-todo (n-done n-not-done)
"Switch entry to DONE when all subentries are done, to TODO otherwise."
(let (org-log-done org-log-states) ; turn off logging
(org-todo (if (= n-not-done 0) "DONE" "TODO"))))

Handy Capture

I store all my tasks in one single file named "work.org", it contains lots of task items, different categories, adding task directly to it is not an easy job.

Org capture saves me, when I think something might need to do, just C-c c, then, select a capture template, and record it.

Later, to move it to work.org, just type C-c C-w.

I save all captures in refile.org, and templates as follow,

1
2
3
4
5
6
7
8
9
10
(setq org-default-notes-file "~/Dropbox/Documents/org/refile.org")
(setq org-capture-templates
(quote (("t" "Todo" entry (file "~/Dropbox/Documents/org/refile.org")
"* TODO %?\n OPENED: %U\n %i")
("n" "Note" entry (file "~/Dropbox/Documents/org/refile.org")
"* %?\n OPENED: %U\n %i")
("j" "Journal" entry (file "~/Dropbox/Documents/org/refile.org")
"* %?\n OPENED: %U\n %i")
("h" "Habit" entry (file "~/Dropbox/Documents/org/refile.org")
"* TODO %?\n SCHEDULED: %t\n OPENED: %U\n :PROPERTIES:\n :STYLE: habit\n :END:\n %i"))))

Come to The Cloud

We live in a cloud era, services are weak if can't be accessed from anywhere, any device.

I want to see my agendas, and tasks in my iPhone, lucky me, guys make MobileOrg, although it's not fully functional as a GTD tool, but it works.

To use MobileOrg via Dropbox, accessing to Dropbox should be authorized, and a folder MobileOrg will be created after.

In Emacs, some configuration need to be added.

1
2
3
4
(setq org-mobile-directory "~/Dropbox/MobileOrg")
(setq org-directory "~/Dropbox/Documents/org")
(setq org-mobile-inbox-for-pull "~/Dropbox/Documents/org/refile.org")
(setq org-mobile-files(quote ("~/Dropbox/Documents/org/work.org")))

Below settings tell org-mobile where to find captures, tasks and agendas, org-mobile-push will transfer them to MobileOrg folder, which will be synced to Dropbox.

Grab an iPhone, open MobileOrg, tap sync, you get all your tasks and agendas.

Everything you changed in iPhone, will be synced to Dropbox (don't worry, just diffs, small amount of data). org-mobile-pull will get the changes and apply it, for my example, the changes will be applied to work.org and refile.org.

But manually do this is so inefficient, hooks can be added to pull everything in cloud during Emacs startup, and push every changes to cloud during quitting Emacs.

1
2
(add-hook 'after-init-hook 'org-mobile-pull)
(add-hook 'kill-emacs-hook 'org-mobile-push)

But this will slow down Emacs startup, I don't like it. So another way comes, automatically sync when you are idle in Emacs, like drinks coffee, or walks away.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(defvar org-mobile-sync-timer nil)
(defvar org-mobile-sync-idle-secs (* 60 10))
(defun org-mobile-sync ()
(interactive)
(org-mobile-pull)
(org-mobile-push))
(defun org-mobile-sync-enable ()
"enable mobile org idle sync"
(interactive)
(setq org-mobile-sync-timer
(run-with-idle-timer org-mobile-sync-idle-secs t
'org-mobile-sync)));
(defun org-mobile-sync-disable ()
"disable mobile org idle sync"
(interactive)
(cancel-timer org-mobile-sync-timer))
(org-mobile-sync-enable)

This will pull, then push org files after 10 minutes idle time.