Emacs Lisp 错误类型参数在格式时间字符串中



我正在使用组织模式并尝试设置一个捕获模板,以将TODO放在按当前日期命名的标题下。 例如,对于今天(12/12/12),我的标题将是:

*** Dec 12

所以我在我的模板中尝试过这个:

 '(org-capture-templates (quote
                          (
                           ;;; note: this template works
                           ("d" "Defect" entry (file+headline "~/doc/org/defects.org" "Open") "** TODO %^{Defect}")
                           ;;; this template does not
                           ("t" "Todo" entry (file+headline "~/doc/org/timesheet.org"  (format-time-string "%h %e")) "**** TODO %i%?"))))

但是,我得到了一个wrong-type-argument stringp例外。 下面是一些堆栈跟踪:

Debugger entered--Lisp error: (wrong-type-argument stringp (format-time-string "%h %e"))
  regexp-quote((format-time-string "%h %e"))
  (format org-complex-heading-regexp-format (regexp-quote hd))
  (re-search-forward (format org-complex-heading-regexp-format (regexp-quote hd)) nil t)
  (if (re-search-forward (format org-complex-heading-regexp-format ...) nil t) (goto-char (point-at-bol)) (goto-char (point-max)) (or (bolp) (insert "n")) (insert "* " hd "n") (beginning-of-line 0))
 ... snip ...

我有一种感觉,它更像是一个通用的Emacs Lisp问题,而不是一个组织模式的问题,但我不确定它可能是什么。 我遇到了一篇文章(我再也找不到了),大意是把格式-时间字符串放在括号里,Lisp 没有把它看作是一个字符串。 这似乎是真的,因为如果我评估它,除非我做插入,否则不会打印任何东西。 但我不想插入它 - 我希望表达式被计算并用作字符串。 另一个问题让我也有类似的想法,我必须做一些事情才能让格式化的字符串显示为字符串。

似乎引用

太多,并且从未评估过调用。正如您所说,字符串有效,因此您可以尝试将其quote更改为准引号和逗号。另外,从格式来看,这个变量似乎是一个列表列表,而你有一个列表列表的列表。我的猜测是这样的:

`(org-capture-templates (
                         ("t" "Todo" entry (file+headline "~/doc/org/timesheet.org" ,(format-time-string "%h %e")) "**** TODO %i%?")))

我不知道模板格式,但您必须确保计算函数调用以生成具有评估值的实际列表。

最新更新