0

I try to log all my todos in archive.org file, I make 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)

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

2

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, privacy policy and cookie policy

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