开发者

How to archive all the DONE tasks using a single command

To archive the DONE tasks i am using

C-c C-x a

command. The draw back is i have to manually move over the DONE tasks one by one and then archive it.

How to archive all the DON开发者_JAVA百科E tasks using a single command.


You can bulk archive (or refile/change todo etc) from within the Agenda view.

http://orgmode.org/manual/Agenda-commands.html#Agenda-commands

If you call Org-Agenda from within the buffer you want to archive you can temporarily restrict it to only that buffer and view only todo entries and filter for only DONE

C-c a < t
N r

Where N corresponds to the shortcut for your DONE state (with default states it would be 2)

Then you'd simply need to mark all the desired headlines and bulk archive

m (mark for bulk action)
B a (or B $ for arch->sibling)


Here's a corrected version of madalu's snippet. Note that this version also only operates on the current subtree (change 'tree back to 'file to operate over the entire file).

(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))


You can write a function using org-map-entries:

(defun my-org-archive-done-tasks ()
  (interactive)
  (org-map-entries 'org-archive-subtree "/DONE" 'file))


Also from http://orgmode.org/manual/Moving-subtrees.html#Moving-subtrees

C-u C-c C-x C-s

Check if any direct children of the current headline could be moved to the archive. To do this, each subtree is checked for open TODO entries. If none are found, the command offers to move it to the archive location. If the cursor is not on a headline when this command is invoked, the level 1 trees will be checked.


There is now a command org-archive-all-done that is built into org-mode, and in org-archive.el.


If you want to do it in the source Org buffer (as opposed to in an Org agenda view), and if they are following each other, you can select all of them in a region, and apply a command (such as C-c C-t d).

Only setting needed:

;; Some commands act upon headlines in the active region.
(setq org-loop-over-headlines-in-active-region 'start-level)


Based on Robert's Answer

(require 'org)
(require 'org-archive)
(add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook 'org-archive-all-done nil t)))


I found the direct "org-map-entries" method in a couple of these answers to be a little "fragile" for some reason in situations with more varied nesting and TODOs at multiple levels.

This method - generating a list and then archiving in reverse (to avoid changes in positioning) seems to cover every use case I've thrown at it. Sharing it here for anyone else that runs into trouble.

Note the "TODO" string match on the last line needs to match how you have your TODOs defined exactly (for example in a vanilla case, the match may be: "TODO=\"DONE\"").

(defun org-archive-done-tasks ()
  "Archive all tasks marked DONE in the file."
  (interactive)
  (mapc (lambda(entry)
          (goto-char entry)
          (org-archive-subtree))
        (reverse (org-map-entries (lambda () (point)) "TODO=\"★ DONE\"" 'file))))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