Extending project.el with to-do functionality

When I work on a personal project which has the potential to grow beyond a few tasks, I like to maintain the project's to-do list within a TODO.org file which I like to place at the tippity-top of the project, or in more technical terms, the project root.

It's sort of annoying having to find-file anytime I want to make a change to my to-dos. So, I wrote up this tiny function which automatically opens the TODO.org file from anywhere inside the project.

(defun project-todo ()
  "Edit the TODO.org file at the root of the current project."
  (let* ((base (ignore-errors (project-root (project-current))))
         (todo (file-name-concat base "TODO.org")))
    (cond ((and base (file-exists-p todo)) (find-file todo))
          ((not base) (error "Not in a project"))
          (t (error "Project does not contain a TODO.org file.")))))

To further extend project.el, we should perhaps register this command in the list of options that appear when we switch to a project with C-x p p. The project-switch-commands variable is what we're after, and we should append an expression in the form of (COMMAND LABEL &optional KEY) if we'd like to see it listed. Let's do that.

(add-to-list 'project-switch-commands '(project-todo "Todo" "t"))

Map it to something memorable.

(global-set-key (kbd "C-x p t") 'project-todo)

And that's it, we're all set.