I work with org-mode TODO lists not in org-agenda mode, but within the actual .org files, marking TODO headings DONE as I go.

* DONE buy milk
* TODO fix car
* STARTED call mom

I want org to move point to the next TODO heading once I mark it as DONE. But not before, i.e. when I mark a TODO heading as STARTED, I want point to stay on that heading:

(setq org-todo-keywords
(sequence "TODO" "STARTED" "|" "DONE")

How do I get org to move point to next TODO heading upon state change to DONE?

I tried this...

(add-hook 'org-after-todo-state-change-hook
(lambda () (org-next-visible-heading 1)) )

...but it doesn't work because the hook is executed within a save-excursion block.

I tried this...

(defun bb/next-heading (&rest args)
(org-next-visible-heading 1))
(advice-add 'org-todo :after 'bb/next-heading)

...which works, but triggers upon ANY state change. How do I make it so org-next-visible-heading gets triggered ONLY when a TODO heading is marked DONE?

  • 1
    The answer to the first question would be either (when (org-entry-is-done-p) (outline-next-visible-heading 1)) or the more specific (when (string= (org-get-todo-state) "DONE") (outline-next-visible-heading 1)).
    – mutbuerger
    Oct 9, 2015 at 16:39
  • How would I place that in a function / hook / advice? Oct 9, 2015 at 17:19
  • 1
    I'd extend your bb/next-heading defun: (defun bb/next-heading (&rest args) (when (org-entry-is-done-p) (outline-next-visible-heading 1)))
    – mutbuerger
    Oct 9, 2015 at 17:41
  • Yes that works! Oct 9, 2015 at 17:46
  • Put it in an answer and I'll break the other into a separate question. Oct 9, 2015 at 17:47

1 Answer 1


In your bb/next-heading defun you could use either (when (org-entry-is-done-p) (outline-next-visible-heading 1)) that regards all org-done-keywords or (when (string= (org-get-todo-state) "DONE") (outline-next-visible-heading 1)) to be more restrictive.

(defun bb/next-heading (&optional arg)
  (when (org-entry-is-done-p) (outline-next-visible-heading 1)))
(advice-add 'org-todo :after 'bb/next-heading) 
  • When using the :after keyword argument, the 'advice function' receives the same arguments as the 'advised function', therefore (currently) the bb/next-heading should have an argument list of the form (&optional arg) here. Apr 15, 2022 at 7:07

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.