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 (or whatever the extension may be) usually located
at the tippity-top of the project, or in more technical terms, the
project root.
It's sort of annoying having to manually find-file
anytime I'd like
to make a change to my to-do list. As a result of this frustration, I
wrote this tiny function which automatically opens the to-do file from
anywhere inside (or outside if not within) the target project.
(defun +project-todo () "Edit the to-do file at the root of the current project." (interactive) (let* ((project (project-root (project-current t))) (todo (car (directory-files project t "^TODO\\(\\..*\\)?$")))) (cond ((and todo (file-exists-p todo)) (find-file todo)) (t (message "Project does not contain a TODO 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, we should append a list of the form (COMMAND LABEL &optional
KEY)
if we'd like to see its shortcut listed.
(add-to-list 'project-switch-commands '(project-todo "Todo" "t"))
Additionally, map the function to something memorable.
(global-set-key (kbd "C-x p t") 'project-todo)
And that's it, we're all set.