Org-mode and habits

Posted: - Modified: | emacs, org

Org Mode is a personal information manager for the Emacs text editor. People have contributed a ton of useful features to it over the years, and the development shows no sign of slowing down. One of the features I’ve been playing around with is the ability to track habits.

Org habits are recurring tasks. For example, everyday, I want to:

  • take my vitamins
  • capture a quick note about the day, and
  • plan the next day

Every week, I want to:

  • talk to my mom
  • check the org-mode mailing list
  • write a weekly review and plan the next week
  • clear and reorganize my belt bag
  • clear my inbox
  • write a bunch of blog posts
  • back up my computer

Once a month, I want to:

  • update the topical index for my blog
  • review and uninstall programs
  • balance my books and update my budget
  • review the past month and plan the next
  • check the library for new books

Org habits let me manage my task list without cluttering future days with tasks. The Org agenda view displays habits that are due today, indicating consistency with colour. In particular, it shows overdue days in red, so you can get the Seinfeld-esque pleasure/commitment-device of not breaking the chain.

Here’s a view from Sunday:

2 days-agenda (W19-W20):
Sunday     13 May 2012
               8:00...... ----------------
              10:00...... ----------------
              12:00...... ----------------
              14:00...... ----------------
              15:57...... now - - - - - - - - - - - - - - - - - - - - - - - - -
              16:00...... ----------------
              18:00...... ----------------
  organizer:  22:00...... TODO Capture a one-sentence note                                           !       
  organizer:  22:00...... TODO Plan the next day                                    ** ***** ** *****!       
  organizer:  Scheduled:  TODO Make a list of recipes I want to learn
  organizer:  Scheduled:  TODO Write a bunch of blog posts             :writing:
  organizer:  Scheduled:  TODO Set up WordPress as my backup system
Monday     14 May 2012 W20
  organizer:  Scheduled:  TODO Build Emacs interface so that I can have Org automatically switch my tasks

To use Org habits, customize org-modules and enable the habit module. To set something as a habit, use C-c C-x p (org-set-property) to set the STYLE property to habit. For more information, you should definitely check out the Org manual’s section on habits.

Yay Emacs and the people who contribute to it!

You can view 30 comments or e-mail me at sacha@sachachua.com.

30 comments

I had no idea this functionality existed in org-mode. Will definitely have a look, it's something that I've needed for a long time. Thanks for the tip!

Greg Tucker-Kellogg

2012-05-16T07:51:01Z

This is really useful, but I can't seem to figure out one part. According to the org manual, "What’s really useful about habits is that they are displayed along with a consistency graph, to show how consistent you’ve been at getting that task done in the past.". How does one activate this graph? Where should I expect to see it? It doesn't show up in my agenda view.

Greg Tucker-Kellogg

2012-05-16T08:22:50Z

Oh, never mind, I had things misconfigured a bit

This sounds really good! But how can I get started? I downloaded it but have no idea what to do next!

Soha: Gosh, Emacs has a bit of a learning curve. This beginner's guide might be useful, and you might also try looking for beginner's guides to Emacs. Someday I may write a from-scratch tutorial. Are you on Microsoft Windows, Mac OS X, or some kind of Linux?

Truong Nghiem

2012-05-16T23:29:40Z

This seems very useful. However I have a question. I want to create a habit that repeats every weekday, i.e. I want to do it every Monday to Friday, but not necessarily on Saturday and Sunday. Can I do that in orgmode? If yes then how?

Soha,

The best way to learn Emacs, in my opinion, is:

1. Take a week off from what you do.

2. Open Emacs

3. Press C-h t (i.e. Control+h followed by t).

Trust me, you will thank yourself for taking that week off.

-- Varun Vats

Another area that emacs is taking some interesting steps in personal information managing is the "notmuch" system for email. It's a tag & text indexer for email that has been integrated with emacs (and mutt if you prefer mutt).
It's got a viewer for mail indexes and threads, although if you want there is an integration with GNUS. I use the notmuch viewers. The thread view shows the email thread subjects that match a tag/text search. Message view mode shows the thread contents.
Integration with email composing, delivery etc., is limited but works. It's still a do-it-yourself operation for integration with procmail or other delivery systems. It uses on GNUS or Mutt for composing email and other mail operations.
It's now past the "too fragile for anyone but developers" stage. It's into the "mostly working system ready for lots of improvements" stage. It's growing rapidly as more people start filling the gaps. I can see some interesting potential for linkages with org-mode as it stabilizes.
I'm forced to use Notes at work and the difference in capabilities and performance as a mail manager is huge. It makes the slow Notes performance painful.

Sacha, the manual doesn't actually explain how to customize the org-modules and enable habits... and you weren't clear on how to do it.
I added the following to my .emacs file:
(add-to-list 'org-modules 'org-habit)
(require 'org-habit)

Nuno: <kbd>M-x customize-variable RET org-modules</kbd> gets you lots of great options. =) There are so many - I should check them out!

