I have some item in an org buffer marked as TODO and having a scheduled timestamp:
* TODO do something
SCHEDULED: <2014-11-02 Sun>
How do I cause the SCHEDULED timestamp to be removed when I move this item to the 'waiting' state?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityI have some item in an org buffer marked as TODO and having a scheduled timestamp:
* TODO do something
SCHEDULED: <2014-11-02 Sun>
How do I cause the SCHEDULED timestamp to be removed when I move this item to the 'waiting' state?
Maybe something like this (tested briefly from buffer and agenda)
(defun rasmus/remove-schedule ()
"Remove SCHEDULED-cookie is switching state to WAITING."
(save-excursion
(and (equal (org-get-todo-state) "WAITING")
(org-get-scheduled-time (point))
(when (search-forward-regexp org-scheduled-time-regexp nil t)
(or (delete-region (match-beginning 0) (match-end 0)) t))
(get-buffer "*Org Agenda*")
(with-current-buffer "*Org Agenda*"
(org-agenda-redo)))))
(add-hook 'org-after-todo-state-change-hook
'rasmus/remove-schedule)
If you're doing this so that WAITING
items don't show up in the
agenda buffer, I'd like to suggest an alternative.
You can define WAITING
to be a DONE
-type keyword. These can easily
be configured to not display in the agenda, even when they have a
schedule. You can do that globally with this:
(setq org-todo-keywords '((sequence "TODO" "|" "WAITING" "DONE")))
Or on a per-file basis with this header:
#+SEQ_TODO: TODO | WAITING DONE
Then, to have these items not display in the agenda, just make sure you set:
(setq org-agenda-skip-scheduled-if-done t)
Finally, if you occasionally need a WAITING
item to be displayed in
the agenda, set a DEADLINE
on it instead of a SCHEDULE
. The
display of deadlines is controlled by a different variable
(org-agenda-skip-deadline-if-done
), so they will still display in the agenda.