组织模式捕获

Syd*_*ove 5 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>
Run Code Online (Sandbox Code Playgroud)

目前,我有这个模板。

(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")
     ))
Run Code Online (Sandbox Code Playgroud)

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

Dan*_*Dan 5

以下代码对我有用。它首先定义了一个自定义函数来创建模板 ( org-capture-class),它根据需要计算日期,并且比内嵌字符串更容易理解(请注意,它依赖于cl-lib,因此请确保已加载)。然后它在模板本身中调用该函数,如果任何字段为空,则清除(响应评论更新):

(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"))))
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

1250 次

最近记录:

11 年,5 月 前