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

时间:2012-12-13 01:16:22

标签: elisp org-mode

我正在使用org-mode并尝试设置捕获模板以将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问题,而不是一个组织模式问题,但我不确定它是什么。我跑过一个帖子(我再也找不到了)说了一些东西,通过将format-time-string放入括号中,Lisp没有把它看成是一个字符串。这似乎是真的,因为如果我评估它,除非我插入,否则不会打印任何内容。但我不想插入它 - 我希望表达式被评估并用作字符串。 Another question让我有类似的想法,我必须做一些事情来使格式化的字符串显示为字符串。

1 个答案:

答案 0 :(得分:0)

似乎引用太多而且从未评估过该呼叫。如你所说,一个字符串可以工作,所以你可以尝试将quote内的内容更改为准引号和逗号。此外,查看格式,似乎此变量是列表列表,并且您有一个列表列表。我猜是这样的:

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

我不知道模板格式,但您必须确保对函数调用进行求值,以生成包含已评估值的实际列表。