组织模式捕获

时间:2014-07-26 05:34:03

标签: emacs org-mode

我正努力打造一个班级'组织捕获的模板。

我想要的是轻松做出这样的条目:

* TODO <course>: Week <week> Lecture <number>
  SCHEDULED: %^T
** TODO prepare for class: <course>-<week>-<number>
   SCHEDULED: <two days before T> DEADLINE: <one day before T>
** TODO review class: <course>-<week>-<number>
   SCHEDULED: <one day after T> DEADLINE: <two days after T>

目前,我有这个模板。

(setq org-capture-templates
   '(
    ("c" "Class" entry (file "~/sydbox/personal/workflow/class.txt")
         "* TODO %^{Course}: Week %^{Week} Lecture %^{Number}\n  SCHEDULED: %(org-insert-time-stamp (org-read-date nil t nil nil nil \" \"))\n location: %^{location} %?\n** TODO %\\1: prepare lecture %\\3 from week %\\2\n   DEADLINE: %(org-insert-time-stamp (org-read-date nil t \"-1d\")) SCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"-2d\"))\n** TODO %\\1: review lecture %\\3 from week %\\2\n   DEADLINE: %(org-insert-time-stamp (org-read-date nil t \"+2d\")) SCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+1d\"))\n")
    ("e" "Exercise session" entry (file "~/sydbox/personal/workflow/class.txt")
     ))

但是,现在我不知道如何输入日期。应提示课程的日期和时间(_only_once _)。

1 个答案:

答案 0 :(得分:3)

以下代码适用于我。它首先定义一个自定义函数来创建模板(org-capture-class),它根据需要计算日期,并且比内嵌字符串更容易在眼睛上注意(注意它依赖于cl-lib,所以make确定已加载)。然后它会在模板中调用该函数,如果任何字段为空(更新以响应评论),则将其指出:

(defun org-capture-class ()
  "Capture a class template for org-capture."
  (cl-labels ((update (date days)
                      (format-time-string
                       (car org-time-stamp-formats)
                       (seconds-to-time (+ (time-to-seconds date)
                                           (* days 86400))))))
    (let ((course   (read-string "Course: " nil nil '(nil)))
          (week     (read-string "Week: " nil nil '(nil)))
          (lecture  (read-string "Lecture No.: " nil nil '(nil)))
          (date     (org-read-date nil t))
          (location (read-string "Location: " nil nil '(nil))))
      (when (and course week lecture date location)
        (concat (format "* TODO %s: Week %s Lecture %s\n"
                        course week lecture)
                (format "  SCHEDULED: %s\n" (update date 0))
                (format "  Location: %s %%?\n" location)
                (format "** TODO %s: prepare lecture %s from week %s\n"
                        course lecture week)
                (format "   DEADLINE: %s SCHEDULED: %s\n"
                        (update date -1) (update date -2))
                (format "** TODO %s: review lecture %s from week %s\n"
                        course lecture week)
                (format "   DEADLINE: %s SCHEDULED: %s\n"
                        (update date 2) (update date 1)))))))

(setq org-capture-templates
   '(("c" "Class" entry
      (file "~/sydbox/personal/workflow/class.txt")
      #'org-capture-class)
     ("e" "Exercise session" entry
      (file "~/sydbox/personal/workflow/class.txt"))))