Search code examples
org-mode

How to archive all the DONE/DELEGATED/DEFERRED tasks using a single command


This is a follow up question on How to archive all the DONE tasks using a single command.

The solution given by Stefan works well for single DONE statement. How can it be extended to work with multiple DONE statements?

Stefan gave the following solution:

(defun org-archive-done-tasks ()
  (interactive)
  (org-map-entries
    (lambda ()
      (org-archive-subtree)
      (setq org-map-continue-from (org-element-property :begin (org-element-at-point))))
   "/DONE" 'tree))

I have the following org-todo-keywords:

(setq org-todo-keywords
      '((sequence "TODO(t)" "NEXT(n)" "WAITING(w)" "PROJECT(p)" "|" "DONE(d)" "DELEGATED" "DEFERRED")))

The goals is to archive all the tasks marked DONE, DELEGATED or DEFERRED. I have tried to use the matching as explained here, but have not been able to get it working. I tried for example:

MATCH = "/DONE|/DELEGATED|/DEFERRED"

I am new to elisp, a solution with explanation is appreciated.


Solution

  • The syntax is a bit obscure, but if I read the page that you linked to correctly, I think (untested!) that the following will work:

    "/+DONE|+DELEGATED|+DEFERRED"
    

    That's very similar to the last example on that page: select entries with a TODO property (/) that is not empty (!) and with a value of that TODO property that is DONE or DELEGATED or DEFERRED.