James
James

Reputation: 1688

How to configure Emacs to archive Done tasks to archive file?

I keep all tasks in a todo.org file. After a task is done, I'd like to select and archive it to a separate archive.org file. I want to set this up in my config file, of course, not as a per-file header.

I tried this:

(setq org-archive-location (concat org-directory "~/Dropbox/logs/archive.org::"))

Which seems to work; I see a message that the task has been archived to my chosen path. But--when I open archive.org, nothing is there. Ever. Then, whenever I close and reopen Emacs, I see the error message Symbol's value as variable is void: org-directory.

So: How do I properly configure Emacs to archive tasks I choose to the correct place? Still an Org mode neophyte, so have mercy.

EDIT: Using Emacs 25.3.2, and Org 9.1.7.

Upvotes: 1

Views: 1630

Answers (1)

lawlist
lawlist

Reputation: 13457

Inasmuch as the O.P. has also expressed (in a comment underneath the original question) a desire to automatically save the target archive buffer, this answer addresses that as well:

(require 'org)

(setq org-archive-location "~/Dropbox/logs/archive.org::")

(defun org-archive-save-buffer ()
  (let ((afile (org-extract-archive-file (org-get-local-archive-location))))
    (if (file-exists-p afile)
      (let ((buffer (find-file-noselect afile)))
        (if (y-or-n-p (format "Save (%s)" buffer))
          (with-current-buffer buffer
            (save-buffer))
          (message "You expressly chose _not_ to save (%s)" buffer)))
      (message "Ooops ... (%s) does not exist." afile))))

(add-hook 'org-archive-hook 'org-archive-save-buffer)

Upvotes: 2

Related Questions