More diving into Org Mode and Emacs.

I have a file, that serves as an inbox for most long term tasks that I want to tackle. Stuff that needs doing, books that I want to buy, books that I want to read, courses that I want to learn, movies or tv shows that I want to watch, stuff on the web that I want to catchup on, etc. etc. etc.

And all this while, I have been moving tasks into my as and when I tackle them. This meant I needed to open both files, and then cut said task out of one and paste it into the other. And as usual, I am now doing this often enough, that it’s become bothersome. Because there are a couple more files as well, that serve as inboxes.

And the same question arises, as usual. Can Emacs help with this?
The answer as it almost always is, is a big, resounding, Yes!

I know it had to do something with what Org calls a refile, since I keep using C-c C-w to move items between different headings in my daily tasks file.
So after a bit of reading the manual, reading blog posts, spelunking through the emacs stackexchange, stalking the Org Mode reddit and an hour of head scratching, I roughed up something that does what I want :)

In a nutshell, what I am doing is what Org calls, a Refile and Copy. The manual page let me know that I could do this across files too. This was exactly what I wanted. It also told me that I needed to configure org-refile-targets variable to tell Org a list of locations, that it would then let me refile my tasks to.

Having split my emacs init.el file into a set of logical files, I opened up the file that held my org settings (very imaginatively called emacs-org-mode-settings.el) and then thought a bit about what files I would want Org to pop up when I wanted to file tasks to.
Would just my daily tasks file do? What if I wanted to file something out of my daily tasks file? Or what if I wanted crisscross transfers between all my task inboxes and daily task file?

I then realised that I was already telling Org Agenda to scan my tasks folder (which holds all my productivity system files) for tasks and dates and schedules and deadlines. I decided to use the same set of files as my targets for refiling. And this turned out to be easier to do than expected. I just had to tell Org to use org-agenda-files as the value for org-refile-targets

It looks a little bit like this.

(setq org-refile-targets
      '((nil :maxlevel . 1)
	   (org-agenda-files :maxlevel . 1)))

I’m telling org-refile-targets on line 1, to look for targets in two locations.
Line 3, is what we were talking about above. Org will look to the same location that org-agenda-files points to, for its refile targets.
Line 2, is where I tell Org to include my current file, the one I am working on, as a target. It helps me move stuff in my daily tasks file from one day to another.
The maxlevel bit is to tell Org the level of headlines to show as targets. Org has headlines and sub-headlines and sub-sub-headlines.1 I just need the first level, which is why it’s set to 1.
It seemed to work, until I ran into a small stumbling block. Org would not let me refile my task at level 0, i.e. the root of the file as a level 1 headline. It could only nest under an existing headline. So, line 4 below, fixes that for me.

(setq org-refile-targets
      '((nil :maxlevel . 1)
	   (org-agenda-files :maxlevel . 1)))
(setq org-refile-use-outline-path 'file)

And tada! It works! You can see it in action below.
Click any of the images below to view them, larger.

The waiting task on the right (writing this post), needs to come in to my daily tasks file on the left

So I hit C-c C-w and Org Mode helpfully pops up what target it thinks I want to move my task to.2
I can hit the tab key to get a list of other files and targets.

Once I do that, the task hops over to the right place!

P.S. Subscribe to my mailing list!
Forward these posts and letters to your friends and get them to subscribe!
P.P.S. Feed my insatiable reading habit.

  1. It’s an outliner after all :) ↩︎

  2. The daily tasks file, under today’s date ↩︎