使用 ox-publish 导出,无法将变量分配给关键字

Exporting with ox-publish, can not assign variable to Keyword

我有一个使用 ox-publish 的工作设置,现在我正在尝试组织它。我的问题是我无法像下面的代码片段那样为关键字符号分配变量。

(setq my-org-base-dir "~/documents/todo")
(setq my-org-exp-dir "~/documents/todo_html")
(require 'ox-publish)
(setq org-publish-project-alist
  '(
    ("org-notes"
     :base-directory my-org-base-dir
     :base-extension "org"
      ; ....
     )
    ("org-static"
     :base-directory my-org-base-dir
      ; ....
     )
    ("org" :components ("org-notes" "org-static"))
    ))

使用 :base-directory "~/documents/todo" 效果很好,但如果我尝试使用变量 (:base-directory my-org-base-dir) 的值,当我尝试导出时,emacs 会给我 Wrong type argument: stringp, org-base-dir

如何为关键字赋值?

Edit: I think I may have misunderstood the question. This answers the question in the title, but doesn't look like it's the issue that the OP is running into.

您不能为关键字赋值。来自 Emacs Lisp 手册(添加了重点):

11.2 Variables that Never Change

In Emacs Lisp, certain symbols normally evaluate to themselves. These include nil and t, as well as any symbol whose name starts with ‘:’ (these are called keywords). These symbols cannot be rebound, nor can their values be changed. Any attempt to set or bind nil or t signals a setting-constant error. The same is true for a keyword (a symbol whose name starts with ‘:’), if it is interned in the standard obarray, except that setting such a symbol to itself is not an error.

当你

(setq org-publish-project-alist '( ... ))

您正在将 org-publish-project-alist 的值设置为文字列表。并不是说您不能 "assign a value to a keyword [argument]",而是列表的引号会阻止对其中的变量求值。例如,

(let ((a 1) (b 2) (c 3))
  (setq foo '(a b c)))
;=> (a b c)               
; *not* (1 2 3)

要获取变量 "interpolated",您需要使用 list 来构造列表,或者使用反引号以便拼接值。例如,

(setq org-publish-project-alist
  `(                                    ;; backquote (`), not quote (')
    ("org-notes"
     :base-directory ,my-org-base-dir   ;; comma (,) to splice value in
     :base-extension "org"
      ; ....
     )
    ("org-static"
     :base-directory ,my-org-base-dir   ;; comma (,)
      ; ....
     )
    ("org" :components ("org-notes" "org-static"))
    ))