0

I am trying to log all my todos in a archive.org file, by means of the following function:

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

The part to move the todos to the archive works, but (org-todo 'done) isn't working and in the archive the todo appears as TODO and not as DONE. If I try to eval (org-todo 'done) in org-buffer with M-: (org-todo 'done), it works so I don't know what's happening.

1 Answer 1

3

Your code works fine, the problem is the key binding. You are binding this key sequence in the global map. When you are in an org buffer, that binding will instead be resolved against org-mode-map, so you'll get the default archive command.

You can verify this: in your org buffer, try C-h k C-c C-x C-s and you'll see it is bound to org-archive-subtree.

There are various ways to bind the key for org mode. For example:

(add-hook 'org-mode-hook
          (lambda () (local-set-key "\C-c\C-x\C-s" 'mark-done-and-archive)))

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.