2
votes

How could I achieve this within Emacs org-mode? Do I need to write some elisp code? I want to refile my DONE tasks to a Anti-todo heading on the same org file. The thing is would like to easily get a sense of what I accomplished during the day. If I archive then at the movement I lose track of what I got DONE during the day. For example:

* Projects
** TODO Task 1
* Anti-todo
** DONE DId some stuff
** DONE Did some other stuff

When I switch Task 1 to DONE I would like it to refile itself to Anti-todo

1
Some elisp will have to be written. Could you add some more detail about where it will refile itself too? Some brief examples could help too. - Eric Johnson

1 Answers

3
votes

org-mode has a function for doing this, it's called org-sort-entries. The command prompts for the sorting type, in your case that would be "o".

To have it do the above automatically add this to your config file:

(defun xmonk/org-sort-todo-list ()
  "Sort buffer in todo order."
  (interactive)
  (save-excursion
    (mark-whole-buffer)
    (org-sort-entries nil ?o))
  (org-overview))


(add-hook 'org-after-todo-state-change-hook 'xmonk/org-sort-todo-list)

The auto refiling on changing the state from Todo to Done, is a bit tricky and cause errors, but the code to do it would be something like this:

(setq org-refile-use-outline-path "Anti-todo")

(defun xmonk/org-refile-done()
  (interactive)
  (beginning-of-buffer)
  (re-search-forward "DONE")
  (if (match-beginning 0)
    (let ((org-refile-targets '((nil :maxlevel . 5))))
      (org-refile nil (current-buffer)))))

Then you can call it from the above hook like so:

(add-hook 'org-after-todo-state-change-hook 'xmonk/org-refile-done)

It will still ask you to confirmation that you want to refile under the Anti-todo heading.