Emacs org-mode: auto-update TODO item states to represent checkbox progress
I use org-mode TODO lists for all my tasks, including programming projects. Single "things" I want to implement in The Archive, for example, often require multiple steps to be completed, not all of which are in close proximity in code, so I keep track of these, lest I forget they have to be done!
I customized my setup a bit to update the TODO items when I work with these checkbox items.
The gist of this stuff is: automatically change TODO to DOING to DONE state when ticking off checkboxes of the item.
A detailed write-up is here: https://christiantietze.de/posts/2021/02/emacs-org-todo-doing-done-checkbox-cycling/
Example of what happens when you interact with checkboxes
* TODO finish this [0/2] - [ ] first step - [ ] second step
Ticking off one checkbox:
* DOING finish this [1/2] - [X] first step - [ ] second step
Ticking of all:
* DONE finish this [2/2] - [X] first step - [X] second step
Gist of the code
(setq org-todo-keywords (quote ((sequence "TODO(t)" "DOING(g)" "|" "DONE(d)")))) (defun org-todo-if-needed (state) "Change header state to STATE unless the current item is in STATE already." (unless (string-equal (org-get-todo-state) state) (org-todo state))) (defun ct/org-summary-checkbox-cookie () "Switch header state to DONE when all checkboxes are ticked, to TODO when none are ticked, and to DOING otherwise" (let (beg end) (unless (not (org-get-todo-state)) (save-excursion (org-back-to-heading t) (setq beg (point)) (end-of-line) (setq end (point)) (goto-char beg) ;; Regex group 1: %-based cookie ;; Regex group 2 and 3: x/y cookie (if (re-search-forward "\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" end t) (if (match-end 1) ;; [xx%] cookie support (cond ((equal (match-string 1) "100%") (org-todo-if-needed "DONE")) ((equal (match-string 1) "0%") (org-todo-if-needed "TODO")) (t (org-todo-if-needed "DOING"))) ;; [x/y] cookie support (if (> (match-end 2) (match-beginning 2)) ; = if not empty (cond ((equal (match-string 2) (match-string 3)) (org-todo-if-needed "DONE")) ((or (equal (string-trim (match-string 2)) "") (equal (match-string 2) "0")) (org-todo-if-needed "TODO")) (t (org-todo-if-needed "DOING"))) (org-todo-if-needed "DOING")))))))) (add-hook 'org-checkbox-statistics-hook #'ct/org-summary-checkbox-cookie)
Author at Zettelkasten.de • https://christiantietze.de/
It looks like you're new here. If you want to get involved, click one of these buttons!