2

I make a function that move from TODO state to DONE and archive it in the archives files, and I set org-mode-map to make this function by a keybinding, but in agenda it doesn't change the TODO state. I tried to find a org-agenda-mode-map or something similar but I can't find it. My function is:

(defun mark-done-and-archive ()
   (interactive)
   (org-todo 'done)
   (org-archive-subtree))
 (define-key org-mode-map "\C-c\C-x\C-s" 'mark-done-and-archive)

EDIT

So when in my TODOS.org file I hit C-c C-x C-s the todo automatically is marked as DONE and move from TODOS.org to archive.org but when I make this in org-agenda buffer the todo is moved from his file well, the only problem is that it isn't marked as done. As example:

Archive todos.org

* TODO one todo from todo.org * TODO Another todo

So I open todos.org and complete the first todo so I hit C-c C-x C-s and the file todos.org now contains:

* TODO Another todo

and archive.org contains: DONE one todo from todo.org

But when I show my org-agenda and * TODO Another todo it's show, I try to complete and move to my archive file, again with C-c C-x C-s but I obtain the following in archive.org:

* DONE one todo from todo.org * TODO Another todo

and todos.org it's empty.

0

1 Answer 1

1

org-mode maintains two sets of functions for most things. The 'normal' version (like org-todo) and the agenda version (org-agenda-todo). If you rewrite your function to use the agenda version, all will be well:

(defun agenda-mark-done-and-archive ()
   (interactive)
   (org-agenda-todo 'done)
   (org-agenda-archive))
 (define-key org-agenda-mode-map "\C-c\C-x\C-s" 'agenda-mark-done-and-archive)

Internally, org-agenda-archive works by calling org-archive-subtree. So if we use advice we can modify org-archive-subtree to first mark things as done and then do whatever it normally does:

(defun org-archive-done (&optional arg)
  (org-todo 'done))

(advice-add 'org-archive-subtree :before 'org-archive-done)

This version changes the normal and agenda versions simultaneously.

Note that the help for org-archive-subtree says

The tree will be moved to that location, the subtree heading be marked DONE, and the current time will be added.

So this should already be happening. If it isn't, there may be some other issue.

2
  • Hy again, your solution works well bu after I upgrade emacs and org-mode org-agenda-mode-map is void, and I cant find another equivalent var, any help??
    – rafaelleru
    Commented Dec 29, 2016 at 18:27
  • @rafaelleru You may need to (require 'org-agenda) first to get the map to exist.
    – erikstokes
    Commented Dec 29, 2016 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.