如何在org-agenda中设置一个键,将任务标记为DONE,然后将其归档?

时间:2016-11-19 19:21:04

标签: emacs org-mode key-bindings

如何在org-agenda中设置一个键,将任务标记为DONE,然后将其归档?

在我的组织议程中,我有一个标记为已完成的关键(由Sacha Chua提供):

(defun sacha/org-agenda-done (&optional arg)
  "Mark current TODO as done.
This changes the line at point, all other lines in the agenda referring to
the same tree node, and the headline of the tree node in the Org-mode file."
  (interactive "P")
  (org-agenda-todo "DONE"))
;; Override the key definition for org-exit
(define-key org-agenda-mode-map "x" 'sacha/org-agenda-done)

我有一个用于存档条目的密钥(在存档文件中保存上下文,由https://gist.github.com/CodeFalling/87b116291aa87fde72cb中的@codefalling提供):

(define-key org-agenda-mode-map "z" 'org-agenda-archive)

但是当我尝试将两者合并为一个键时,我部分失败了,因为在归档条目后,emacs不会在org-agenda模式下返回原始缓冲区:

(defun jyby/org-agenda-mark-done-and-archive ()
"Mark the current TODO as done and archive it."
(interactive)
(org-agenda-todo "DONE")
(save-excursion
  (org-agenda-switch-to)
  (org-archive-subtree-hierarchical)
  )
)
(define-key org-agenda-mode-map "D" 'jyby/org-agenda-mark-done-and-archive)

知道为什么吗?

(为了记录,我确实尝试使用save-current-buffer功能,但没有用。)

当然,我还想取消并存档一个键:

(defun jyby/org-agenda-cancel-and-archive ()
    "Mark the current TODO as done and archive it."
    (interactive)
    (save-current-buffer
      (org-agenda-todo "CANC")
      (org-agenda-switch-to)
      (org-archive-subtree-hierarchical)
      )
    )
(define-key org-agenda-mode-map "C" 'jyby/org-agenda-cancel-and-archive)

0 个答案:

没有答案