I am trying to automatically toggle a 'blocking' tag to a todo entry based on certain conditions. The tag label is #Ordered
.
I have two todo keywords EPIC
and PHASE
that should receive this tag when calling the function. The tag should only be applied if there exists a 'previous sibling' in a 'todo state' in the buffer.
To illustrate, I add a few examples:
=> BEGIN BUFFER
* PHASE Do not tag at BOF
* EPIC This should receive the tag
* TODO This should not receive the tag
* PHASE This should receive the tag
=> END BUFFER
=> BEGIN BUFFER
* DONE This should not receive the tag
* PHASE This should not receive the tag
* EPIC This sould receive the tag
* PHASE This should receive the tag
There is one more edge case I have not even tried to cover yet, and I would be more than happy if only the cases above where working ! I still mention it for the sake of completeness.
* PHASE should not be tagged
* DONE shoud not be tagged
* PHASE this should be tagged in theory
I have tried many different approach, I will just post my latest failure that basically tags everything but DONE tasks. I find it hard to go to previous sibling, and check if we got a todo state without throwing an error if there is no previous sibling.
Please do not mind missing parenthesis, I removed irrelevant parts of the code for more clarity so to speak :)
(when-let ((todo (org-entry-get (point) "TODO")))
(if (and (= 1 (org-current-level))
(member todo '("PHASE" "EPIC")))
(progn
(let ((ordered nil))
(save-excursion
(if (org-get-previous-sibling)
(setq ordered (org-entry-is-todo-p)
)))
(if ordered
(org-toggle-tag "#Ordered"))))
previous sibling
a node in the same subtree at the same level as the node you are dealing with? That is my guess, but I just wanted to make absolutely sure.