fix(org): improve TODO time override

This commit is contained in:
Kiana Sheibani 2024-08-14 05:10:28 -04:00
parent 02bbdde2d2
commit 50ed195193
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -2983,10 +2983,25 @@ My attention span being what it is, I often forget to update TODO entries in my
If nil, then use the current time.")
(defadvice! ~/org-override-time (old-fn)
;; HACK: Why does Emacs have so many independently defined time functions
(defadvice! ~/org-override-time (old-fn &rest args)
"Use `org-todo-time' as the current time if it is specified."
:around #'org-current-time
(or org-todo-time (funcall old-fn)))
:around (list #'org-current-time #'org-auto-repeat-maybe)
(if org-todo-time
(cl-letf (((symbol-function #'current-time)
(lambda (&rest _) org-todo-time))
(float-time-old (symbol-function #'float-time))
((symbol-function #'float-time)
(lambda (&optional time) (funcall float-time-old (or time org-todo-time))))
(time-subtract-old (symbol-function #'time-subtract))
((symbol-function #'time-subtract)
(lambda (a b) (funcall time-subtract-old (or a org-todo-time) (or b org-todo-time))))
(decode-time-old (symbol-function #'decode-time))
((symbol-function #'decode-time)
(lambda (&optional time &rest args)
(apply decode-time-old (or time org-todo-time) args))))
(apply old-fn args))
(apply old-fn args)))
#+end_src
We can then define and bind alternate versions of ~org-todo~ and ~org-agenda-todo~ that allow us to pick the time to set.