Search code examples
emacslispelisporg-mode

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


I have a working setup with ox-publish and now i am trying to organize it. My problem is that i cannot assign a variable to the keyword-symbols like in the snippet below.

(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"))
    ))

Using :base-directory "~/documents/todo" works just fine but if i try to use the value from a variable (:base-directory my-org-base-dir) emacs gives me Wrong type argument: stringp, org-base-dir when i try to export.

How do i assign a value to a Keyword?


Solution

  • When you do

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

    you're setting the value of org-publish-project-alist to a literal list. It's not that you can't "assign a value to a keyword [argument]", it's that quotation of a list prevents evaluation of variables within it. E.g.,

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

    To get the variables "interpolated" you either need to use list to construct the list, or use a backquote so that you can splice in the values. E.g.,

    (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"))
        ))