I am a big fan of Kanban. I wrote Kanban-Dashboards with a decent metric analysis in Filemaker Pro and in Excel. However, some features I missed there and since my workflow is moving towards Emacs I would like to track my progress there. The Keyword here is org-mode, obviously. I already can generate a decent cumulative flow diagram (Kudos to Sacha Chua!). One thing that keeps puzzling me though is how/whether I can limit the number of tasks for a given TODO-status.

Lets say, for example, that you have the Tasks TODO - DOING - DONE and would like to impose a WIP-limit on the middle-status. Is there a way so that I cannot change a task's status to "DOING" when already two tasks are on "DOING"?

Another possibility would be to show the exceeding tasks in another color - is this possible in an Agenda?

  • You need to do the goto the bottom thing (goto-char (point-max)), then do the re-search-backward thing (re-search-backward "\\* doing" nil t), and find out whether there is another task that meets the search criteria (plus any additional criteria, e.g., more than two, etc.) -- if it matches, then either do or don't do something. We do the goto to the bottom thing, instead of the goto to the top thing, because searching backwards leaves point at the beginning of the todo -- i.e., it's more efficient and we don't need to do org-back-to-heading.
    – lawlist
    Mar 21, 2015 at 19:27
  • It should be possible to implement something similar to the built-in support for TODO dependencies. It looks like there is an org-blocker-hook that is used to check if a task should be blocked from changing state, so perhaps you could add a custom hook that counts the number of tasks in the next state. (See e.g. org-block-todo-from-children-or-siblings-or-parent.)
    – glucas
    Mar 21, 2015 at 19:33
  • I wonder if you could use org-scan-tags with the todo-only argument and a custom action that counts TODOs in a given state. Then use that in an org-blocker-hook to compare the current count with the limit.
    – glucas
    Mar 21, 2015 at 19:40

1 Answer 1


Org has support for blocking a TODO state change, used to implement TODO dependencies.

You should be able to leverage this to implement a work in progress limit:

  • Use org-scan-tags to implement a custom function to count the number of TODO items in a given state.

  • Add a custom function to org-blocker-hook that counts the number of items in a given state and compares it to a configured limit.

Here's some code that seems to do the trick. This will prevent you from moving a task to the DOING state if there are already two or more tasks in that state. You can set org-wip-state and org-wip-limit to customize the limit.

(defun org-count-todos-in-state (state)
  (let ((count 0))
    (org-scan-tags (lambda ()
                     (when (string= (org-get-todo-state) state)
                       (setq count (1+ count))))
                   t t)

(defvar org-wip-limit 2  "Work-in-progress limit")
(defvar org-wip-state "DOING")

(defun org-block-wip-limit (change-plist)
  (catch 'dont-block
    (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
              (not (string= (plist-get change-plist :to) org-wip-state)))
      (throw 'dont-block t))

    (when (>= (org-count-todos-in-state org-wip-state) org-wip-limit )
      (setq org-block-entry-blocking (format "WIP limit: %s" org-wip-state))
      (throw 'dont-block nil))

    t)) ; do not block

(add-hook 'org-blocker-hook #'org-block-wip-limit)
  • Hi glucas, thanks for the answer. I tried to implement it by pasting the code into scratch and at first it works rather decent. Thats why I wanted to post a variation of the code inside my .emacs-file. However, now it is not working anymore. I removed the hook with (remove-hook 'org-blocker-hook #'org-block-wip-limit) and re-added it but it did not came back to life... Do you know what I am doing wrong?
    – Phil Ipp
    Mar 26, 2015 at 21:21
  • Hard to say without seeing code/Messages/etc. Are you using the same code in your init file? You may want to put it in an eval-after-load so that it gets loaded after org-mode. If you end up messing up the list of functions in a hook variable you can set it to nil and try again, e.g. (setq org-blocker-hook nil). You can check if the hook is being called at all by adding a (message "calling wip limit hook") at the top of the org-block-wip-limit function.
    – glucas
    Mar 27, 2015 at 14:22
  • Thanks, glucas, now it (almost) works. In fact, it essentially works and I have expanded it in such a way that two tasks now have a WIP-limit. Thanks!
    – Phil Ipp
    Mar 27, 2015 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.