组织模式:Symbol 的函数定义无效:\,

Org Mode: Symbol's function definition is void: \,

我正在尝试创建一个 Org 模式捕获模板,将每个条目写入一个基于时间的文件名。

首先,暂存缓冲区中有一个辅助函数:

;; Example input: (capture-date-based-file "~/path/to/logs/" "log")
;; Expected output: "~/path/to/logs/2017-11-27-monday-log.org"
(defun capture-date-based-file (path entry-type)
  "Create a date-based file name based on the given type."
  (downcase (concat path (format-time-string "%Y-%m-%d-%A-") entry-type ".org")))

然后,它被用在捕获模板列表中:

(setq org-capture-templates
      '(("l" "Log" entry (file+headline ,(capture-date-based-file "~/path/to/logs/" "log"))
         "* %?\n%U\n" :clock-in t :clock-resume t) ))

我得到一个错误:Symbol's function definition is void: \,

由于逗号字符,很难在 Google 中找到答案。我查看了文档,但不确定自己做错了什么。

逗号表示您想要评估capture-date-based-file的调用,但周围的形式是quoted而不是 反引号,所以那行不通。

即这是两个完全不同的东西:

'(foo ,(bar) baz)
`(foo ,(bar) baz)

C-hig(elisp)BackquoteRET

在反引号形式中,逗号会导致立即对后面的形式求值,然后将求值结果代入反引号形式。在引用形式中,,(bar) 仅保留为文字 ,(bar).

您看到的特定错误的原因是 lisp reader 产生以下内容:

ELISP> (read ",(bar)")
(\, (bar))

因此,任何 评估 ,(bar) 的尝试实际上是在调用不存在的函数 \,

(您将遇到的不太明显的错误之一,FWIW。)

在您的场景中,我假设 org 从模板结构中提取特定表单并对其进行评估。 M-x toggle-debug-on-error 很可能会告诉您发生这种情况的确切时间和地点。