I have a list of repeatable tasks. Sometimes I deactivate them by changing state to CANCELED. But when I do it the new SCHEDULE is created in the future. To prevent that from happening I change timestamp to inactive by hand, and when I want to bring this repeatable task back to TODO I have to remember to activate timestamp.
I could remove timestamp from task before canceling it, and set it again if necessary, but I want to keep it as inactive in case I would like to return to it in the future, so I know repeatable setting from the past.
How could I make task timestamp (DEADLINE and/or SCHEDULED) inactive while switching to CANCELED state, and active while changing it to TODO automatically?
EDIT: I managed to put together something like this, but it doesn't work.
(defun jarfar/org-state-canceled-timestamp-toggle ()
"Toggle active/inactive SCHEDULED or DEADLINE timestamp when switching between CANCELED and TODO state."
(save-excursion
(let ((state (org-get-todo-state)))
(cond
((equal state "CANCELED")
(when (and
(org-get-deadline-time (point))
(search-forward-regexp "DEADLINE: .*" nil t)
(null (deactivate-mark))
(equal (char-to-string (char-after)) ">"))
(org-toggle-timestamp-type))
(when (and
(org-get-scheduled-time (point))
(search-forward-regexp "SCHEDULED: .*" nil t)
(null (deactivate-mark))
(equal (char-to-string (char-after)) ">"))
(org-toggle-timestamp-type)))
((equal state "TODO")
(when (and
(org-get-deadline-time (point))
(search-forward-regexp "DEADLINE: .*" nil t)
(null (deactivate-mark))
(equal (char-to-string (char-after)) "]"))
(org-toggle-timestamp-type))
(when (and
(org-get-scheduled-time (point))
(search-forward-regexp "SCHEDULED: .*" nil t)
(null (deactivate-mark))
(equal (char-to-string (char-after)) "]"))
(org-toggle-timestamp-type)))))
(when (equal (buffer-name (current-buffer)) "*Org Agenda*")
(with-current-buffer "*Org Agenda*" (org-agenda-redo)))))
(add-hook 'org-after-todo-state-change-hook 'jarfar/org-state-canceled-timestamp-toggle)
org-after-todo-state-change-hook
.