I often forget add TODO for my task, any idea?

I try to manager all my tasks in ~/projects/org/*/*.org, but often forget to add TODO keyword in headline, so stuff org-agenda cannot see them. Of course, always use org-capture to add task can solve this problem, but if I'm just in my task.org, invoke org-capture is a little redundant.

Posted Feb 12, 2020, 3:59 AM UTC

14
MCHerb•

You can configure a before-save-hook to ensure all headers have a TODO.

(defun my/ensure-todos-set-hook ()
  "Ensure all headers under a certain path have TODO."
  (when-let ((filename (buffer-file-name))
             ((f-parent-of? "/home/USER/org/agenda-files" filename))
             ((f-ext? filename "org")))
    (save-excursion
      (goto-char (point-min))
      (loop do (outline-next-heading)
            while (outline-on-heading-p)
            do (unless (org-get-todo-state)
                 (forward-whitespace 1)
                 (insert "TODO "))))))

(add-hook 'before-save-hook 'my/ensure-todos-set-hook)
4
floscr•

In Doom Emacs we have org-insert-below/above, which inserts a new item below or above the current one with the matching TODO prefix already applied.

This is bound to C-Enter/C-Shift-Enter

Here's the function: https://github.com/hlissner/doom-emacs/blob/11bfb178948e610931c8fe6640a831c06393f4cc/modules/lang/org/autoload/org.el#L239

Maybe you can extract that functionality.

2
-dag-•

Why is it redundant? I always capture tasks regardless of which buffer I'm visiting.

1
gusbrs•

There's org-insert-todo-heading, bound by default to "<M-S-return>" and "C-c C-x M".

1