org-capture file location出错

("j" "Journal" entry (file+olp+datetree (concat org-directory "/journal.org")) "* %?\nEntered on %U\n %i\n %a")

就是这个template

然后执行的时候 报错 invalid file location: nil debug信息如下

Debugger entered--Lisp error: (error "Invalid file location: nil")
  signal(error ("Invalid file location: nil"))
  error("Invalid file location: %S" nil)
  org-capture-expand-file((concat org-directory "/journal.org"))
  org-capture-target-buffer((concat org-directory "/journal.org"))
  org-capture-set-target-location(nil)
  org-capture(nil)
  funcall-interactively(org-capture nil)
  call-interactively(org-capture nil nil)
  command-execute(org-capture)

我寻思 `(concat org-directory “/journey.org”) 也不可能出错呀 括号仔细看了看也没问题,怎么回事?

可以自己执行下这句 (concat org-directory “/journey.org”) 看看。把光标放在括号后面,按 C-x C -e

这个没有问题啊

("j" "Journal" entry (file+olp+datetree "journal.org") "* %?\nEntered on %U\n %i\n %a")

这样就可以了,不用 concat,效果一样

Most target specifications contain a file name. If that file name is the empty string, it defaults to ‘org-default-notes-file’. A file can also be given as a variable or as a function called with no argument. When an absolute path is not specified for a target, it is taken as relative to ‘org-directory’.

但concat用法,报错是为啥?

看起来并没有问题,不清楚,可能需要跟一下 org mode 的源码

The problem is quoting. You need something like

`(... entry (file+olp+datetree ,(concat ...)) ...)

Otherwise, (concat org-directory ...) is not evaluated into a string and Org cannot know what you meant.

See Backquote (GNU Emacs Lisp Reference Manual)