rjh: Envy. =) I should get mail working in my Microsoft Windows setup again.

Truong Nghiem: Doesn't look like there are weekday repeats for habits, but you can probably get away with making it a daily habit and then also marking it done during the weekends.

Thanks, Sacha, I now feel like a kid in a candy store! :)

Thanks, Varun ...and Sacha, I'm using Microsoft Windows. I'll check out your beginners guide. I don't know if I can take a whole week off but I'll try to fit in somehow!

Raymond Zeitler

2012-05-20T05:24:39Z

Thanks! I was wondering how Org-mode does recurrence, and now I know!

Hi Sacha, How did you produce that agenda view?

Hi Sacha, I Like reading your blogs, and got the inspiration to use emacs, though i am a no programmer, had an experience as a Unix SA, and have an inclination to learn programming and i like the way you treat the topic. As I was reading in this post of yours about org-habits, I couldn't figure out how i may be able to use it. I use emacs 24 but i didn't find org-modules in it. If you could let me know how its done. It would be helpful.

Sorry for the delay! You should be able to use M-x customize-variable RET org-modules RET to add or remove items from that list. In addition, check out the documentation in org-habits ( http://orgmode.org/manual/T... to see the property you need to add (:STYLE: habit) and how to specify the repetition frequency in the Scheduled line. Hope that helps!

Hi Sacha, inspired by your posts about org-mode I decided to give it a shot. Currently I'm a bit stuck customizing a journal flow for me. When creating a new entry I want the head of that entry to be a timestamp including the option to tag it. My template looks like this: ("t" "Journal Entry test" plain
(file+datetree "~/orgmode/journaltest.org")
"**** %U %^g \n%?"))

This does almost what I want, but for some reason I don't understand this puts the newest entry at top of the sublist, I would expect it to be appended to the list. So this is what happens:

* 2015
** 2015-10 Oktober
*** 2015-10-07 Mittwoch
**** [2015-10-07 Mi 14:33]
**** [2015-10-07 Mi 14:31]
**** [2015-10-07 Mi 14:30]

and that's what I would expect (want):
* 2015
** 2015-10 Oktober
*** 2015-10-07 Mittwoch
**** [2015-10-07 Mi 14:30]
**** [2015-10-07 Mi 14:31]
**** [2015-10-07 Mi 14:33]

Any help is greatly appreciated :-)

That _is_ strange, since mine adds to the bottom of the list by default... Is this something you should check with the Org Mode mailing list? It shouldn't add to the beginning of the list unless you have the :prepend keyword, which you don't have in your template.

Andrei Beliankou

2016-07-13T16:58:53Z

Dear Sacha,

how did you manage to combine scheduled tasks and your habits in one place in the agenda shown above?

Habits are just scheduled tasks with a special property (:STYLE: habit), so if you set them up according to the Org Mode manual section on habits and enable org-habit-show-habits, they should appear. Hope that helps!

I also wondered how to do that. Here's the solution: You can achieve this (having scheduled habits together with other scheduled items) by modifying the variable org-agenda-sorting-strategy. You have to make sure that, for the agenda view, the time indication is used for sorting before the habit property. So, put time-up/time-down before habit-down/habit-up, for example like this in your .emacs:
'(org-agenda-sorting-strategy
(quote
((agenda time-up habit-down priority-down category-keep) ;; this was originally: (agenda habit-down time-up priority-down category-keep)
(todo priority-down category-keep)
(tags priority-down category-keep)
(search category-keep))))

Awesome, thanks for sharing!

Andrei Beliankou

2017-02-22T15:58:42Z

Thank you very much, that is exactly what I was looking for :)

Emmanuel Goldstein

2017-09-02T14:26:38Z

Hi Sacha, how do you enable org-modules?

M-x customize-variable, or you can look for org-modules in my config at http://sachachua.com/dotemacs to see how I do it with (setq org-modules ...) and (org-load-modules-maybe t).

Emmanuel Goldstein

2019-01-17T07:46:59Z

Dear Sacha: I couldn't find this anywhere else, so I ask you, you Emacs Goddess. Can you SCHEDULE a task setting simultaneously its DEADLINE date? I only seem to be able to create two entries for the same task (one SCHEDULED and another one DEADLINE). Thanks in advance!

You should be able to use the keyboard shortcut to schedule the task, and another to set the deadline. If you do this a lot, you might consider making your own function that does both.

Emmanuel Goldstein

2019-01-18T18:27:38Z

Then, you need two lines in your org file, right? But I just found out the following:

* TITLE OF ITEM
SCHEDULED: <2019-01-16 Wed> DEADLINE: <2019-02-10 Sun>

If you put them in the same line, it will create both the scheduled and the deadline event!

... oh, were you typing those in by hand? I just use the keyboard shortcuts (C-c C-s and C-c C-d, I think), which take care of putting them on the same line.

Emmanuel Goldstein

2019-01-24T14:13:50Z

Silly me...