org-capture file location出错

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


然后执行的时候 报错 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 "/"))
  org-capture-target-buffer((concat org-directory "/"))
  funcall-interactively(org-capture nil)
  call-interactively(org-capture nil nil)

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

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


("j" "Journal" entry (file+olp+datetree "") "* %?\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’.


看起来并没有问题,不清楚,可能需要跟一下 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)