refactor(org-checklist): combine advice and patch

This commit is contained in:
Kiana Sheibani 2025-04-03 06:21:12 -04:00
parent cdd56bfafe
commit 848c27d1d0
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -3326,12 +3326,6 @@ The simple package =org-checklist= from =org-contrib= makes it so that checkboxe
(add-hook 'org-after-todo-state-change-hook #'org-checklist))) (add-hook 'org-after-todo-state-change-hook #'org-checklist)))
#+end_src #+end_src
The ~org-checklist~ function will reset the checkboxes on any task, but I only want them reset when the task repeats.
#+begin_src emacs-lisp
(advice-add #'org-checklist :before-while #'org-get-repeat)
#+end_src
I don't want to have to specify the =RESET_CHECK_BOXES= property for every TODO I write, though. I would much prefer if it was on by default, and the system allowed me to turn it off if I wanted to. Luckily, the fine control Org gives you over property inheritance nicely fixes this problem. I don't want to have to specify the =RESET_CHECK_BOXES= property for every TODO I write, though. I would much prefer if it was on by default, and the system allowed me to turn it off if I wanted to. Luckily, the fine control Org gives you over property inheritance nicely fixes this problem.
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -3340,9 +3334,13 @@ I don't want to have to specify the =RESET_CHECK_BOXES= property for every TODO
(defpatch! org-checklist (defpatch! org-checklist
(defun org-reset-checkbox-state-maybe) () (defun org-reset-checkbox-state-maybe) ()
(el-patch-concat
"Reset all checkboxes in an entry if the `RESET_CHECK_BOXES' property is set" "Reset all checkboxes in an entry if the `RESET_CHECK_BOXES' property is set"
(el-patch-add " and if the entry has a repeating timestamp."))
(interactive "*") (interactive "*")
(if (org-entry-get (point) "RESET_CHECK_BOXES" (el-patch-add t)) (if (el-patch-wrap 2
(and (org-get-repeat)
(org-entry-get (point) "RESET_CHECK_BOXES" (el-patch-add t))))
(org-reset-checkbox-state-subtree))) (org-reset-checkbox-state-subtree)))
#+end_src #+end_src