如何配置Emacs以将完成的任务存档到存档文件?

问题描述 投票:1回答:1

我将所有任务保存在todo.org文件中。任务完成后,我想选择并将其存档到单独的archive.org文件中。我想在我的配置文件中设置它,当然,不是作为每个文件头。

我试过这个:

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

这似乎有效;我看到一条消息,表明任务已归档到我选择的路径。但是 - 当我打开archive.org时,什么都没有。永远。然后,每当我关闭并重新打开Emacs时,我都会看到错误消息Symbol's value as variable is void: org-directory

那么:如何正确配置Emacs以将我选择的任务存档到正确的位置?仍然是一个组织模式的新手,所以有怜悯。

编辑:使用Emacs 25.3.2和Org 9.1.7。

emacs org-mode
1个回答
2
投票

因为O.P.也表达了(在原始问题下面的评论中)自动保存目标存档缓冲区的愿望,这个答案也解决了这个问题:

(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)
© www.soinside.com 2019 - 2024. All rights reserved.